Skip to content

Instantly share code, notes, and snippets.

@joer14
Created December 8, 2017 18:28
Show Gist options
  • Save joer14/8520d228fa77b8645ab79995ccdbf775 to your computer and use it in GitHub Desktop.
Save joer14/8520d228fa77b8645ab79995ccdbf775 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python
import requests
import json
import datetime
import time
import emoji
import random
#
key = 'MW9S-E7SL-26DU-VV8V'
url = 'http://api.bart.gov/api/etd.aspx?json=y&cmd=etd&orig=12th&dir=n&key='+key
r = requests.get(url)
content = json.loads(r.content)
content = content['root']['station'][0]['etd']
when_train_is_coming = []
for x in content:
if x['abbreviation'] == 'RICH':
for train in x['estimate']:
when_train_is_coming.append(train['minutes'])
trains = [':train:',':train2:',':bullettrain_side:',':bullettrain_front:',':light_rail:']
# # print trains
train = random.choice(trains)
# print
msg = ', '.join(when_train_is_coming)
# print msg
msg = train+': ' +msg
# print msg
print(emoji.emojize('%s' % msg, use_aliases=True))
# print(emoji.emojize(':train:', use_aliases=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment