Skip to content

Instantly share code, notes, and snippets.

@hannahherbig
Created April 24, 2022 01:17
Show Gist options
  • Save hannahherbig/246a5ef1304e1865d5e718be926bf2c2 to your computer and use it in GitHub Desktop.
Save hannahherbig/246a5ef1304e1865d5e718be926bf2c2 to your computer and use it in GitHub Desktop.
fetch the times for coachella streams and make a message formatted for discord
import asyncio
import aiohttp
import lxml.html
import lxml.etree
import re
import arrow
async def main():
async with aiohttp.ClientSession() as session:
async with session.get("https://www.coachella.com") as response:
html = lxml.html.fromstring(await response.text())
every = []
for channel_div in html.cssselect("div.channel"):
(h4,) = channel_div.cssselect("header > h4")
channel_text = h4.text
m = re.match(r"^Channel (\d+)$", channel_text)
channel = int(m.group(1))
(inner,) = channel_div.cssselect("div.channel-inner")
for el in inner.cssselect("h5, ol"):
if el.tag == "h5":
date_text = el.text
now = arrow.get(date_text, "dddd, MMMM Do", tzinfo="US/Pacific")
now = now.replace(year=2022, hour=12 + 5)
elif el.tag == "ol":
for li in el.xpath('.//li[*[@class="artist"]]'):
(time_span,) = li.cssselect(".time")
time_text = time_span.text
time_ar = arrow.get(time_text, 'h:mm A')
next_time = now.replace(hour=time_ar.hour, minute=time_ar.minute)
if next_time < now:
next_time = next_time.shift(days=+1)
(artist_span,) = li.cssselect(".artist")
artist_text = artist_span.text
every.append((now, channel, artist_text))
every.sort()
for now, channel, name in every:
print(
f"<t:{now.int_timestamp}:t> #{channel} **{name}** <t:{now.int_timestamp}:R>"
)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment