support pst timezone
This commit is contained in:
parent
a632b75b8f
commit
02549c2c3b
1 changed files with 13 additions and 12 deletions
|
@ -17,14 +17,14 @@ user = wa.MobileWebAuth(environ['STEAM_USERNAME'])
|
|||
# try oauth token
|
||||
try:
|
||||
print('trying oauth login')
|
||||
|
||||
|
||||
with open('oauth_token', 'r') as file:
|
||||
user.oauth_login(file.read(), steam_id=environ['STEAM_ID'], language='english')
|
||||
|
||||
|
||||
print('oauth login successful')
|
||||
except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
||||
print('oauth login failed:', exp)
|
||||
|
||||
|
||||
# get previously known message ids from imap server
|
||||
|
||||
print('loggin into IMAP Server:', environ['IMAP_HOST'])
|
||||
|
@ -55,17 +55,17 @@ except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
|||
while True:
|
||||
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
||||
newest_msg_id = data[0].split()[-1]
|
||||
|
||||
|
||||
if newest_msg_id in old_msg_ids:
|
||||
print('refreshing messages')
|
||||
sleep(1)
|
||||
else:
|
||||
print('messages received')
|
||||
break
|
||||
|
||||
|
||||
typ, data = Mailbox.fetch(newest_msg_id, '(RFC822)')
|
||||
msg = email.message_from_bytes(data[0][1])
|
||||
|
||||
|
||||
for payload in msg.get_payload():
|
||||
if (
|
||||
payload.get_content_maintype() == 'text' and
|
||||
|
@ -74,10 +74,10 @@ except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
|||
plaintext_lines = payload.get_payload(decode=True).decode().splitlines()
|
||||
code = plaintext_lines[plaintext_lines.index('Login Code') + 1]
|
||||
break
|
||||
|
||||
|
||||
Mailbox.close()
|
||||
Mailbox.logout()
|
||||
|
||||
|
||||
print('code found:', code)
|
||||
user.login(email_code=code, language='english')
|
||||
|
||||
|
@ -89,15 +89,13 @@ except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
|||
# CRAWL
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from datetime import datetime, timezone
|
||||
import pytz
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
import requests
|
||||
from hashlib import sha3_256
|
||||
import pg8000
|
||||
|
||||
pdt = pytz.timezone("Us/Pacific")
|
||||
db = pg8000.connect(
|
||||
database=environ['DB_NAME'],
|
||||
user=environ['DB_USER'],
|
||||
|
@ -118,7 +116,10 @@ def parse_trs(trs):
|
|||
from_name = tds[0].text
|
||||
to_url = tds[1].find('a')['href']
|
||||
to_name = tds[1].text
|
||||
date = datetime.strptime(tds[2].text, '%b %d, %Y @ %I:%M%p PDT').replace(tzinfo=pdt)
|
||||
timestamp_string, timezone_string = tds[2].text.rsplit(None, 1)
|
||||
offsets = {'PST': -8, 'PDT': -7}
|
||||
timezone_object = timezone(timedelta(hours=offsets[timezone_string]), 'UTC')
|
||||
date = datetime.strptime(timestamp_string, '%b %d, %Y @ %I:%M%p').replace(tzinfo=timezone_object)
|
||||
message = tds[3].text
|
||||
checksum = sha3_256(
|
||||
(from_url + to_url + str(date.timestamp()) + message).encode()
|
||||
|
|
Loading…
Reference in a new issue