summaryrefslogtreecommitdiffstats
path: root/main.py
blob: 60b12c0d1a2510d2f745746c358f01c13afe570b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import json
import mysql.connector

with open ('/webspace/path/info.json', 'w') as f:
	cnx = mysql.connector.connect(user='user', password="pass", database='db')
	cursor = cnx.cursor()
	cursor.execute("SELECT node FROM caps_features GROUP BY subnode;")

	result = dict()
	for client in cursor:
		client = client[0]
		if client not in result.keys():
			result[client] = 1
		else:
			result[client] += 1

	cursor.close()
	cnx.close()

	try:
		f.write(json.dumps(result, indent=4, sort_keys=True))
	except FileNotFoundError:
		pass

	f.close()