Just some minor changes.

This commit is contained in:
TheTechRobo 2022-04-04 21:29:10 -04:00
parent 595fb8f63d
commit f270e585e7
1 changed files with 5 additions and 0 deletions

View File

@ -43,6 +43,7 @@ class PlaceScraper:
{"time": time.time(), "url": url, "data": data}
)
async def regen_token(self, sesh):
print("Regenerating token...")
async with sesh.get("https://reddit.com/r/place", headers={"User-Agent": "Mozilla"}) as f:
a = await f.text()
i = a.index('''"session":{"accessToken":"''')
@ -61,6 +62,7 @@ class PlaceScraper:
await self.add_to_db(self.db, "sent_ws", {"sent": send, "time": time.time()})
async def run_forever(self):
global STOP, STOPPED
prev = {}
cert = False
if type(os.environ.get("DISABLE_CERT_VERIF")) is None:
cert = True
@ -71,6 +73,9 @@ class PlaceScraper:
while True:
try:
response = await websocket.recv()
if json.loads(response) == {"type": "ka"} and prev == {"type": "ka"}:
raise websockets.exceptions.ConnectionClosedOK(None, None)
prev = response
except websockets.exceptions.ConnectionClosedOK:
await self.regen_token(sesh)
print(raw_data.connection_init % self.token)