summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2018-04-13 16:38:37 +0000
committerNathan Kinkade <nath@nkinka.de>2018-04-13 16:38:37 +0000
commit383c2f6c536fd0caed05ed79a7f7cfd996ba8af0 (patch)
treeee3fe2630922ce713296e5773a81123003e14fb0
parentb7124c02665c8fbdad28d1e091782df43c6077de (diff)
Use 4-space indention instead of tabs.
-rwxr-xr-xscrape_trucks.py116
1 files changed, 58 insertions, 58 deletions
diff --git a/scrape_trucks.py b/scrape_trucks.py
index 6c42794..99131a7 100755
--- a/scrape_trucks.py
+++ b/scrape_trucks.py
@@ -18,73 +18,73 @@ timestamp = datetime.now().strftime('%A, %B %d, %Y %H:%M:%S')
# Aliases a list of locations to a short name
limits = {
- 'oti':
- [
- 'DC - Metro Center',
- 'DC - Franklin Square',
- 'DC - Farragut Square'
- ],
+ 'oti':
+ [
+ u'DC - Metro Center',
+ u'DC - Franklin Square',
+ u'DC - Farragut Square'
+ ],
}
response = {
- 'error': '',
- 'date': timestamp,
- 'locations' : {},
+ 'error': '',
+ 'date': timestamp,
+ 'locations' : {},
}
def main(limit):
- try:
- res = urllib2.urlopen(url)
- page = res.read()
- soup = BeautifulSoup(page)
- except Exception, e:
- response['error'] = e.message
- return
+ try:
+ res = urllib2.urlopen(url)
+ page = res.read()
+ soup = BeautifulSoup(page)
+ except Exception, e:
+ response['error'] = e.message
+ return
- locations = {}
- for h2 in soup.findAll('h2')[1:]:
- next_sib = h2
- trucks = []
- while True:
- truck = {}
- next_sib = next_sib.nextSibling
- if not next_sib:
- break
- try:
- if next_sib.name == 'div':
- if next_sib['style'] == u'position:relative;':
- truck['name'] = next_sib.find('span').text
- truck['url'] = next_sib.find('a')['href']
- trucks.append(truck)
- if next_sib.name == 'h2':
- locations[h2.text] = trucks
- break
- except Exception, e:
- pass
+ locations = {}
+ for h2 in soup.findAll('h2')[1:]:
+ next_sib = h2
+ trucks = []
+ while True:
+ truck = {}
+ next_sib = next_sib.nextSibling
+ if not next_sib:
+ break
+ try:
+ if next_sib.name == 'div':
+ if next_sib['style'] == u'position:relative;':
+ truck['name'] = next_sib.find('span').text
+ truck['url'] = next_sib.find('a')['href']
+ trucks.append(truck)
+ if next_sib.name == 'h2':
+ locations[h2.text] = trucks
+ break
+ except Exception, e:
+ pass
- try:
- if limit:
- limited = limits[limit]
- try:
- for location in limited:
- response['locations'][location] = locations[location]
- except KeyError:
- pass
- else:
- response['locations'] = locations
- except:
- response['locations'] = locations
+ try:
+ if limit:
+ limited = limits[limit]
+ try:
+ for location in limited:
+ response['locations'][location] = locations[location]
+ except KeyError:
+ pass
+ else:
+ response['locations'] = locations
+ except:
+ response['locations'] = locations
if __name__ == '__main__':
- query_params = cgi.FieldStorage()
+ query_params = cgi.FieldStorage()
- limit = ''
- try:
- if 'limit' in query_params:
- limit = query_params['limit'].value
- except:
- pass
+ limit = ''
+ try:
+ if 'limit' in query_params:
+ limit = query_params['limit'].value
+ except:
+ pass
- main(limit)
- print 'Content-type: application/json; charset=UTF-8\n'
- print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
+ main(limit)
+ print 'Content-type: application/json; charset=UTF-8\n'
+ print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))