Python Projects: Display the daily Horoscope for a specified sign
Python Web Project-7 with Solution
Create a Python project to display the daily Horoscope for a specified sign.
Sample Output:
Input your Zodiac sign number: 1. Aries 2. Taurus 3. Gemini 4. Cancer 5. Leo 6. Virgo 7. Libra 8. Scorpio 9. Sagittarius 10. Capricorn 11. Aquarius 12. Pisces Input a number from said list: 7 Choose some day: yesterday today tomorrow Input the day from said list: yesterday Jan 23, 2021 - There's passion in the air today, Libra. You can feel it. The feeling is so strong that the air almost pulsates. What are you going to do about it? If you're in a romantic relationship, plan an intimate evening together, free of chores and daily tasks. If you're single, peruse your little black book and see if there are any relationships worth warming up.
Sample Solution:
Python Code:
#Source:https://bit.ly/3pfYSJ6
import requests
from bs4 import BeautifulSoup
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__":
print("Daily Horoscope. \n")
print(
"Input 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 = int(input("Input a number from said list: ").strip())
print("Choose some day:\n", "yesterday\n", "today\n", "tomorrow\n")
day = input("Input the day from said list: ")
horoscope_text = horoscope(zodiac_sign, day)
print(horoscope_text)
Flowchart:
Improve this sample solutions and post your code through Disqus
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/projects/python/web-programming/python-web-programming-7.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics