Telenet telemeter
Posted: Wednesday 17 January 2018 19:21
I made my first script ever to check how many GB's I downloaded this month by parsing telenet's webtool.
to get this code working you need to have the requests package installed.
On my rpi it ran only on python2 but with some warning in the terminal, i got an error with python3. On my pc it ran fine with python3.
I run this script with crontab and it works fine

Code: Select all
import requests
DOMOTICZ_IP = 'http://192.168.*.**:8080'
DEVICE_IDX = 'your dummy counter idx'
POST_LOGIN_URL = "https://login.prd.telenet.be/openid/login"
REQUEST_URL ="https://api.prd.telenet.be/ocapi/public/?p=internetusage,internetusagereminder"
payload = {
"j_username": "your username",
"j_password": "your password"
}
COOKIE = #your request cookie
with requests.Session() as session:
post = session.post(POST_LOGIN_URL, data=payload)
# print(post.status_code)
page = session.get(REQUEST_URL,headers=headers)
# print(page.status_code)
# print(page.content)
file = page.json()
KBCOUNTER = file['internetusage'][0]['availableperiods'][0]['usages'][0]['totalusage']['includedvolume']
COUNTER = str(KBCOUNTER / 1048576)
#print(COUNTER)
requests.get(DOMOTICZ_IP + "/json.htm?type=command¶m=udevice&idx=" + DEVICE_IDX + "&svalue=" + COUNTER)
On my rpi it ran only on python2 but with some warning in the terminal, i got an error with python3. On my pc it ran fine with python3.
I run this script with crontab and it works fine
