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 oauth token
|
||||||
try:
|
try:
|
||||||
print('trying oauth login')
|
print('trying oauth login')
|
||||||
|
|
||||||
with open('oauth_token', 'r') as file:
|
with open('oauth_token', 'r') as file:
|
||||||
user.oauth_login(file.read(), steam_id=environ['STEAM_ID'], language='english')
|
user.oauth_login(file.read(), steam_id=environ['STEAM_ID'], language='english')
|
||||||
|
|
||||||
print('oauth login successful')
|
print('oauth login successful')
|
||||||
except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
||||||
print('oauth login failed:', exp)
|
print('oauth login failed:', exp)
|
||||||
|
|
||||||
# get previously known message ids from imap server
|
# get previously known message ids from imap server
|
||||||
|
|
||||||
print('loggin into IMAP Server:', environ['IMAP_HOST'])
|
print('loggin into IMAP Server:', environ['IMAP_HOST'])
|
||||||
|
@ -55,17 +55,17 @@ except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
||||||
while True:
|
while True:
|
||||||
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
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]
|
newest_msg_id = data[0].split()[-1]
|
||||||
|
|
||||||
if newest_msg_id in old_msg_ids:
|
if newest_msg_id in old_msg_ids:
|
||||||
print('refreshing messages')
|
print('refreshing messages')
|
||||||
sleep(1)
|
sleep(1)
|
||||||
else:
|
else:
|
||||||
print('messages received')
|
print('messages received')
|
||||||
break
|
break
|
||||||
|
|
||||||
typ, data = Mailbox.fetch(newest_msg_id, '(RFC822)')
|
typ, data = Mailbox.fetch(newest_msg_id, '(RFC822)')
|
||||||
msg = email.message_from_bytes(data[0][1])
|
msg = email.message_from_bytes(data[0][1])
|
||||||
|
|
||||||
for payload in msg.get_payload():
|
for payload in msg.get_payload():
|
||||||
if (
|
if (
|
||||||
payload.get_content_maintype() == 'text' and
|
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()
|
plaintext_lines = payload.get_payload(decode=True).decode().splitlines()
|
||||||
code = plaintext_lines[plaintext_lines.index('Login Code') + 1]
|
code = plaintext_lines[plaintext_lines.index('Login Code') + 1]
|
||||||
break
|
break
|
||||||
|
|
||||||
Mailbox.close()
|
Mailbox.close()
|
||||||
Mailbox.logout()
|
Mailbox.logout()
|
||||||
|
|
||||||
print('code found:', code)
|
print('code found:', code)
|
||||||
user.login(email_code=code, language='english')
|
user.login(email_code=code, language='english')
|
||||||
|
|
||||||
|
@ -89,15 +89,13 @@ except (wa.LoginIncorrect, FileNotFoundError) as exp:
|
||||||
# CRAWL
|
# CRAWL
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
import pytz
|
|
||||||
import re
|
import re
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import requests
|
import requests
|
||||||
from hashlib import sha3_256
|
from hashlib import sha3_256
|
||||||
import pg8000
|
import pg8000
|
||||||
|
|
||||||
pdt = pytz.timezone("Us/Pacific")
|
|
||||||
db = pg8000.connect(
|
db = pg8000.connect(
|
||||||
database=environ['DB_NAME'],
|
database=environ['DB_NAME'],
|
||||||
user=environ['DB_USER'],
|
user=environ['DB_USER'],
|
||||||
|
@ -118,7 +116,10 @@ def parse_trs(trs):
|
||||||
from_name = tds[0].text
|
from_name = tds[0].text
|
||||||
to_url = tds[1].find('a')['href']
|
to_url = tds[1].find('a')['href']
|
||||||
to_name = tds[1].text
|
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
|
message = tds[3].text
|
||||||
checksum = sha3_256(
|
checksum = sha3_256(
|
||||||
(from_url + to_url + str(date.timestamp()) + message).encode()
|
(from_url + to_url + str(date.timestamp()) + message).encode()
|
||||||
|
|
Loading…
Reference in a new issue