Neskatoties uz to, ka mums ir overpass
un wizard
Code Playgrounds, kas ļauj ierakstīt čatā vaicājuma tekstu un dabūt klīkšķināmo pogu, lai pāriet uz Overpass Turbo lapu, ik pa laiku kāds ie'paste'o short link (piemēram, te). Ideja ir uztaisīt Zulip botu, kas skanēs visus ienākošus massage'us, un ja tiek pamanīts tāds short link, bots atbildēs ar vaicājuma tekstu koda blokā.
#!/usr/bin/env python3
from base64 import urlsafe_b64decode
from urllib.parse import urlparse, parse_qsl, unquote
from urllib.request import build_opener, HTTPRedirectHandler
# https://github.com/tyrasd/overpass-turbo/blob/c16d92d43a68091b56d4ec65b2ef326950d7c586/js/misc.ts#L239-L262
def decompress(data: str):
d: dict[int, str] = {}
currChar, *rest = data
oldPhrase = currChar
yield currChar
code = 256
phrase = None
for i in rest:
currCode = ord(i)
if currCode < 256:
phrase = i
else:
phrase = d[currCode] if currCode in d else oldPhrase + currChar
yield phrase
currChar = phrase[0]
d[code] = oldPhrase + currChar
code += 1
oldPhrase = phrase
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape
def escape(s):
def transform(c):
if "A" <= c and c <= "Z" or "a" <= c and c <= "z" or "0" <= c and c <= "9" or c in r"@\*_+-./":
return c
o = ord(c)
return f"%{o:02x}" if o < 256 else f"%u{o:04x}"
return "".join(map(transform, s))
class My(HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, hdrs, newurl):
for k, v in parse_qsl(urlparse(newurl).query, strict_parsing=True, encoding="ASCII", errors="strict"):
if k == "q":
v += "=" * ((4 - len(v) % 4) % 4)
print(unquote(escape("".join(decompress(urlsafe_b64decode(v).decode(encoding="UTF-8"))))))
exit(0)
build_opener(My).open("https://overpass-turbo.eu/s/1pUv")
Last updated: Dec 22 2024 at 05:42 UTC