forked from tizianoghisu/asn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetasn.py
137 lines (118 loc) · 3.61 KB
/
getasn.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import requests
import os
import csv, smtplib, ssl
from email.mime.text import MIMEText
import shutil
from datetime import datetime, timedelta
notify=False
f=open('secs.txt','r')
lines=f.readlines()
f.close()
trues=[]
falses=[]
sectors=[]
dates=[]
for line in lines:
check=False
s1=line.split()[0]
s2=line.split()[1]
page="https://asn21.cineca.it/pubblico/miur/esito/"+s1+"%252F"+s2+"/2/3"
response=requests.get(page)
text=response.text
if not ('Non risultano' in text):
check=True
v=text[text.find("Dal"):]
try:
date=v.split()[1]
except:
check=False
if not check:
page="https://asn21.cineca.it/pubblico/miur/esito/"+s1+"%252F"+s2+"/1/3"
response=requests.get(page)
text=response.text
if not ('Non risultano' in text):
check=True
v=text[text.find("Dal"):]
try:
date=v.split()[1]
except:
check=False
if check:
dates.append(date)
trues.append(line)
sectors.append(line.split()[0]+'/'+line.split()[1])
else:
falses.append(line)
print(line+str(check))
if ((notify==True) and (len(trues)>0)):
from_address = "[email protected]"
password = "provaprova"
msg = MIMEText('This is test mail')
msg['Subject'] = 'Test mail'
if os.path.exists("tobenotified.txt"):
f=open("tobenotified.txt")
lines=f.readlines()
f.close()
context = ssl.create_default_context()
no=open('notifications.out','a')
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(from_address, password)
for line in lines:
s=line.split()[0]
if any(s in sector for sector in sectors):
for i in range(1,len(line.split())):
email=line.split()[i]
p="I have notified "+str(email)+" for sector "+str(line.split()[0])+" \n"
no.write(p)
msg=MIMEText("Sono stati pubblicati i risultati del SSC "+s)
msg['Subject']="NUOVI RISULTATI ASN"
server.sendmail(
from_address,
email, msg.as_string())
no.close()
f1=open('present.txt','w')
f2=open('notpresent.txt','w')
f3=open('secs_ordered.txt','a')
for line in falses:
f2.write(line)
i=-1
for line in trues:
i+=1
f1.write('- '+dates[i]+' '+line)
f3.write('')
f3.write('- '+dates[i]+' '+line)
f1.close()
f2.close()
f3.close()
shutil.copyfile('notpresent.txt','secs.txt')
f=open('secs_ordered.txt')
lines=f.readlines()
count=0
secs=[]
for line in lines:
if len(line.split())>1:
secs.append(line)
count+=1
f.close()
f=open('README.md','w')
#f.write('visita il sito [https://www.risultatiasn.it](https://www.risultatiasn.it) (aggiornato in tempo reale)\n')
f.write('ESITI PUBBLICATI '+str(count)+'/190 \n')
for sec in secs[::-1]:
s1=sec.split()[2]
s2=sec.split()[3]
p1="https://asn21.cineca.it/pubblico/miur/esito/"+s1+"%252F"+s2+"/1/3"
p2="https://asn21.cineca.it/pubblico/miur/esito/"+s1+"%252F"+s2+"/2/3"
f.write('\n')
f.write(sec.rstrip("\n")+" [I fascia]("+p1+") [II fascia]("+p2+") \n")
f.write('\n')
now = datetime.now()
hours=1
hoursToAdd = timedelta(hours = hours)
timeToPrint=now+hoursToAdd
f.write('UPDATED '+str(timeToPrint))
fs=open('spiegazione.txt','r')
lines=fs.readlines()
fs.close()
for line in lines:
f.write(line)
f.close()