47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from flask import Flask
|
|
from flask_restful import Resource, Api, reqparse
|
|
import pandas as pd
|
|
import numpy as np
|
|
import ast
|
|
import kiss
|
|
import glob
|
|
app = Flask(__name__)
|
|
api = Api(app)
|
|
|
|
class Users(Resource):
|
|
def get(self):
|
|
data = pd.read_csv('users.csv') # read CSV
|
|
data = data.to_dict(orient = 'records') # convert dataframe to dictionary
|
|
return {'data': data}, 200 # return data and 200 OK code
|
|
|
|
class Locations(Resource):
|
|
def get(self):
|
|
data = pd.read_csv('locations.csv') # read CSV
|
|
data = data.to_dict(orient = 'records') # convert dataframe to dictionary
|
|
return {'data': data}, 200 # return data and 200 OK code
|
|
|
|
# Read some log files
|
|
list_stacked = pd.DataFrame()
|
|
file_list = glob.glob("logs/*.log")
|
|
#print(file_list)
|
|
for file in file_list:
|
|
file1 = pd.read_csv(file)
|
|
list_stacked = pd.concat([list_stacked, file1])
|
|
# TODO Can we do this without numpy?
|
|
list_stacked.replace(np.nan, 0, inplace=True)
|
|
#print(list_stacked.head())
|
|
|
|
class Packets(Resource):
|
|
def get(self):
|
|
data = list_stacked
|
|
data = data.to_dict(orient = 'records') # convert dataframe to dictionary
|
|
#data = data.to_json(orient='records')
|
|
return {'data': data}, 200 # return data and 200 OK code
|
|
|
|
api.add_resource(Users, '/users') # '/users' is our entry point for Users
|
|
api.add_resource(Locations, '/locations') # and '/locations' is our entry point for Locations
|
|
api.add_resource(Packets, '/packets') # and '/locations' is our entry point for Locations
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True) # run our Flask app
|