Skip to content

Instantly share code, notes, and snippets.

@frafra frafra/
Created Jun 28, 2018

What would you like to do? 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
import copy
parse_timespan = copy.copy(humanfriendly.parse_timespan)
humanfriendly.parse_timespan = lambda s: sum(map(parse_timespan, s.split()))
BASE = ""
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.get("/iliad", output=hug.output_format.json)
def iliad(username: hug.types.text, password: hug.types.text):
""" basic account information parser """
data = {'login-ident': username, 'login-pwd': password}
response =, 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)
phone_field = soup.find_all(class_='smaller')[3]
phone_number = extractDigits(phone_field.text)
response['phone_number'] = phone_number
return response
if __name__ == '__main__':
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.