INNER CODE UNIT · Python
_get_endpoints
trevorhobenshield/twitter-api-client · scripts/update.py:177
def _get_endpoints(res: Response, out: Path = JS_FILES_MAP) -> dict:
temp = re.findall('\+"\."\+(\{.*\})\[e\]\+?' + '"' + _a + '"', res.text)[0]
endpoints = orjson.loads(temp.replace('vendor:', '"vendor":').replace('api:', '"api":'))
if out:
out.write_bytes(dump_json(endpoints))
return endpoints
def get_js_files(r: Response, out: Path = JS_FILES) -> None:
endpoints = _get_endpoints(r)
csp = sorted({x.strip(';') for x in r.headers.get("content-security-policy").split() if x.startswith("https://")})
PATH_URLS.write_text('\n'.join(csp))
urls = [
f'{_base}/{k}.{v}{_a}'
for k, v in endpoints.items()
if not re.search(r'participantreaction|\.countries-|emojipicker|i18n|icons\/', k, flags=re.I)
]
asyncio.run(process(download(urls, out=out), desc='Downloading JS files'))