Skip to content

Instantly share code, notes, and snippets.

@JakenHerman
Created May 12, 2014 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakenHerman/41b8396b0bd22cab5df5 to your computer and use it in GitHub Desktop.
Save JakenHerman/41b8396b0bd22cab5df5 to your computer and use it in GitHub Desktop.
Final suitcase-challenge
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.6 (/Library/Frameworks/Python.framework/Versions/2.7/bin/python)" project-jdk-type="Python SDK" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Suitcase-Challenge.iml" filepath="$PROJECT_DIR$/.idea/Suitcase-Challenge.iml" />
</modules>
</component>
</project>
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>
<?xml version="1.0"?>
<buses rt="22">
<time>12:29 AM</time>
<bus>
<id>1771</id>
<rt>22</rt>
<d>North Bound</d>
<dd>Northbound</dd>
<dn>N</dn>
<lat>41.888622714627175</lat>
<lon>-87.62955425631615</lon>
<pid>5421</pid>
<pd>Northbound</pd>
<run>P278</run>
<fs>Howard</fs>
<op>53112</op>
<dip>7662</dip>
<bid>7872719</bid>
<wid1>0P</wid1>
<wid2>278</wid2>
</bus>
<bus>
<id>1881</id>
<rt>22</rt>
<d>North Bound</d>
<dd>Northbound</dd>
<dn>N</dn>
<lat>41.93252155698579</lat>
<lon>-87.6448508953226</lon>
<pid>5421</pid>
<pd>Northbound</pd>
<run>P258</run>
<fs>Howard</fs>
<op>51838</op>
<dip>24901</dip>
<bid>7872280</bid>
<wid1>0P</wid1>
<wid2>258</wid2>
</bus>
<bus>
<id>1901</id>
<rt>22</rt>
<d>South East Bound</d>
<dd>Southbound</dd>
<dn>SSE</dn>
<lat>41.94892586602105</lat>
<lon>-87.65777503119574</lon>
<pid>3936</pid>
<pd>Southbound</pd>
<run>P260</run>
<fs>Harrison</fs>
<op>31400</op>
<dip>27437</dip>
<bid>7872462</bid>
<wid1>0P</wid1>
<wid2>260</wid2>
</bus>
<bus>
<id>4170</id>
<rt>22</rt>
<d>South East Bound</d>
<dd>Southbound</dd>
<dn>SSE</dn>
<lat>41.91450864351713</lat>
<lon>-87.63361206054688</lon>
<pid>3936</pid>
<pd>Southbound</pd>
<run>P279</run>
<fs>Harrison</fs>
<op>54356</op>
<dip>41608</dip>
<bid>7872721</bid>
<wid1>0P</wid1>
<wid2>279</wid2>
</bus>
<bus>
<id>1778</id>
<rt>22</rt>
<d>South Bound</d>
<dd>Southbound</dd>
<dn>S</dn>
<lat>41.87406539916992</lat>
<lon>-87.63102722167969</lon>
<pid>3936</pid>
<pd>Southbound</pd>
<run>P259</run>
<fs>Harrison</fs>
<op>38640</op>
<dip>56536</dip>
<bid>7872306</bid>
<wid1>0P</wid1>
<wid2>259</wid2>
</bus>
<bus>
<id>1859</id>
<rt>22</rt>
<d>North Bound</d>
<dd>Northbound</dd>
<dn>N</dn>
<lat>42.018064821683446</lat>
<lon>-87.6729736328125</lon>
<pid>3932</pid>
<pd>Northbound</pd>
<run>P257</run>
<fs>Howard</fs>
<op>30090</op>
<dip>57405</dip>
<bid>7872279</bid>
<wid1>0P</wid1>
<wid2>257</wid2>
</bus>
<bus>
<id>1405</id>
<rt>22</rt>
<d>North Bound</d>
<dd>Northbound</dd>
<dn>N</dn>
<lat>42.01862335205078</lat>
<lon>-87.67300415039062</lon>
<pid>3932</pid>
<pd>Northbound</pd>
<run>P280</run>
<fs>Howard</fs>
<op>52281</op>
<dip>57535</dip>
<bid>7872723</bid>
<wid1>0P</wid1>
<wid2>280</wid2>
</bus>
</buses>
__author__ = 'Jaken'
import urllib
import webbrowser
from xml.etree.ElementTree import parse
lat = 41.980262
lon = -87.668452
u = urllib.urlopen('http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22')
data = u.read()
f = open('rt22.xml', 'wb')
f.write(data)
f.close()
doc = parse('rt22.xml')
for bus in doc.findall('bus'):
latBus = float(bus.findtext('lat'))
lonBus = float(bus.findtext('lon'))
if latBus > lat:
direction = bus.findtext('d')
if direction.startswith('North'):
busid = bus.findtext('id')
print "Direction >> North"
print busid, latBus
if direction.startswith('South'):
busid = bus.findtext('id')
print "Direction >> South"
print busid, latBus, lonBus
latBusStr = str(latBus)
lonBusStr = str(lonBus)
webbrowser.open_new("http://maps.googleapis.com/maps/api/staticmap?center="+latBusStr+","+lonBusStr
+"&zoom=12&size=400x400&sensor=false")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment