forked from tapaswenipathak/Horoscope-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6ee8a8c
commit 1fc3978
Showing
4 changed files
with
142 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import urllib.request | ||
from lxml import etree | ||
import re | ||
|
||
#################################################################### | ||
# API | ||
#################################################################### | ||
|
||
class Horoscope: | ||
|
||
@staticmethod | ||
def get_todays_horoscope(sunsign): | ||
url = "http://www.ganeshaspeaks.com/horoscopes/daily-horoscope/" + sunsign | ||
response = urllib.request.urlopen(url) | ||
htmlparser = etree.HTMLParser() | ||
tree = etree.parse(response, htmlparser) | ||
date = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[1]/div[2]/div/p/text()")) | ||
date = date.replace("['", "").replace("']", "").replace("['(", "").replace(")']", "") | ||
horoscope = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[2]/p[1]/text()")) | ||
horoscope = horoscope.replace("[\"\\r\\n ", "").replace(" \\r\\n \\r\\n \"]", "") | ||
dict = { | ||
'date': date, | ||
'horoscope': horoscope, | ||
'sunsign': sunsign | ||
} | ||
|
||
return dict | ||
|
||
@staticmethod | ||
def get_weekly_horoscope(sunsign): | ||
url = "http://www.ganeshaspeaks.com/horoscopes/weekly-horoscope/" + sunsign | ||
response = urllib.request.urlopen(url) | ||
htmlparser = etree.HTMLParser() | ||
tree = etree.parse(response, htmlparser) | ||
week = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[1]/div[2]/div/p/text()")) | ||
week = week.replace("['", "").replace("[u'\\n", "").replace("']", "").replace("\\u2013", "-") | ||
horoscope = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[2]/p[1]/text()")) | ||
horoscope = horoscope.replace("\\r\\n ", "").replace(" \\r\\n ", "").replace(" \\r\\n \\r\\n ", "").replace("['", "").replace("']", "") | ||
dict = { | ||
'week': week, | ||
'horoscope': horoscope, | ||
'sunsign': sunsign | ||
} | ||
|
||
return dict | ||
|
||
@staticmethod | ||
def get_monthly_horoscope(sunsign): | ||
url = "http://www.ganeshaspeaks.com/horoscopes/monthly-horoscope/" + sunsign | ||
response = urllib.request.urlopen(url) | ||
htmlparser = etree.HTMLParser() | ||
tree = etree.parse(response, htmlparser) | ||
month = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[1]/div[2]/div/p/text()")) | ||
month = month.replace("['", "").replace("\\r\\n ", "").replace("['\\n", "").replace("']", "") | ||
horoscope = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[2]/p[1]/text()[1]")) | ||
horoscope = horoscope.replace("\\r\\n ", "").replace("['", "").replace("']", "") | ||
dict = { | ||
'month': month, | ||
'horoscope': horoscope, | ||
'sunsign': sunsign | ||
} | ||
|
||
return dict | ||
|
||
@staticmethod | ||
def get_yearly_horoscope(sunsign): | ||
url = "http://www.ganeshaspeaks.com/horoscopes/yearly-horoscope/" + sunsign | ||
response = urllib.request.urlopen(url) | ||
htmlparser = etree.HTMLParser() | ||
tree = etree.parse(response, htmlparser) | ||
year = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[1]/div[2]/div/p/text()")) | ||
year = year.replace("['", "").replace("['\\n", "").replace("']", "") | ||
horoscope = str(tree.xpath( | ||
"//*[@id=\"daily\"]/div/div[1]/div[2]/p[1]/text()")) | ||
horoscope = horoscope.replace("['\\r\\n ", "").replace(" \\r\\n \\r\\n ", "").replace("[u'", "").replace("']", "").replace("\\xe2\\x80\\x99s", "") | ||
dict = { | ||
'year': year, | ||
'horoscope': horoscope, | ||
'sunsign': sunsign | ||
} | ||
|
||
return dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
Flask==0.10.1 | ||
Jinja2==2.7.3 | ||
MarkupSafe==0.23 | ||
Werkzeug==0.9.6 | ||
gunicorn==19.3.0 | ||
itsdangerous==0.24 | ||
newrelic==2.54.0.41 | ||
horoscope==1.0.5 | ||
wsgiref==0.1.2 | ||
Flask | ||
Jinja2 | ||
MarkupSafe | ||
Werkzeug | ||
gunicorn | ||
itsdangerous | ||
newrelic | ||
lxml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,64 @@ | ||
from flask import Flask, jsonify | ||
from horoscope import Horoscope | ||
from pyhoroscope import Horoscope | ||
|
||
app = Flask(__name__) | ||
app = Flask (__name__) | ||
|
||
############################################ | ||
# Index | ||
# Index | ||
############################################ | ||
|
||
|
||
@app.route('/', methods=['GET']) | ||
def index_route(): | ||
@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}', | ||
} | ||
}) | ||
'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']) | ||
#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 | ||
#Start Flask | ||
########################################### | ||
|
||
if __name__ == "__main__": | ||
app.run() | ||
app.run() |