Create a gist now

Instantly share code, notes, and snippets.

anonymous /orange.py
Created Sep 19, 2017

What would you like to do?
from requests import session
from bs4 import BeautifulSoup
import re
import Adafruit_CharLCD as LCD
import logging
logger = logging.getLogger('orange')
hdlr = logging.FileHandler('orange.log')
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
payload = {
'USER': 'user@domain.tld',
'PASSWORD': 'password',
'smauthreason': '/',
'smretries': '0',
'lang': 'fr',
'target': 'https://sso.orange.be/fr/home',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'Host' : 'sso.orange.be',
'Origin': 'https://www.orange.be',
'Referer': 'https://www.orange.be/fr/e-services/login'
}
with session() as c:
dataleft = []
datatotal = []
c.post('https://sso.orange.be/auth/sm/login.fcc', data=payload)
response = c.get('https://e-services.orange.be/fr/invoices/your-usage/32xxxxxxx')
soup = BeautifulSoup(response.text, "html5lib")
left = soup.find_all("div", class_="balance-remaining")
for x in left:
x = x.string.strip()
x = int(re.search(r'\d+', x).group())
dataleft.append(x)
total = soup.find_all("div", class_="progress-bar-label-right")
for y in total:
y = y.string.strip()
if "Valable" not in y:
if '=' in y:
value = y.split('=',1)[1]
else:
value = y
value = int(re.search(r'\d+', value).group())
datatotal.append(value)
dataleftsum = sum(dataleft)
datatotalsum = sum(datatotal)
percentage = 100 * int(dataleftsum)/int(datatotalsum)
dataleftsumgb = float(dataleftsum)/1024
datatotalsumgb = float(datatotalsum)/1024
lcd = LCD.Adafruit_CharLCDPlate()
if percentage < 10:
lcd.set_color(1.0, 0.0, 0.0)
elif percentage < 50:
lcd.set_color(1.0, 1.0, 0.0)
elif percentage > 50:
lcd.set_color(0.0, 1.0, 0.0)
message = str('%.2f' % dataleftsumgb + "/" + '%.2f' % datatotalsumgb) + " GB"
lcd.message(message)
logger.info(message)
lcd.set_cursor(0, 1)
message = str(percentage) + "% left"
lcd.message(message)
logger.info(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment