-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (59 loc) · 1.75 KB
/
main.py
File metadata and controls
76 lines (59 loc) · 1.75 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Flask, jsonify, request
import pymysql
from flask_cors import CORS
from src.modules.analysis import AnalysisClass
from src.modules.inflation import InflationClass
from src.modules.cpi import CpiClass
app = Flask(__name__)
CORS(app)
# Create a connection to the database
conn = pymysql.connect(
host='localhost',
user='root',
password='',
db='inflation_db'
)
# Create a cursor object to interact with the database
cursor = conn.cursor()
analysisClass = AnalysisClass()
inflationClass = InflationClass()
cpiClass = CpiClass()
@app.route('/', methods=['GET'])
def sample_object():
return "Returning Sample Object}"
# GET all analysis data
@app.route('/analysis/get-all', methods=['GET'])
def get_all_analysis():
try:
records = analysisClass.analysis_getall()
return records
except Exception as e:
return jsonify({'error': str(e)})
# Create an analysis
@app.route('/analysis/create', methods=['POST'])
def create_item():
try:
date = request.json['date']
description = request.json['description']
createRecord = analysisClass.create_analysis(date, description)
return createRecord
except Exception as e:
return jsonify({'error': str(e)})
# GET all inflation data
@app.route('/inflation/get-all', methods=['GET'])
def get_all_inflation():
try:
records = inflationClass.inflation_getall()
return records
except Exception as e:
return jsonify({'error': str(e)})
# GET all cpi data
@app.route('/cpi/get-all', methods=['GET'])
def get_all_cpi():
try:
cpi_records = cpiClass.cpi_getall()
return cpi_records
except Exception as e:
return jsonify({'error': str(e)})
if __name__ == '__main__':
app.run()