本文整理汇总了Python中lib.db.DB.insert_location方法的典型用法代码示例。如果您正苦于以下问题:Python DB.insert_location方法的具体用法?Python DB.insert_location怎么用?Python DB.insert_location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.db.DB
的用法示例。
在下文中一共展示了DB.insert_location方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Geocoder
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import insert_location [as 别名]
conf_file = 'data/geocoder.conf'
geocoder = Geocoder(logging, conf_file)
db = DB(logging)
while True:
users = db.get_geocoding_target_users(100)
if len(users) == 0:
logging.info("All users in DB are geocoded.")
time.sleep(10*60)
continue
for user in users:
if user['location_property'] == '':
db.update_user_by_geocoded_info(user['id'], -1)
logging.info("Cannot geocoded %s", user['id'])
time.sleep(10)
continue
locations = geocoder.get(user['location_property'])
if len(locations) == 0:
db.update_user_by_geocoded_info(user['id'], -1)
logging.info("Cannot geocoded %s", user['id'])
time.sleep(10)
continue
location = locations.pop(0)
location['id'] = location['id'].split('.')[0]
db.insert_location(location)
db.update_user_by_geocoded_info(user['id'], location['id'])
logging.info("Geocoded %s", user['id'])