diff --git a/app/routers/profile.py b/app/routers/profile.py index 5c51d0e7..b4be7b6d 100644 --- a/app/routers/profile.py +++ b/app/routers/profile.py @@ -46,14 +46,17 @@ async def profile( session.commit() user = session.query(User).filter_by(id=1).first() - # Get on this day data from wiki + signs = ['Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', + 'Virgo', 'Libra', 'Scorpio', 'Sagittarius', + 'Capricorn', 'Aquarius', 'Pisces'] on_this_day_data = get_on_this_day_events(session) return templates.TemplateResponse("profile.html", { "request": request, "user": user, "events": upcoming_events, - "on_this_day_data": on_this_day_data + "signs": signs, + "on_this_day_data": on_this_day_data, }) diff --git a/app/static/horoscope.js b/app/static/horoscope.js new file mode 100644 index 00000000..70114aec --- /dev/null +++ b/app/static/horoscope.js @@ -0,0 +1,28 @@ +function sendSignDescription(singName) { + const sign = singName.toLowerCase(); + const signData = "https://aztro.sameerkumar.website/?sign=" + sign + + "&day=today"; + const xhr = new XMLHttpRequest(); + xhr.open("POST", signData, true); + xhr.onload = function() { + let jsonObject = JSON.parse(this.responseText); + let element = document.getElementById("daily_horoscope"); + let str = jsonObject.description; + element.innerHTML = str; + }; + xhr.send(); +} + + + +function addEventsAfterPageLoaded() { + const elements = document.getElementsByClassName("sign"); + Array.from(elements).forEach((element) => { + let singName = element.name; + element.addEventListener("click", function() { + sendSignDescription(singName); + }, false); + }); +} + +document.addEventListener("DOMContentLoaded", addEventsAfterPageLoaded); \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index 16aaf490..4cc5d825 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,23 +1,23 @@ +
{% block head %} - +