From 3b96c1c3b5de5e19b3700d21433c544bd5191bf2 Mon Sep 17 00:00:00 2001 From: Kim-R2O <67785939+Kim-R2O@users.noreply.github.com> Date: Fri, 3 Jul 2020 19:34:15 +0000 Subject: [PATCH 1/3] added daily horoscope scrapper --- web_programming/daily_horoscope.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 web_programming/daily_horoscope.py diff --git a/web_programming/daily_horoscope.py b/web_programming/daily_horoscope.py new file mode 100644 index 000000000000..2a766bd74858 --- /dev/null +++ b/web_programming/daily_horoscope.py @@ -0,0 +1,28 @@ +from bs4 import BeautifulSoup as bs +import requests + +def horoscope(): + print('Your daily Horoscope. \n') + print('enter your Zodiac sign number:\n', + '1. Aries\n','2. Taurus\n', + '3. Gemini\n', '4. Cancer\n', + '5. Leo\n', '6. Virgo\n', + '7. Libra\n', '8. Scorpio\n', + '9. Sagittarius\n', '10. Capricorn\n', + '11. Aquarius\n', '12. Pisces\n') + + z_sign = input('number> ') + print('choose some day:\n', 'yesterday\n', 'today\n', 'tomorrow\n') + day = input('enter the day> ') + + url = f'https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{day}.aspx?sign={z_sign}' + try: #exception handling for wrong day input + soup = bs(requests.get(url).content, 'html.parser') + s = soup.find('div', class_= 'main-horoscope') + print('*' * 70) + print(s.p.text) #horoscope text for chosen Zodiac sign + except: + print('it seems like you made a mistake in spelling the Day word. Please check your input and try again') + +if __name__ == "__main__": + horoscope() From edbf1bf21c0c9af809d01a2c6b094a4f6805ab7d Mon Sep 17 00:00:00 2001 From: Kim-R2O <67785939+Kim-R2O@users.noreply.github.com> Date: Sat, 4 Jul 2020 14:23:57 +0000 Subject: [PATCH 2/3] Update daily horoscope scrapper script code refactoring, script editing --- web_programming/daily_horoscope.py | 55 +++++++++++++++++------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/web_programming/daily_horoscope.py b/web_programming/daily_horoscope.py index 2a766bd74858..ac156e23897e 100644 --- a/web_programming/daily_horoscope.py +++ b/web_programming/daily_horoscope.py @@ -1,28 +1,35 @@ -from bs4 import BeautifulSoup as bs +from bs4 import BeautifulSoup import requests -def horoscope(): - print('Your daily Horoscope. \n') - print('enter your Zodiac sign number:\n', - '1. Aries\n','2. Taurus\n', - '3. Gemini\n', '4. Cancer\n', - '5. Leo\n', '6. Virgo\n', - '7. Libra\n', '8. Scorpio\n', - '9. Sagittarius\n', '10. Capricorn\n', - '11. Aquarius\n', '12. Pisces\n') - - z_sign = input('number> ') - print('choose some day:\n', 'yesterday\n', 'today\n', 'tomorrow\n') - day = input('enter the day> ') - - url = f'https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{day}.aspx?sign={z_sign}' - try: #exception handling for wrong day input - soup = bs(requests.get(url).content, 'html.parser') - s = soup.find('div', class_= 'main-horoscope') - print('*' * 70) - print(s.p.text) #horoscope text for chosen Zodiac sign - except: - print('it seems like you made a mistake in spelling the Day word. Please check your input and try again') + +def horoscope(zodiac_sign: int, day: str) -> str: + url = ( + "https://www.horoscope.com/us/horoscopes/general/" + f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}" + ) + soup = BeautifulSoup(requests.get(url).content, "html.parser") + return soup.find("div", class_="main-horoscope").p.text + if __name__ == "__main__": - horoscope() + print("Daily Horoscope. \n") + print( + "enter your Zodiac sign number:\n", + "1. Aries\n", + "2. Taurus\n", + "3. Gemini\n", + "4. Cancer\n", + "5. Leo\n", + "6. Virgo\n", + "7. Libra\n", + "8. Scorpio\n", + "9. Sagittarius\n", + "10. Capricorn\n", + "11. Aquarius\n", + "12. Pisces\n", + ) + zodiac_sign = input("number> ") + print("choose some day:\n", "yesterday\n", "today\n", "tomorrow\n") + day = input("enter the day> ") + horoscope_text = horoscope(zodiac_sign, day) + print(horoscope_text) From b2362b5b58938318dbd2480dad3bd06dcb7c568c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 10 Jul 2020 17:23:36 +0200 Subject: [PATCH 3/3] Update web_programming/daily_horoscope.py --- web_programming/daily_horoscope.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_programming/daily_horoscope.py b/web_programming/daily_horoscope.py index ac156e23897e..ecb37ce106f4 100644 --- a/web_programming/daily_horoscope.py +++ b/web_programming/daily_horoscope.py @@ -28,7 +28,7 @@ def horoscope(zodiac_sign: int, day: str) -> str: "11. Aquarius\n", "12. Pisces\n", ) - zodiac_sign = input("number> ") + zodiac_sign = int(input("number> ").strip()) print("choose some day:\n", "yesterday\n", "today\n", "tomorrow\n") day = input("enter the day> ") horoscope_text = horoscope(zodiac_sign, day)