|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import requests |
| 3 | +from bs4 import BeautifulSoup |
| 4 | +import smtplib |
| 5 | +from email.message import EmailMessage |
| 6 | +import sys |
| 7 | + |
| 8 | +def sendmail(S, OACI_AR): |
| 9 | + msg = EmailMessage() |
| 10 | + msg.set_content(S) |
| 11 | + msg['Subject'] = f'ATENCION: Nuevo vuelo del %s!!!' % OACI_AR |
| 12 | + |
| 13 | + |
| 14 | + s = smtplib.SMTP('localhost') |
| 15 | + s.send_message(msg) |
| 16 | + s.quit() |
| 17 | + |
| 18 | + |
| 19 | +def proc(OACI_AR): |
| 20 | + OACI_AR = OACI_AR.upper() |
| 21 | + fp = open("/tmp/%s.txt","r+" % OACI_AR) |
| 22 | + linesR = [line.rstrip() for line in fp.readlines()] |
| 23 | + linesW = [] |
| 24 | + URL = "https://dinacia.gub.uy/search/contenido?keys=%s+" % OACI_AR |
| 25 | + page = requests.get(URL) |
| 26 | + soup = BeautifulSoup(page.content, "html.parser") |
| 27 | + results = soup.find('ol',class_="list-group node_search-results") |
| 28 | + newc = str(results.prettify()) |
| 29 | + for n,e in enumerate(results.find_all("p")): |
| 30 | + sOACI_AR = OACI_AR.replace("-","") |
| 31 | + s = str(e)[3:].split("\n")[0].replace("<strong>","").replace("</strong>","").replace(OACI_AR,sOACI_AR).replace(OACI_AR.lower(),sOACI_AR).split("-") |
| 32 | + if s != ["<em></em></p>"]: |
| 33 | + if s[1] == 'Internacional Ángel S. Adami': s[1]='SUAA' |
| 34 | + s = s[:3] + [s[3].replace(" ","")] + [s[4].replace(" ","")] |
| 35 | + s2=";".join(s) |
| 36 | + linesW.append(s2) |
| 37 | + if linesW != linesR: |
| 38 | + S = "\n".join(linesW) |
| 39 | + print("="*60) |
| 40 | + print(S) |
| 41 | + fp.seek(0) |
| 42 | + for line in linesW: |
| 43 | + fp.writelines(line+"\n") |
| 44 | + sendmail(S, OACI_AR) |
| 45 | + print("-"*60) |
| 46 | + fp.close() |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + proc(sys.argv[1]) |
0 commit comments