log
This commit is contained in:
parent
a7b24d4df1
commit
9107e00bb2
1 changed files with 29 additions and 17 deletions
46
app.py
46
app.py
|
@ -12,34 +12,47 @@ from time import sleep
|
|||
|
||||
# get previously known message ids from imap server
|
||||
|
||||
M = imaplib.IMAP4_SSL(environ['IMAP_HOST'])
|
||||
M.login(environ['IMAP_USER'], environ['IMAP_PASSWORD'])
|
||||
M.select()
|
||||
typ, data = M.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
||||
print('loggin into IMAP Server:', environ['IMAP_HOST'])
|
||||
|
||||
Mailbox = imaplib.IMAP4_SSL(environ['IMAP_HOST'])
|
||||
Mailbox.login(environ['IMAP_USER'], environ['IMAP_PASSWORD'])
|
||||
Mailbox.select()
|
||||
typ, data = Mailbox.search(None, '(FROM "noreply@steampowered.com" SUBJECT "Your Steam account: Access from new web or mobile device")')
|
||||
old_msg_ids = data[0].split()
|
||||
|
||||
# perform steam login
|
||||
|
||||
print('loggin into STEAM:', environ['STEAM_USERNAME'])
|
||||
|
||||
user = wa.WebAuth(environ['STEAM_USERNAME'])
|
||||
|
||||
try:
|
||||
user.login(environ['STEAM_PASSWORD'])
|
||||
except (wa.LoginIncorrect) as exp:
|
||||
print('ERROR: loggin incorrect')
|
||||
raise
|
||||
except (wa.CaptchaRequired) as exp:
|
||||
print(user.captcha_url)
|
||||
user.login(password=environ['STEAM_PASSWORD'], captcha=input("Captcha: "))
|
||||
print('ERROR: captcha required:', user.captcha_url)
|
||||
#user.login(password=environ['STEAM_PASSWORD'], captcha=input("Captcha: "))
|
||||
raise
|
||||
except wa.TwoFactorCodeRequired:
|
||||
print('ERROR: 2FA code required')
|
||||
#user.login(twofactor_code=input("2FA Code: "))
|
||||
raise
|
||||
except wa.EmailCodeRequired:
|
||||
print('getting email code')
|
||||
while True:
|
||||
typ, data = M.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]
|
||||
|
||||
if newest_msg_id in old_msg_ids:
|
||||
print('refreshing messages')
|
||||
sleep(1)
|
||||
else:
|
||||
print('messages received')
|
||||
break
|
||||
|
||||
typ, data = M.fetch(newest_msg_id, '(RFC822)')
|
||||
typ, data = Mailbox.fetch(newest_msg_id, '(RFC822)')
|
||||
msg = email.message_from_bytes(data[0][1])
|
||||
|
||||
for payload in msg.get_payload():
|
||||
|
@ -51,9 +64,8 @@ except wa.EmailCodeRequired:
|
|||
code = plaintext_lines[plaintext_lines.index('Login Code') + 1]
|
||||
break
|
||||
|
||||
print('code found:', code)
|
||||
user.login(email_code=code)
|
||||
except wa.TwoFactorCodeRequired:
|
||||
user.login(twofactor_code=input("2FA Code: "))
|
||||
|
||||
# CRAWL
|
||||
|
||||
|
@ -76,6 +88,7 @@ def parse_trs(trs):
|
|||
date = datetime.strptime(tds[2].text, '%b %d, %Y @ %I:%M%p PDT').replace(tzinfo=pdt)
|
||||
text = tds[3].text
|
||||
print(f'({date}) {from_name} -> {to_name}: {text}')
|
||||
|
||||
# download steamuserimages
|
||||
for url_string in re.findall(r'(https?://\S+)', text):
|
||||
url = urlparse(url_string)
|
||||
|
@ -86,12 +99,10 @@ def parse_trs(trs):
|
|||
|
||||
# get first page
|
||||
|
||||
r = user.session.get('https://help.steampowered.com/en/accountdata/GetFriendMessagesLog')
|
||||
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
|
||||
print('parsing friend messages log')
|
||||
response = user.session.get('https://help.steampowered.com/en/accountdata/GetFriendMessagesLog')
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
continue_value = soup.find(class_='AccountDataLoadMore')['data-continuevalue']
|
||||
|
||||
account_data_table = soup.find(id='AccountDataTable_1')
|
||||
trs = account_data_table.find_all('tr')[1:]
|
||||
|
||||
|
@ -100,6 +111,7 @@ parse_trs(trs)
|
|||
# get further pages
|
||||
|
||||
while True:
|
||||
print('getting next page')
|
||||
r = user.session.get(f'https://help.steampowered.com/en/accountdata/AjaxLoadMoreData/?url=GetFriendMessagesLog&continue={continue_value}')
|
||||
continue_value = r.json()['continue']
|
||||
html = r.json()['html']
|
||||
|
@ -108,5 +120,5 @@ while True:
|
|||
|
||||
# CLOSE
|
||||
|
||||
M.close()
|
||||
M.logout()
|
||||
Mailbox.close()
|
||||
Mailbox.logout()
|
||||
|
|
Loading…
Reference in a new issue