-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_outerwilds.py
More file actions
60 lines (45 loc) · 1.67 KB
/
Copy pathswitch_outerwilds.py
File metadata and controls
60 lines (45 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import requests
from bs4 import BeautifulSoup
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import datetime
import time
from pathlib import Path
now = datetime.datetime.now()
epoch = time.time()
content = ""
url = "https://www.nintendo.com/games/detail/outer-wilds-switch/"
headers = {"User-Agent": 'Mozilla/5.0 (X11; Linux x86_64)', 'Cache-Control': 'no-cache', "Pragma": "no-cache"}
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
product = soup.find('h1', class_="h2 game-title").get_text()
availability = soup.find('div', class_="availability").get_text()
status = "TBD"
if availability != None and status in availability:
print(product.strip(), "on Switch - status: sad times, still TBD")
content = "Outer Wilds is still TBD, I will recheck tomorrow"
else:
print(product.strip(), "on Switch - status: OMFDAYS IT IS AVAILABLE!")
content = "Outer Wilds is now available to buy! GO GO GO!"
print('Composing email...')
SERVER = Path('./.secret.server').read_text()
PORT = 587
FROM = Path('./.secret.from').read_text()
TO = Path('./.secret.to').read_text()
PASS = Path('./.secret.pass').read_text()
msg = MIMEMultipart()
msg['Subject'] = 'OUTER WILDS on NINTENDO SWITCH' + ' ' + str(now.day) + '-' + str(now.month) + '-' + str(now.year) + ' [' + str(epoch) + ']'
msg['From'] = FROM
msg['To'] = TO
msg.attach(MIMEText(content, 'html'))
print('Initiating Server...')
server = smtplib.SMTP(SERVER, PORT)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(FROM, PASS)
server.sendmail(FROM, TO, msg.as_string())
print('Email sent.')
server.quit()
print("All done. Bye.")