This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathserver.py
66 lines (53 loc) · 1.89 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
from flask import Flask, jsonify
from pyhoroscope import Horoscope
from flask_cors import CORS
app = Flask (__name__)
CORS(app)
############################################
# 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'
})
############################################
# 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()