本文整理汇总了Python中Preprocess.decodeAddressToCoordinates方法的典型用法代码示例。如果您正苦于以下问题:Python Preprocess.decodeAddressToCoordinates方法的具体用法?Python Preprocess.decodeAddressToCoordinates怎么用?Python Preprocess.decodeAddressToCoordinates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Preprocess
的用法示例。
在下文中一共展示了Preprocess.decodeAddressToCoordinates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: retieveEventsAtDate
# 需要导入模块: import Preprocess [as 别名]
# 或者: from Preprocess import decodeAddressToCoordinates [as 别名]
def retieveEventsAtDate(date, url):
# root website
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html, "html.parser")
briefs = soup.select("div.item.event_item.vevent")
# retieve all the events detail pages url.
print 'collecting', len(briefs), 'events from', url
toVisit = []
for brief in briefs:
toVisit.append(brief.find('a').get('href'))
result = []
# get information from each events detail pages.
for item in toVisit:
tmp = {}
url = item
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html, "html.parser")
# the event information is reside here.
event = soup.select("div.box_header.vevent")[0]
# extract title from h1 tag's text
title = event.h1.span.get_text().strip()
# extract time from h2 tag's abbr field
time = ""
for abbr in event.h2.findAll('abbr'):
time += abbr.get_text().strip() + " "
print time
time = timePreprocess(date, time)
print time
if time is None:
print("can't resolve time, discard this event")
continue
display_location = event.h3.a
real_location = event.h3.small
if display_location is not None and real_location is not None and len(display_location) > 0 and len(real_location) > 0:
display_location = display_location.get_text().strip()
real_location = real_location.get_text().strip()
else:
# discard bad formated events
print("can't resolve location, discard this event")
continue
if "Cornell University" in real_location:
real_location = real_location.replace("Cornell University", "")
print "real_location becomes: " + real_location
if "Ithaca, NY 14853, USA" not in real_location:
real_location = display_location + ", Ithaca, NY 14853, USA"
latlng = Preprocess.decodeAddressToCoordinates(real_location)
print "latlng: %s" % latlng
lat = latlng['lat']
lng = latlng['lng']
# street = event.h3.small
# if street is not None:
# street = street.get_text().strip()
# else:
# street = "Cornell University"
description = event.select("div.description")
if len(description) > 0:
description = description[0].get_text()
else:
# discard bad formated events
print("can't resolve description, discard this event")
continue
image = soup.select("div.box_image")
if len(image) > 0:
image = image[0].a.img['src']
else:
# discard bad formated events
print("can't resolve image, discard this event")
continue
tmp['title'] = title
tmp['time'] = time
tmp['location'] = display_location
tmp['description'] = description
tmp['image'] = image
tmp['lat'] = lat
tmp['lng'] = lng
tmp['secondaryTag'] = ['Cornell Sponsored']
for free_food_keyword in free_food_keywords:
if free_food_keyword in tmp['description'].lower():
tmp['secondaryTag'].append('Free Food')
break
print 'retrieved:', tmp['title']
result.append(tmp)
# return all events dicitionary in an array.
return result