From 8a484dfc37ff7ef5754d33e09eb99d05e02a21fa Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 17 Oct 2018 02:44:59 +0200 Subject: Initial Commit + simple python script dumping all caps in the db --- .gitignore | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 29 ++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..521e6e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +venv/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# .idea +.idea + +# project stuff +info.json diff --git a/main.py b/main.py new file mode 100644 index 0000000..60b12c0 --- /dev/null +++ b/main.py @@ -0,0 +1,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() -- cgit v1.2.3-18-g5258