forked from tapaswenipathak/Horoscope-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
76 lines (58 loc) · 2.36 KB
/
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
72
73
74
75
76
from flask import Flask, jsonify
from horoscope import Horoscope
app = Flask(__name__)
############################################
# Index
############################################
@app.route('/', methods=['GET'])
def index_route():
return jsonify({
'author': 'Tapasweni Pathak',
'author_url': 'http://tapasweni-pathak.github.io/',
'base_url': 'horoscope-api.herokuapp.com',
'project_name': 'Horoscope API',
'project_url': 'http://tapasweni-pathak.github.io/Horoscope-API',
'project_issues': 'https://github.com/tapasweni-pathak/Horoscope-API/issues',
'endpoints': {
'Today\'s Horosocope': '/horoscope/today/{sunsign}',
'Weekly Horoscope': 'horoscope/week/{sunsign}',
'Monthly Horoscope': 'horoscope/month/{sunsign}',
'Yearly Horosope': 'horoscope/year/{sunsign}',
}
})
############################################
# Horoscopes
###########################################
# Todays' Horoscope
@app.route('/horoscope/today/<sunsign>', methods=['GET'])
def today_horoscope_route(sunsign):
result = dict(Horoscope.get_todays_horoscope(sunsign))
return jsonify(date=result['date'],
sunsign=result['sunsign'],
horoscope=result['horoscope'])
# Current Week Horoscope
@app.route('/horoscope/week/<sunsign>', methods=['GET'])
def weekly_horoscope_route(sunsign):
result = dict(Horoscope.get_weekly_horoscope(sunsign))
return jsonify(week=result['week'],
sunsign=result['sunsign'],
horoscope=result['horoscope'])
# Current Month Horoscope
@app.route('/horoscope/month/<sunsign>', methods=['GET'])
def monthly_horoscope_route(sunsign):
result = dict(Horoscope.get_monthly_horoscope(sunsign))
return jsonify(month=result['month'],
sunsign=result['sunsign'],
horoscope=result['horoscope'])
# Current Year Horoscope
@app.route('/horoscope/year/<sunsign>', methods=['GET'])
def yearly_horoscope_route(sunsign):
result = dict(Horoscope.get_yearly_horoscope(sunsign))
return jsonify(year=result['year'],
sunsign=result['sunsign'],
horoscope=result['horoscope'])
###########################################
# Start Flask
###########################################
if __name__ == "__main__":
app.run()