Initial commit

This commit is contained in:
franjsco 2020-12-03 18:47:26 +01:00
parent 78133f4ac7
commit 45eb241c6b
3 changed files with 93 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv

70
iliadly.py Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python3
##################################################
# iliadly #
# https://github.com/franjsco/iliadly #
# @franjsco #
##################################################
from requests_html import HTMLSession
from colored import fg, bg, attr
URL_CONTATORI_ILIAD = 'https://www.iliad.it/account/consumi-e-credito'
def preleva_dati():
# sesione html e get (esecuzione metodo render() per eseguire js)
session = HTMLSession()
res = session.get(URL_CONTATORI_ILIAD)
res.html.render()
# selettore css dei contatori
sel_dati = 'div.conso-infos:nth-child(4) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)'
sel_chiamate = 'div.conso-infos:nth-child(4) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)'
sel_sms = 'div.conso-infos:nth-child(4) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1)'
sel_mms = 'div.conso-infos:nth-child(4) > div:nth-child(2) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1)'
sel_nome_offerta= '.page > h2:nth-child(1) > span:nth-child(1)'
sel_scadenza_offerta = '.end_offerta'
sel_credito = 'b.red'
# ricerca dati mediante selettori e assegnazione valori nel dizionario
dati = {
"offerta": res.html.find(sel_nome_offerta, first=True).text.split('\n', 1)[0][7:].strip(),
"credito": res.html.find(sel_credito, first=True).text.split('\n', 1)[0].strip(),
"chiamate": res.html.find(sel_chiamate, first=True).text.split('\n', 1)[0][9:].strip(),
"internet": res.html.find(sel_dati, first=True).text.split('\n', 1)[0].strip(),
"sms": res.html.find(sel_sms, first=True).text.split('\n', 1)[0].strip(),
"mms": res.html.find(sel_mms, first=True).text.split('\n', 1)[0].strip(),
"scadenza": res.html.find(sel_scadenza_offerta, first=True).text[-10:].strip()
}
return dati
def stampa_contatori(dati):
print('%s%s%s iliadly %s' % (fg(160), bg(15) ,attr(1), attr(0)))
print('Offerta:%s%s %s %s' % (fg(1), attr(1), dati["offerta"], attr(0)))
print('Scadenza:%s%s %s %s' % (fg(1) ,attr(1), dati["scadenza"], attr(0)))
print('Credito:%s%s %s %s' % (fg(1), attr(1), dati["credito"], attr(0)))
print('Chiamate:%s%s %s %s' % (fg(1), attr(1), dati["chiamate"], attr(0)))
print('SMS:%s%s %s %s' % (fg(1) ,attr(1), dati["sms"], attr(0)))
print('MMS:%s%s %s %s' % (fg(1),attr(1), dati["mms"], attr(0)))
print('Dati:%s%s %s %s' % (fg(1) ,attr(1), dati["internet"], attr(0)))
def main():
try:
dati = preleva_dati()
except:
print('%s%siliadly: Errore nel prelevare i dati. Assicurati di essere connesso ad internet con SIM iliad. %s' % (fg(1), bg(0), attr(0)))
exit(1)
try:
stampa_contatori(dati)
except:
print('%s%siliadly: Errore nella stampa a video dei contatori. %s' % (fg(1), bg(0), attr(0)))
exit(1)
if __name__ == "__main__":
main()
exit(0)

22
requirements.txt Normal file
View File

@ -0,0 +1,22 @@
appdirs==1.4.4
beautifulsoup4==4.9.3
bs4==0.0.1
certifi==2020.11.8
chardet==3.0.4
colored==1.4.2
cssselect==1.1.0
fake-useragent==0.1.11
idna==2.10
lxml==4.6.2
parse==1.18.0
pyee==7.0.4
pyppeteer==0.2.2
pyquery==1.4.3
requests==2.25.0
requests-html==0.10.0
six==1.15.0
soupsieve==2.0.1
tqdm==4.54.0
urllib3==1.26.2
w3lib==1.22.0
websockets==8.1