Commit bcbcea99 authored by Nolan Darilek's avatar Nolan Darilek
Browse files

Initial commit.

parents
*.db*
*.pyc
gtfs.zip
settings.json
# GTFS Skill
Ask [Mycroft](https://mycroft.ai) about data in [General Transit Feed Specification](http://gtfs.org/) format. Supported queries will include:
* "Tell me about stop 1068.": Provides a brief description of the stop and lists the next departure.
* "Which stop is on the south corner of Woodrow and Anderson?": Performs fuzzy string searches against stop descriptions. May not be accurate in all areas.
* "When is the next 323 westbound from stop 1068?": Searches static and real-time feeds for the next departure of the specified bus.
* "Alert me 10 minutes before the next 323 westbound departs stop 1068.": Trigger an alarm when the specified line is about to depart.
* "Refresh transit data.": Refreshes the locally cached GTFS static data. This also happens on a regular, daily schedule.
from os.path import dirname, exists, join
from adapt.intent import IntentBuilder
# import geopandas
from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft.util.log import getLogger
import pygtfs
import requests
__author__ = 'Nolan Darilek'
# Logger: used for debug lines, like "LOGGER.debug(xyz)". These
# statements will show up in the command line when running Mycroft.
LOGGER = getLogger(__name__)
class GtfsSkill(MycroftSkill):
def __init__(self):
super(GtfsSkill, self).__init__(name="GtfsSkill")
self.schedule = pygtfs.Schedule(join(self.file_system.path, "gtfs.db"))
self.gtfs_path = join(self.file_system.path, "gtfs.zip")
def initialize(self):
super(GtfsSkill, self).initialize()
if not exists(self.gtfs_path) and self.config.get("gtfsURL"):
self.refresh_gtfs(speak_messages = True)
def refresh_gtfs(self, speak_messages=False):
if speak_messages:
self.speak_dialog("refreshing")
self.speak_dialog("wait")
response = requests.get(self.config.get("gtfsURL"), allow_redirects=True)
gtfs = self.file_system.open("gtfs.zip", "w")
gtfs.write(response.content)
if speak_messages:
self.speak_dialog("importing")
self.speak_dialog("wait")
gtfs.close()
pygtfs.overwrite_feed(self.schedule, join(self.file_system.path, gtfs.name))
if speak_messages:
self.speak_dialog("done")
@intent_handler(IntentBuilder("RefreshIntent").require("RefreshKeyword").build())
def handle_refresh_intent(self, message):
self.refresh_gtfs(speak_messages = True)
@intent_handler(IntentBuilder("StopInfoIntent").require("StopInfoKeyword").require("Stop").build())
def handle_stop_info_intent(self, message):
self.speak_dialog("welcome")
def stop(self):
pass
def create_skill():
return GtfsSkill()
Import of transit data complete.
Import of transit feed complete.
Import of transit data finished.
Import of transit feed finished.
Import of transit data done.
Import of transit feed done.
Done importing transit data.
Importing transit data. This may take a while.
Refreshing transit data.
Updating transit data.
Refreshing transit details.
Updating transit details.
Refreshing transit feed.
Updating transit feed.
Please wait.
Please be patient.
Any time.
Glad to be of service.
Glad to help.
My Pleasure.
No problem.
You're welcome.
(on|for|about) (?P<Stop>.*)
{
"identifier": "GtfsSkill",
"name": "GTFS Transit",
"skillMetadata": {
"sections": [
{
"name": "Options",
"fields": [
{
"type": "label",
"label": "URL to the GTFS feed you wish to track"
},
{
"name": "gtfsURL",
"type": "text",
"label": "GTFS feed URL",
"value": ""
}
]
}
]
}
}
details
information
info
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment