-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathflask_doviz_server.py
72 lines (57 loc) · 2.28 KB
/
flask_doviz_server.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
from flask import Flask, make_response, jsonify, request
from DovizKurlari import DovizKurlari
import markdown
import markdown.extensions.fenced_code
kurlar = DovizKurlari()
app = Flask(__name__)
@app.route('/')
def index():
readme_file = open("README.md", "r")
md_template_string = markdown.markdown(readme_file.read(), extensions=["fenced_code"])
return md_template_string
@app.route('/api/doviz', methods=['GET', 'POST'])
def api_doviz():
if request.method == "GET":
return make_response(jsonify(kurlar.DegerSor()), 200)
elif request.method == 'POST':
content = request.json
tarih= content['tarih']
if "tur" in content:
tur= content['tur']
return make_response(jsonify(kurlar.Arsiv_tarih(tarih).get(tur.upper())), 201) # 201 = ARSIV
else:
return make_response(jsonify(kurlar.Arsiv_tarih(tarih)), 201) # 201 = ARSIV
@app.route('/api/doviz/<tur>', methods=['GET', 'POST'])
def api_her_doviz(tur):
if request.method == "GET":
Doviz_Value = kurlar.DegerSor().get(tur.upper())
if Doviz_Value:
return make_response(jsonify(Doviz_Value), 200)
else:
return make_response(jsonify(Doviz_Value), 404)
elif request.method == "POST": # Arsiv
content = request.json
tarih= content['tarih']
Doviz_Value = kurlar.Arsiv_tarih(tarih).get(tur.upper())
if Doviz_Value:
return make_response(jsonify(Doviz_Value), 201)
else:
return make_response(jsonify(Doviz_Value), 404)
@app.route('/api/doviz/<yil>/<ay>/<gun>', methods=['GET'])
def gun_ay_yil_api(yil,ay,gun):
if request.method == "GET":
Doviz_Value = kurlar.Arsiv(gun,ay,yil)
if Doviz_Value:
return make_response(jsonify(Doviz_Value), 200)
else:
return make_response(jsonify(Doviz_Value), 404)
@app.route('/api/doviz/<yil>/<ay>/<gun>/<tur>', methods=['GET'])
def gun_ay_yil_tur_api(yil,ay,gun,tur):
if request.method == "GET":
Doviz_Value = kurlar.Arsiv(gun,ay,yil).get(tur.upper())
if Doviz_Value:
return make_response(jsonify(Doviz_Value), 200)
else:
return make_response(jsonify(Doviz_Value), 404)
if __name__ == '__main__':
app.run(debug=True,host="0.0.0.0")