Created
May 27, 2017 19:06
-
-
Save fitnr/be056c2342e115c37e97d73719417bea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.5 | |
import os | |
import sys | |
from urllib.parse import urlsplit | |
from requests import Session | |
from transitfeeds import TransitFeeds | |
listing = sys.argv[1] | |
feed_ids = sys.argv[2:] | |
urls = [] | |
with Session() as s: | |
api = TransitFeeds(os.environ['TRANSITFEEDS_API_KEY'], session=s) | |
latest = [api.latest(i) for i in feed_ids] | |
with open(listing, 'r+') as f: | |
prev_paths = [urlsplit(x).path for x in f.read().strip().split('\n')] | |
f.seek(0) | |
for new in latest: | |
f.write(new + '\n') | |
if urlsplit(new).path not in prev_paths: | |
urls.append(new) | |
with Session() as session: | |
for url in urls: | |
r = session.get(url) | |
filename = urlsplit(url).path.strip('/') | |
os.makedirs(os.path.dirname(filename)) | |
with open(filename, 'wb') as f: | |
for chunk in r.iter_content(chunk_size=256): | |
f.write(chunk) | |
print(filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FEED_IDS="mta/81 mta/80 mta/85 mta/82 mta/83 mta/84" | |
0 4 * * 0 python3.5 checkfeeds.py feeds.txt $FEED_IDS | xargs -n 1 -I {} make load DATABASE=nycbus GTFS={} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://transitfeeds-data.s3-us-west-1.amazonaws.com/public/feeds/mta/81/20170405/gtfs.zip | |
https://transitfeeds-data.s3-us-west-1.amazonaws.com/public/feeds/mta/80/20170404/gtfs.zip | |
https://transitfeeds-data.s3-us-west-1.amazonaws.com/public/feeds/mta/85/20170404/gtfs.zip | |
https://transitfeeds-data.s3-us-west-1.amazonaws.com/public/feeds/mta/82/20170405/gtfs.zip | |
https://transitfeeds-data.s3-us-west-1.amazonaws.com/public/feeds/mta/83/20170405/gtfs.zip | |
https://transitfeeds-data.s3-us-west-1.amazonaws.com/public/feeds/mta/84/20170404/gtfs.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/fitnr/transitfeeds-api/archive/alpha.tar.gz#egg=transitfeeds-0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment