Skip to content

Instantly share code, notes, and snippets.

Last active September 11, 2019 22:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Save data to InfluxDB
#!/usr/bin/env python
import argparse
import delegator
import json
import requests
def run(client_id, influx_db):
cmd ='speedtest-cli --json')
data_text = cmd.out
data = json.loads(data_text)
data_map = {
'net_download': data['download'],
'net_upload': data['upload'],
db_data = []
for key, value in data_map.items():
db_data.append('%s,client_id=%s, value=%s'
% (key, client_id, value))
db_data = '\n'.join(db_data), data=db_data)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--client_id', required=True,
help='client id stored in DB with results')
parser.add_argument('-d', '--influx_db', required=True,
help='InfluxDB URI, including db etc')
args = parser.parse_args()
run(args.client_id, args.influx_db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment