-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
181 lines (142 loc) · 5.1 KB
/
app.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from flask import Flask, request, send_file, Response
from flask_restful import Api, Resource, reqparse
from flask_jwt import JWT
from boto3 import client
from configparser import ConfigParser
import json
import os
# BSE Imports
from bse import bse_latest_ca
from bse import bse_company_ca
# NSE Imports
from nse import nse_latest_ca
from nse import nse_company_ca
# MoneyControl Imports
from money_control import money_control_upcoming_ca
from money_control import money_control_company_ca
from user_email_subscribe import add_to_subscriber_list as subscribe
configure = ConfigParser()
configure.read("secret.ini")
ACCESS_KEY = configure.get("AWS", "ACCESS_KEY")
SECRET_KEY = configure.get("AWS", "SECRET_KEY")
BUCKET = configure.get("AWS", "BUCKET")
REGION = configure.get("AWS", "REGION")
app = Flask(__name__, static_url_path="/public", static_folder="public/")
app.config["PROPAGATE_EXCEPTIONS"] = True
app.secret_key = "Pratik"
api = Api(app)
def get_client():
return client(
's3',
REGION,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
# BSE Latest corporate action from the database(Server)
class LatestCA_BSE(Resource):
def get(self):
return {"latest_ca": bse_latest_ca.latest_ca(request)}
# BSE Particular company corporate action from historical data
class CompanyCA_BSE(Resource):
def get(self, code):
return {"ca": bse_company_ca.company_ca(code)}
# BSE PDF
class PDF_BSE(Resource):
def get(self):
KEY = 'Latest Corporate Actions BSE.pdf'
s3 = get_client()
file = s3.get_object(Bucket=BUCKET, Key=KEY)
return Response(
file['Body'].read(),
mimetype='application/pdf',
headers={"Content-Disposition": f"attachment;filename={KEY}"}
)
# BSE CSV
class CSV_BSE(Resource):
def get(self):
KEY = 'Latest Corporate Actions BSE.csv'
s3 = get_client()
file = s3.get_object(Bucket=BUCKET, Key=KEY)
return Response(
file['Body'].read(),
mimetype='application/csv',
headers={"Content-Disposition": f"attachment;filename={KEY}"}
)
# NSE Latest corporate action from the database
class LatestCA_NSE(Resource):
def get(self):
return {"latest_ca": nse_latest_ca.latest_ca(request)}
# NSE Particular company corporate action from historical data
class CompanyCA_NSE(Resource):
def get(self, code):
return {"ca": nse_company_ca.company_ca(code)}
# NSE PDF
class PDF_NSE(Resource):
def get(self):
KEY = 'Latest Corporate Actions NSE.pdf'
s3 = get_client()
file = s3.get_object(Bucket=BUCKET, Key=KEY)
return Response(
file['Body'].read(),
mimetype='application/pdf',
headers={"Content-Disposition": f"attachment;filename={KEY}"}
)
# NSE CSV
class CSV_NSE(Resource):
def get(self):
KEY = 'Latest Corporate Actions NSE.csv'
s3 = get_client()
file = s3.get_object(Bucket=BUCKET, Key=KEY)
return Response(
file['Body'].read(),
mimetype='application/csv',
headers={"Content-Disposition": f"attachment;filename={KEY}"}
)
# Money Control Latest corporate action from the database
class LatestCA_MC(Resource):
def get(self):
return {"latest_ca": money_control_upcoming_ca.latest_ca(request)}
# Money Control Particular company corporate action from historical data
class CompanyCA_MC(Resource):
def get(self, code):
return {"ca": money_control_company_ca.company_ca(code)}
# Money Control PDF
class PDF_MC(Resource):
def get(self):
KEY = 'Latest Corporate Actions MC.pdf'
s3 = get_client()
file = s3.get_object(Bucket=BUCKET, Key=KEY)
return Response(
file['Body'].read(),
mimetype='application/pdf',
headers={"Content-Disposition": f"attachment;filename={KEY}"}
)
# BSE MC
class CSV_MC(Resource):
def get(self):
KEY = 'Latest Corporate Actions MC.csv'
s3 = get_client()
file = s3.get_object(Bucket=BUCKET, Key=KEY)
return Response(
file['Body'].read(),
mimetype='application/csv',
headers={"Content-Disposition": f"attachment;filename={KEY}"}
)
class Subscribe(Resource):
def post(self):
return subscribe.add_as_subscriber(request)
api.add_resource(LatestCA_BSE, "/api/bse_latestca")
api.add_resource(CompanyCA_BSE, "/api/bse_companyca/<string:code>")
api.add_resource(PDF_BSE, "/download/bse_pdf")
api.add_resource(CSV_BSE, "/download/bse_csv")
api.add_resource(LatestCA_NSE, "/api/nse_latestca")
api.add_resource(CompanyCA_NSE, "/api/nse_companyca/<string:code>")
api.add_resource(PDF_NSE, "/download/nse_pdf")
api.add_resource(CSV_NSE, "/download/nse_csv")
api.add_resource(LatestCA_MC, "/api/mc_latestca")
api.add_resource(CompanyCA_MC, "/api/mc_companyca/<string:code>")
api.add_resource(PDF_MC, "/download/mc_pdf")
api.add_resource(CSV_MC, "/download/mc_csv")
api.add_resource(Subscribe, "/api/subscribe")
if __name__ == "__main__":
app.run(port=5000, debug=True)