-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (32 loc) · 1.19 KB
/
main.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
import os
import smtplib
import requests
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(subject, body):
email = os.environ['EMAIL']
password = os.environ['PASSWORD']
recipient = os.environ['RECIPIENT']
msg = MIMEMultipart()
msg['From'] = email
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP(os.environ['SMTP_SERVER'], os.environ['SMTP_PORT'])
server.starttls()
server.login(email, password)
server.sendmail(email, recipient, msg.as_string())
server.quit()
def read_expected_robots_txt(file_path):
with open(file_path, 'r') as f:
return f.read().strip()
def main():
url = 'https://example.de/robots.txt'
expected_robots_txt = read_expected_robots_txt('expected-robots.txt')
response = requests.get(url)
if response.status_code != 200 or response.text.strip() != expected_robots_txt:
subject = 'Änderung in robots.txt oder Statuscode nicht 200'
body = f'Statuscode: {response.status_code}\n\nInhalt der robots.txt:\n\n{response.text}'
send_email(subject, body)
if __name__ == '__main__':
main()