Skip to content

Commit

Permalink
Merge pull request tapaswenipathak#30 from simeg/trim-horoscope
Browse files Browse the repository at this point in the history
Trim horoscope output
  • Loading branch information
tapaswenipathak authored Sep 10, 2017
2 parents d91bdaa + 976258c commit 81b97c9
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions pyhoroscope.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import urllib.request
from lxml import etree
import re


####################################################################
# API
####################################################################

class Horoscope:
def __init__(self):
pass

@staticmethod
def get_todays_horoscope(sunsign):
url = "https://www.ganeshaspeaks.com/horoscopes/daily-horoscope/" + sunsign
response = urllib.request.urlopen(url)
htmlparser = etree.HTMLParser()
tree = etree.parse(response, htmlparser)
html_parser = etree.HTMLParser()
tree = etree.parse(response, html_parser)
date = str(tree.xpath(
"//*[@id=\"daily\"]/div/div[1]/div[1]/div[2]/div/p/text()"))
"//*[@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()"))
"//*[@id=\"daily\"]/div/div[1]/div[2]/p[1]/text()"))
horoscope = horoscope.replace("[\"\\r\\n ", "").replace(" \\r\\n \\r\\n \"]", "")
horoscope = horoscope.strip()
dict = {
'date': date,
'horoscope': horoscope,
Expand All @@ -32,14 +36,17 @@ def get_todays_horoscope(sunsign):
def get_weekly_horoscope(sunsign):
url = "https://www.ganeshaspeaks.com/horoscopes/weekly-horoscope/" + sunsign
response = urllib.request.urlopen(url)
htmlparser = etree.HTMLParser()
tree = etree.parse(response, htmlparser)
html_parser = etree.HTMLParser()
tree = etree.parse(response, html_parser)
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", "-")
"//*[@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("']", "")
"//*[@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("']", "")
horoscope = horoscope.strip()
dict = {
'week': week,
'horoscope': horoscope,
Expand All @@ -52,14 +59,16 @@ def get_weekly_horoscope(sunsign):
def get_monthly_horoscope(sunsign):
url = "https://www.ganeshaspeaks.com/horoscopes/monthly-horoscope/" + sunsign
response = urllib.request.urlopen(url)
htmlparser = etree.HTMLParser()
tree = etree.parse(response, htmlparser)
html_parser = etree.HTMLParser()
tree = etree.parse(response, html_parser)
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("']", "")
"//*[@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]"))
"//*[@id=\"daily\"]/div/div[1]/div[2]/p[1]/text()[1]"))
horoscope = horoscope.replace("\\r\\n ", "").replace("['", "").replace("']", "")
horoscope = horoscope.strip()
dict = {
'month': month,
'horoscope': horoscope,
Expand All @@ -72,14 +81,18 @@ def get_monthly_horoscope(sunsign):
def get_yearly_horoscope(sunsign):
url = "https://www.ganeshaspeaks.com/horoscopes/yearly-horoscope/" + sunsign
response = urllib.request.urlopen(url)
htmlparser = etree.HTMLParser()
tree = etree.parse(response, htmlparser)
html_parser = etree.HTMLParser()
tree = etree.parse(response, html_parser)
year = str(tree.xpath(
"//*[@id=\"daily\"]/div/div[1]/div[1]/div[2]/div/p/text()"))
"//*[@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", "")
"//*[@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", "")
horoscope = horoscope.strip()
dict = {
'year': year,
'horoscope': horoscope,
Expand Down

0 comments on commit 81b97c9

Please sign in to comment.