<commit_before>#!/usr/bin/env python3
import requests
import pickle
import socket
import os
import json

MAPURL = 'https://map.stormarn.freifunk.net/data/nodelist.json'
HOST = '0.0.0.0'
PORT = '2004'
NEW = True


def packMessage():
    payload = pickle.dumps(listOfMetricTuples, protocol=2)
    header = struct.pack("!L", len(payload))
    message = header + payload
    return message


def getData(url):
    r = requests.get(url)
    if r.status_code == 200:
        data = r.json()
        with open('nodes.json', 'w') as outfile:
            json.dump(data, outfile)
        return data
    else:
        return "error"


def parseData(data):
    for entry in data['nodes']:
        pass


def sendMessage(data):
    connection = socket.create_connection((HOST, PORT))
    connection.send(data)
    connection.close()


def main():
    if(NEW):
        print('Loading new file')
        data = getData(MAPURL)
        if data != "error":
            parseData(data)
        else:
            print("error")
    else:
        print('Using old file')
        with open('nodes.json', 'r') as infile:
            data = json.load(infile)
        parseData(data)
        return data


if __name__ == '__main__':
    main()<commit_msg>stuff<commit_after>#!/usr/bin/env python3
import requests
import json
import time
from influxdb import InfluxDBClient

MAPURL = 'https://map.stormarn.freifunk.net/data/nodelist.json'
HOST = '127.0.0.1'
PORT = '2004'
NEW = True
USER = 'python'
PASSWORD = ''


def getData(url):
    r = requests.get(url)
    if r.status_code == 200:
        data = r.json()
        with open('nodes.json', 'w') as outfile:
            json.dump(data, outfile)
        return data
    else:
        return "error"


def parseData(data):
    nodeList = []
    timestamp = int(time.time())

    for entry in data['nodes']:
        node = {}
        node['measurement'] = "client_count"
        node['tags'] = {}
        node['tags']['id'] = str(entry['id'])
        node['tags']['name'] = str(entry['name'])
        node['time'] = timestamp
        node['fields'] = {}
        node['fields']['value'] = str(entry['status']['clients'])
        nodeList.append(node)
    return nodeList


def sendMessage(data):
    client = InfluxDBClient('localhost', 8086, USER, PASSWORD, '<PASSWORD>')
    # Optional
    # client.create_database('freifunk')
    client.write_points(data, 's')
    return "ok"  # "Result: {0}".format(result)


def main():
    if(NEW):
        print('Loading new file')
        data = getData(MAPURL)
        if data != "error":
            print(sendMessage(parseData(data)))
        else:
            print("error")
    else:
        print('Using old file')
        with open('nodes.json', 'r') as infile:
            data = json.load(infile)
            print(sendMessage(parseData(data)))


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.14785040195735757, 'fraction_numerical': 0.01118490038448095, 'mean_word_length': 2.4902439024390244, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5067053', 'n_tokens_mistral': 946, 'n_tokens_neox': 907, 'n_words': 214}