<commit_before>#!/usr/bin/env python
# =============================================================================
# file = api.py
# description = System Information API
# author = GR <https://github.com/shortdudey123>
# create_date = 2014-07-25
# mod_date = 2014-07-25
# version = 0.1
# usage = 
# notes =
# python_ver = 2.7.6
# =============================================================================

from flask import Flask, render_template, abort, redirect, url_for, request, jsonify
from flask.ext import restful

import sys
import platform
import time
import datetime

from filesystem import getFilesystemData

app = Flask(__name__)
api = restful.Api(app)

class sysInfo(restful.Resource):
    def get(self):
        sysData = createSysDict()
        return jsonify(sysData)

class sysInfoReq(restful.Resource):
    def get(self, sysReq):
        sysData = createSysDict()
        if sysReq in sysData.keys():
            return jsonify({sysReq:sysData[sysReq]})
        else:
            return not_found()

class pythonInfo(restful.Resource):
    def get(self):
        pythonData = createPythonDict()
        return jsonify(pythonData)

class pythonInfoReq(restful.Resource):
    def get(self, pythonReq):
        pythonData = createPythonDict()
        if pythonReq in pythonData.keys():
            return jsonify({pythonReq:pythonData[pythonReq]})
        else:
            return not_found()

class filesysInfo(restful.Resource):
    def get(self):
        filesysData = getFilesystemData()
        return jsonify(filesysData)

@app.route('/')
def index():
    sysData = createSysDict()
    pythonData = createPythonDict()
    return render_template('index.html', sysData=sysData, pythonData=pythonData)

# based on http://blog.luisrei.com/articles/flaskrest.html
@app.errorhandler(404)
def not_found(error=None):
    message = {
            'status': 404,
            'message': 'Not Found: ' + request.url,
    }
    response = jsonify(message)
    response.status_code = 404

    return response

def createSysDict():
    ret = {}
    ret['Platform'] = sys.platform
    ret['Arch'] = platform.architecture()
    ret['MachineType'] = platform.machine()
    ret['Name'] = platform.node()
    ret['Processor'] = platform.processor()
    ret['System'] = platform.system()
    ret['Release'] = platform.release()
    ret['Uname'] = platform.uname()

    # OS specific info
    if platform.system() == 'Linux':
        ret['Dist'] = platform.linux_distribution()
    elif platform.system() == 'Windows':
        ret['WinVer'] = sys.getwindowsversion()

    # time info
    ret['Time'] = time.time()
    ret['DateTime'] = datetime.datetime.now()

    return ret


def createPythonDict():
    ret = {}
    ret['Copyright'] = sys.copyright
    ret['Path'] = sys.path
    ret['Version'] = sys.version

    return ret

api.add_resource(sysInfo, '/api/1/SysInfo')
api.add_resource(sysInfoReq, '/api/1/SysInfo/<string:sysReq>')
api.add_resource(pythonInfo, '/api/1/PythonInfo')
api.add_resource(pythonInfoReq, '/api/1/PythonInfo/<string:pythonReq>')
api.add_resource(filesysInfo, '/api/1/FilesystemInfo')

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)<commit_msg>add fs breakdown<commit_after>#!/usr/bin/env python
# =============================================================================
# file = api.py
# description = System Information API
# author = GR <https://github.com/shortdudey123>
# create_date = 2014-07-25
# mod_date = 2014-07-25
# version = 0.1
# usage = 
# notes =
# python_ver = 2.7.6
# =============================================================================

from flask import Flask, render_template, abort, redirect, url_for, request, jsonify
from flask.ext import restful

import sys
import platform
import time
import datetime
import re

from filesystem import getFilesystemData

app = Flask(__name__)
api = restful.Api(app)

class sysInfo(restful.Resource):
    def get(self):
        sysData = createSysDict()
        return jsonify(sysData)

class sysInfoReq(restful.Resource):
    def get(self, sysReq):
        sysData = createSysDict()
        if sysReq in sysData.keys():
            return jsonify({sysReq:sysData[sysReq]})
        else:
            return not_found()

class pythonInfo(restful.Resource):
    def get(self):
        pythonData = createPythonDict()
        return jsonify(pythonData)

class pythonInfoReq(restful.Resource):
    def get(self, pythonReq):
        pythonData = createPythonDict()
        if pythonReq in pythonData.keys():
            return jsonify({pythonReq:pythonData[pythonReq]})
        else:
            return not_found()

class filesysInfo(restful.Resource):
    def get(self):
        filesysData = getFilesystemData()
        return jsonify(filesysData)

class filesysInfoReq(restful.Resource):
    def get(self, filesysReq):
        filesysData = getFilesystemData()
        filesysReqPath = re.sub('_', '/', filesysData)
        if filesysReqPath in filesysData.keys():
            return jsonify({filesysReqPath:filesysReqPath[filesysReqPath]})
        else:
            return not_found()

@app.route('/')
def index():
    sysData = createSysDict()
    pythonData = createPythonDict()
    return render_template('index.html', sysData=sysData, pythonData=pythonData)

# based on http://blog.luisrei.com/articles/flaskrest.html
@app.errorhandler(404)
def not_found(error=None):
    message = {
            'status': 404,
            'message': 'Not Found: ' + request.url,
    }
    response = jsonify(message)
    response.status_code = 404

    return response

def createSysDict():
    ret = {}
    ret['Platform'] = sys.platform
    ret['Arch'] = platform.architecture()
    ret['MachineType'] = platform.machine()
    ret['Name'] = platform.node()
    ret['Processor'] = platform.processor()
    ret['System'] = platform.system()
    ret['Release'] = platform.release()
    ret['Uname'] = platform.uname()

    # OS specific info
    if platform.system() == 'Linux':
        ret['Dist'] = platform.linux_distribution()
    elif platform.system() == 'Windows':
        ret['WinVer'] = sys.getwindowsversion()

    # time info
    ret['Time'] = time.time()
    ret['DateTime'] = datetime.datetime.now()

    return ret


def createPythonDict():
    ret = {}
    ret['Copyright'] = sys.copyright
    ret['Path'] = sys.path
    ret['Version'] = sys.version

    return ret

api.add_resource(sysInfo, '/api/1/SysInfo')
api.add_resource(sysInfoReq, '/api/1/SysInfo/<string:sysReq>')
api.add_resource(pythonInfo, '/api/1/PythonInfo')
api.add_resource(pythonInfoReq, '/api/1/PythonInfo/<string:pythonReq>')
api.add_resource(filesysInfo, '/api/1/FilesystemInfo')
api.add_resource(filesysInfoReq, '/api/1/FilesystemInfo/<string:filesysReq>')

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)
{'fraction_non_alphanumeric': 0.1749488453668518, 'fraction_numerical': 0.013592516807950891, 'mean_word_length': 3.608080808080808, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '1812146', 'n_tokens_mistral': 2158, 'n_tokens_neox': 2048, 'n_words': 432}