Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: horoscope in api programs #98

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/apps/pages/programs/ApiPrograms/horoscope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import streamlit as st
import requests
from bs4 import BeautifulSoup

def horoscope():
def get_horoscope_by_day(zodiac_sign: int, day: str):
try:
if not "-" in day:
res = requests.get(f"https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-{day}.aspx?sign={zodiac_sign}")
else:
day = day.replace("-", "")
res = requests.get(f"https://www.horoscope.com/us/horoscopes/general/horoscope-archive.aspx?sign={zodiac_sign}&laDate={day}")

soup = BeautifulSoup(res.content, 'html.parser')
data = soup.find('div', attrs={'class': 'main-horoscope'})
return data.p.text, None
except Exception as e:
return None, str(e)

zodiac_signs = {
"Aries": 1, "Taurus": 2, "Gemini": 3, "Cancer": 4, "Leo": 5, "Virgo": 6, "Libra": 7, "Scorpio": 8, "Sagittarius": 9, "Capricorn": 10, "Aquarius": 11, "Pisces": 12
}

st.title("Daily Horoscope")

sign = st.selectbox("Select your Zodiac sign", options=list(zodiac_signs.keys()))
day = st.selectbox("Select the day", options=["today", "yesterday", "tomorrow"])
convert_button = st.button(label="Get Horoscope")

if convert_button:
zodiac_sign = zodiac_signs[sign]
horoscope_text, error = get_horoscope_by_day(zodiac_sign, day)
if horoscope_text:
st.success(horoscope_text)
else:
st.error(f"Could not retrieve horoscope data: {error}")
5 changes: 4 additions & 1 deletion src/apps/pages/programs/apiProgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def apiPrograms():
st.title('API Programs')
choice = st.selectbox('Select a program to execute', [None, "Jokes", "General Facts", "Gemini ChatBot", "Quote of the Day", "Currency Convertor", "Unit Convertor"])
choice = st.selectbox('Select a program to execute', [None, "Jokes", "General Facts", "Gemini ChatBot", "Quote of the Day", "Currency Convertor", "Unit Convertor", "Horoscope"])

st.markdown('---')

Expand All @@ -24,6 +24,9 @@ def apiPrograms():
elif choice == "Unit Convertor":
from src.apps.pages.programs.ApiPrograms.unit_converter import units_convert
units_convert()
elif choice == "Horoscope":
from src.apps.pages.programs.ApiPrograms.horoscope import horoscope
horoscope()

else:
st.info("Star this project on [GitHub](https://github.com/Avdhesh-Varshney/Jarvis), if you like it!", icon='⭐')
Expand Down