INNER CODE UNIT · Python
main
trevorhobenshield/twitter-api-client · scripts/update.py:210
def main():
client = Client(headers={'user-agent': random.choice(USER_AGENTS)}, follow_redirects=True, http2=True)
r1 = client.get('https://x.com')
PATH_HOMEPAGE.write_text(r1.text)
try:
get_js_files(r1)
except Exception as e:
logger.warning(f'Failed to get js files\t\t{e}')
main_js = re.findall(r'href="(https\:\/\/abs\.twimg\.com\/responsive-web\/client-web\/main\.\w+\.js)"', r1.text)[0]
r2 = client.get(main_js)
PATH_MAIN.write_text(r2.text)
expr = r'\{[^{}]*queryId:\s?"([^"]+)",\s*operationName:\s?"([^"]+)",\s*operationType:\s?"([^"]+)",\s*metadata:\s?\{\s*featureSwitches:\s?\[(.*?)\],\s*fieldToggles:\s?\[(.*?)\]\s*\}\s*\}'
matches = re.findall(expr, r2.text, flags=re.A)
ops = parse_matches(matches)