-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm.py
39 lines (31 loc) · 1 KB
/
alarm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
import os
from urllib.request import urlretrieve
import feedparser
import pygame
from podcasts import podcasts
# Use quotes around argument
podcast = sys.argv[1]
feed = feedparser.parse(f'https://www.npr.org/rss/podcast.php?id={podcasts[podcast]}')
items = feed['entries']
podcast_ep = items[0].title
podcast_url = items[0].links[0].href
def play(podcast, podcast_ep):
"""Plays mp3 files"""
pygame.init()
pygame.mixer.music.load(os.path.join('archive', f'{podcast}',
f'{podcast_ep}.mp3'))
pygame.mixer.music.play(0)
clock = pygame.time.Clock()
clock.tick(10)
while pygame.mixer.music.get_busy():
pygame.event.poll()
clock.tick(10)
# download file and save to archive
def main():
os.makedirs(os.path.join('archive', f'{podcast}'), exist_ok=True)
urlretrieve(podcast_url,
os.path.join('archive',f'{podcast}',f'{podcast_ep}.mp3'))
play(podcast, podcast_ep)
if __name__ == '__main__':
main()