diff --git a/pyhoroscope.py b/pyhoroscope.py index 5ea1f36..4ab402f 100644 --- a/pyhoroscope.py +++ b/pyhoroscope.py @@ -1,23 +1,27 @@ import urllib.request from lxml import etree + #################################################################### # API #################################################################### class Horoscope: + def __init__(self): + pass @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) + 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 = { @@ -32,14 +36,16 @@ def get_todays_horoscope(sunsign): 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) + 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, @@ -53,13 +59,14 @@ def get_weekly_horoscope(sunsign): 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) + 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 = { @@ -74,14 +81,17 @@ def get_monthly_horoscope(sunsign): 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) + 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,