-
Notifications
You must be signed in to change notification settings - Fork 0
/
MDFE.py
61 lines (55 loc) · 2.05 KB
/
MDFE.py
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
61
import requests
from bs4 import BeautifulSoup
import smtplib
import time
URL = "https://theskylive.com/mars-tracker"
#SEARCH THE INTERNET FOR "MY USER AGENT COPY AND PASTE IT IN "YOUR USER AGENT(line 11)""
headers = {
"User-Agent": 'YOUR USER AGENT'}
#YOU'LL NEED TO CHANGE TARGET AND STARTING DISTANCE IF YOU WOULD LIKE TO.(line 23, 24)
def check_distance():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="disearth").get_text()
mars_distance = soup.find(id="disearth").get_text()
converted_dist = float(mars_distance)
target_distance = float(200000000)
starting_distance = float(293500000)
distance_from_earth = str(starting_distance - converted_dist)
while ():
if (converted_dist < target_distance):
send_mail()
print("The Mars just got closer by " + distance_from_earth + "km!")
print(converted_dist)
print("The operation has been completed successfully!")
break
if (converted_dist > target_distance):
print("Waiting for target distance.")
print(mars_distance + "km")
#Send Mail
def send_mail():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('YOUR GMAIL', "YOUR GMAIL PRIVATE KEY")
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="disearth").get_text()
mars_distance = soup.find(id="disearth").get_text()
converted_dist = float(mars_distance)
starting_distance = float(293500000)
distance_from_earth = str(starting_distance - converted_dist)
subject = 'The Mars Is Closer!'
body = "The Mars just got closer to Earth by " + distance_from_earth + "km!"
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
"from E-MAIL(example@gmail.com)",
"TO E-MAIL(example@gmail.com)",
msg
)
print("Email has been sent.")
server.quit()
while True:
check_distance()
time.sleep(0.1)