-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
92 lines (70 loc) · 3.35 KB
/
__init__.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from os.path import dirname
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
import urllib, json
import unicodedata
import feedparser
from bs4 import BeautifulSoup
try:
from mycroft.skills.audioservice import AudioService
except:
from mycroft.util import play_mp3
AudioService = None
__author__ = 'James Purser'
LOGGER = getLogger(__name__)
class AngryBeanieSkill(MycroftSkill):
def __init__(self):
super(AngryBeanieSkill, self).__init__(name="AngryBeanieSkill")
self.audioservice = None
def initialize(self):
get_podcasts_intent = IntentBuilder("GetPodcastsIntent").require("GetPodcastsKeyword").build()
self.register_intent(get_podcasts_intent, self.handle_get_podcasts_intent)
get_episodes_intent = IntentBuilder("GetEpisodesIntent").require("GetEpisodesKeyword").require("ShowName").build()
self.register_intent(get_episodes_intent, self.handle_get_episodes_intent)
get_latest_episode_intent = IntentBuilder("GetLatestEpisodeIntent").require("GetLatestEpisodeKeyword").require("ShowName").build()
self.register_intent(get_latest_episode_intent, self.handle_get_latest_episode_intent)
stop_latest_episode_intent = IntentBuilder("StopAngryBeanieIntent").require("AngryBeanieStopVerb").build()
self.register_intent(stop_latest_episode_intent, self.handle_stop)
if AudioService:
self.audioservice = AudioService(self.emitter)
def handle_get_podcasts_intent(self, message):
self.speak_dialog("podcasts")
def handle_get_episodes_intent(self, message):
show = message.data.get("ShowName")
episodes = getEpisodes(show.encode('utf-8'))
self.speak_dialog("episodes", {'show': show.encode('utf-8'), 'episodes': episodes.encode('utf-8')})
def handle_get_latest_episode_intent(self, message):
show = message.data.get("ShowName")
episode = getLatestEpisode(show)
self.speak("Playing episode")
if self.audioservice:
self.audioservice.play(episode, message.data['utterance'])
else: # othervice use normal mp3 playback
self.process = play_mp3(episode)
def handle_stop(self, message):
self.stop()
def stop(self):
if self.process and self.process.poll() is None:
self.process.terminate()
self.process.wait()
self.speak_dialog('angrybeanie.stop.playing')
def getEpisodes(show):
feeds = {'for science': 'http://feeds.feedburner.com/angrybeanie/ForScienceMP3?format=xml', 'women in stem': 'http://feeds.feedburner.com/WomenInStemm?format=xml'}
feed = feedparser.parse(feeds[show])
titles = ""
for entry in feed.entries:
titles += entry.title+", "
return titles
def getLatestEpisode(show):
feeds = {
'for science': 'http://feeds.feedburner.com/angrybeanie/ForScienceMP3?format=xml',
'women in stem': 'http://feeds.feedburner.com/WomenInStemm?format=xml',
'purser explores the world': 'http://feeds.feedburner.com/PurserExploresTheWorld'
}
feed = feedparser.parse(feeds[show])
entry = feed.entries[0]
media = entry.media_content[0]['url']
return media
def create_skill():
return AngryBeanieSkill()