Skip to content

Commit

Permalink
Merge pull request #98 from akarshghildyal/horoscope
Browse files Browse the repository at this point in the history
feat: horoscope in api programs
  • Loading branch information
Avdhesh-Varshney committed Jul 12, 2024
2 parents 446d18e + 8016606 commit 3846afe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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

0 comments on commit 3846afe

Please sign in to comment.