mirror of
https://github.com/Death916/deathsite.git
synced 2026-04-11 04:56:37 -07:00
update yt video on main page with newest
This commit is contained in:
parent
81f81da166
commit
e5609912d3
3 changed files with 20 additions and 12 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -14,4 +14,4 @@ assets*
|
|||
/assets*
|
||||
# Virtual environments
|
||||
.venv
|
||||
*.json
|
||||
*.json
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
"""personal site for projects/streams"""
|
||||
import reflex as rx
|
||||
import datetime
|
||||
import videos
|
||||
import asyncio
|
||||
|
||||
|
||||
|
|
@ -52,12 +51,15 @@ NAV_BUTTON_STYLE = {
|
|||
},
|
||||
}
|
||||
|
||||
from deathsite.videos import Youtube
|
||||
|
||||
class State(rx.State):
|
||||
current_page: str = "Home"
|
||||
page_title: str = "Death916's Site" # Added page_title attribute
|
||||
current_time: str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
projects: list[dict[str, str]] = PROJECTS_DATA
|
||||
current_yt_video: str = ""
|
||||
last_yt_fetch: str = "" # ISO date string
|
||||
|
||||
def update_time(self):
|
||||
self.current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
|
@ -72,6 +74,14 @@ class State(rx.State):
|
|||
yt.get_newest_video()
|
||||
self.current_yt_video = yt.current_yt_video
|
||||
await asyncio.sleep(86400) # Update every 60 seconds
|
||||
|
||||
async def update_yt_video(self):
|
||||
today = datetime.date.today().isoformat()
|
||||
if self.last_yt_fetch != today or not self.current_yt_video:
|
||||
yt = Youtube()
|
||||
url = yt.get_current_yt_video()
|
||||
self.current_yt_video = url
|
||||
self.last_yt_fetch = today
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import reflex as rx
|
||||
from deathsite.deathsite import page_content, YOUTUBE_EMBED_URL, TWITCH_EMBED_URL, GITHUB_URL
|
||||
from deathsite.deathsite import page_content, TWITCH_EMBED_URL, GITHUB_URL, State
|
||||
|
||||
@rx.page(route="/")
|
||||
@rx.page(route="/", on_load=State.update_yt_video)
|
||||
@rx.page(route="/home")
|
||||
def home():
|
||||
return page_content(
|
||||
return page_content(
|
||||
rx.box(
|
||||
rx.vstack(
|
||||
rx.container(
|
||||
|
|
@ -36,22 +36,23 @@ def home():
|
|||
rx.hstack(
|
||||
rx.vstack(
|
||||
rx.heading("Whats New:", size="8", color="#ffffff"),
|
||||
|
||||
rx.html(
|
||||
# Use Var.contains() and Var.split() for reactive string manipulation
|
||||
f"""
|
||||
<iframe width="350" height="200" src="{YOUTUBE_EMBED_URL}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
<iframe width="350" height="200" src={rx.cond(State.current_yt_video.contains('v='), f"https://www.youtube.com/embed/{State.current_yt_video.split('v=')[1]}", "about:blank")} title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
"""
|
||||
),
|
||||
rx.text("Stream: ", color="#ffffff"),
|
||||
rx.html(
|
||||
f"""
|
||||
<iframe width="350" height="200" src="{TWITCH_EMBED_URL}" title="Twitch video player" frameborder="0" autoplay="false" allowfullscreen></iframe>
|
||||
|
||||
"""
|
||||
),
|
||||
|
||||
align_items="start",
|
||||
spacing="2",
|
||||
justify="start",
|
||||
|
||||
),
|
||||
rx.vstack(
|
||||
rx.heading(
|
||||
|
|
@ -91,10 +92,7 @@ def home():
|
|||
width="100%",
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
align_items="start",
|
||||
width="100%",
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue