当前位置: 首页>>代码示例>>Python>>正文


Python Location.geocode方法代码示例

本文整理汇总了Python中models.Location.geocode方法的典型用法代码示例。如果您正苦于以下问题:Python Location.geocode方法的具体用法?Python Location.geocode怎么用?Python Location.geocode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Location的用法示例。


在下文中一共展示了Location.geocode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: take_suggestions

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import geocode [as 别名]
def take_suggestions():
	if os.path.exists(LATESTFILE_SUG):
		fp = open(LATESTFILE_SUG)
		lastid = fp.read().strip()
		fp.close()
		
		if lastid == '':
			lastid = 0
	else:
		lastid = 0
		
	result = api.GetMentions(since_id = lastid)
	#No mention, no suggestion
	print lastid
	if len(result) == 0:
		print "No mention received"
		return []
	else :
		fp = open(LATESTFILE_SUG, 'w')
		fp.write(str(max([x.id for x in result])))
		fp.close()
		entry = History.query.descending('mongo_id').first()
		for x in result:
			print x.text
		#Somebody already suggested..
		if entry.next_location.name != entry.suggested_location.name :
			print "There already is a suggestion. Fitz is currently headed to "+entry.next_location.name
			return []
		else :
			candidates = {}
			#Walk through all the mentions we got here..
			
			for x in result :
				mention_entry = x.text.split(' ')
				s_user = x.user.screen_name
				#Locations have to be proposed in a form of "Check out ***"
				if mention_entry[1] == 'Check' and mention_entry[2] == 'out':
					s_key = s_user + ":" + ' '.join(mention_entry[3:])
					s_geo = geocoder(' '.join(mention_entry[3:]))
					distance = gcd(entry.next_location.geocode[0], entry.next_location.geocode[1], s_geo[1], s_geo[2])
					candidates[s_key] = distance
			#Got somethin' but no useful words
			if len(candidates) == 0:
				print "Got some words, but no suggestions.."
				return []
			#Got somewhere to go!
			else :
				next_move = min(candidates, key=candidates.get)
				print candidates[candidates.keys()[0]] > candidates[candidates.keys()[1]]
				print next_move		
				l = Location()
				l.name = next_move.split(':')[1]
				l.geocode = geocoder(next_move.split(':')[1])[1:]
				entry.suggested_location = l
				entry.suggested_by = next_move.split(':')[0]
				entry.save()
				user_sug = []
				user_sug.append(next_move.split(':')[0])
				user_sug.append(next_move.split(':')[1])
				return user_sug
开发者ID:soloture,项目名称:wanderer,代码行数:62,代码来源:bot.py

示例2: suggest

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import geocode [as 别名]
def suggest():
	entry = History.query.descending('mongo_id').first()
	suggested_point = app.config['SUGGESTED_POINT']
	geocode = geocoder(suggested_point)
	location = Location()
	location.name = geocode[0]
	location.geocode = (geocode[1],geocode[2])
	entry.suggested_location = location
	entry.save()
	return suggested_point + " suggested!"
开发者ID:soloture,项目名称:wanderer,代码行数:12,代码来源:views.py


注:本文中的models.Location.geocode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。