Skip to content

Instantly share code, notes, and snippets.

@frafra frafra/iliad.py
Created Jun 28, 2018

Embed
What would you like to do?
iliad.it basic account information parser
#!/usr/bin/env python3
import bs4 # fades beautifulsoup4
import hug # fades
import humanfriendly # fades
import requests # fades
import datetime
import string
# https://github.com/xolox/python-humanfriendly/issues/29
import copy
parse_timespan = copy.copy(humanfriendly.parse_timespan)
humanfriendly.parse_timespan = lambda s: sum(map(parse_timespan, s.split()))
BASE = "https://www.iliad.it/account/"
def extractDigits(text):
result = ""
for character in text:
if character in string.digits:
result += character
return result
parser = {
1: lambda s: {'calls': humanfriendly.parse_timespan(s)},
3: lambda s: {'SMS': int(extractDigits(s))},
5: lambda s: {'data': humanfriendly.parse_size(s.replace(",", "."))},
9: lambda s: {'MMS': int(extractDigits(s))},
}
@hug.cli()
@hug.get("/iliad", output=hug.output_format.json)
def iliad(username: hug.types.text, password: hug.types.text):
""" iliad.it basic account information parser """
data = {'login-ident': username, 'login-pwd': password}
response = requests.post(BASE, data=data)
soup = bs4.BeautifulSoup(response.text, 'html.parser')
highlighted = soup.find_all(class_='red')
response = {}
for index, item in enumerate(highlighted):
if index in parser:
information = parser[index](item.text)
response.update(information)
phone_field = soup.find_all(class_='smaller')[3]
phone_number = extractDigits(phone_field.text)
response['phone_number'] = phone_number
return response
if __name__ == '__main__':
iliad.interface.cli()
bs4
hug
humanfriendly
requests
from iliad import __hug_wsgi__ as application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.