PyTelekomPass/PyPass.py
2018-12-09 14:32:19 +01:00

49 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
# Python Telekom Data Usage Logger
# Copyright (c) 2018 Nis Wechselberg <enbewe@enbewe.de>
#
# This work is licensed under MIT license. You should have
# received a copy of the MIT license legalcode along with this
# work. If not, see <https://opensource.org/licenses/MIT>.
# pylint: disable=C0103
"""
Python Telekom Data Usage Logger
Small script to request data from the portal pass.telekom.de and
submit it to InfluxDB
"""
import requests
from influxdb import InfluxDBClient
REQUEST_API_URL = 'http://pass.telekom.de/api/service/generic/v1/status'
REQUEST_HEADERS = {'User-Agent': 'Mozilla/4.0'}
HOST_NAME = "Neutestorf-RasPi"
# Send http request to telekom page and extract json response
response = requests.get(REQUEST_API_URL, headers=REQUEST_HEADERS)
respJson = response.json()
# Prepare timedata for database
measurement = [
{
"measurement": "pass_telekom_de",
"tags": {
"host": HOST_NAME
},
"fields": {
"initialVolume": respJson['initialVolume'],
"usedVolume": respJson['usedVolume'],
"remainingSeconds": respJson['remainingSeconds'],
"usedAtMillis": respJson['usedAt']
}
}
]
# Send data to InfluxDB
influx = InfluxDBClient(host='10.91.12.10', database='network')
influx.write_points(measurement)