本文整理汇总了Python中models.History.status方法的典型用法代码示例。如果您正苦于以下问题:Python History.status方法的具体用法?Python History.status怎么用?Python History.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.History
的用法示例。
在下文中一共展示了History.status方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import status [as 别名]
def move():
p_entry = History.query.descending('mongo_id').first()
n_entry = History()
n_entry = p_entry
print p_entry.next_location.geocode[0]
print p_entry.next_location.geocode[1]
print p_entry.suggested_location.geocode[0]
print p_entry.suggested_location.geocode[1],
print p_entry.suggested_location.geocode[0] == p_entry.next_location.geocode[0]
#if the bot is not moving
if p_entry.status is False:
print "Fitz Owen is not moving, and.."
#if the bot has got a new suggestion, then move move move yo
if p_entry.next_location.geocode != p_entry.suggested_location.geocode:
print "there is a suggested destination :" + p_entry.suggested_location.name
n_entry.status = True
n_entry.previous_location = p_entry.next_location
n_entry.next_location = p_entry.suggested_location
distance = gcd(n_entry.previous_location.geocode[0], n_entry.previous_location.geocode[1], n_entry.next_location.geocode[0], n_entry.next_location.geocode[1])
n_entry.distance = distance
n_entry.number_of_segments = int(distance / p_entry.speed)
if (distance / p_entry.speed) < 1:
n_entry.number_of_segments = 1
print "Now moving towards" + n_entry.next_location.name +"..."
else :
print "okay, not moving"
#if the bot is approaching the destination..
elif p_entry.status is True:
if p_entry.segment is p_entry.number_of_segments:
print "got there!"
#then stop, and calibrate the location, reset
n_entry.status = False
n_entry.current_location = p_entry.next_location
n_entry.segment = 1
#Okay, now let's move..
else:
print "moving.."
lon = (p_entry.next_location.geocode[0] - p_entry.previous_location.geocode[0]) / p_entry.number_of_segments
lat = (p_entry.next_location.geocode[1] - p_entry.previous_location.geocode[1]) / p_entry.number_of_segments
xy = (p_entry.current_location.geocode[0]+lon,p_entry.current_location.geocode[1]+lat)
n_entry.current_location.geocode = xy
n_entry.segment = p_entry.segment + 1
print n_entry.segment
print n_entry.number_of_segments
n_entry.current_time = str(datetime.datetime.now())
n_entry.save()
示例2: crawl_user
# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import status [as 别名]
def crawl_user(account):
client = weibo.APIClient(app_key=settings.WEIBO_APPKEY, app_secret=settings.WEIBO_APPSECRET)
client.set_access_token(account.access_token, 0)
if settings.DEBUG:
COUNT = 21
else:
COUNT = settings.WEIBO_API_MAX_COUNT
id_func = lambda s:s.id
##TODO: handle exception
if not account.latest_status:
all_statuses = client.statuses.home_timeline.get(count = COUNT).statuses
else:
statuses = client.statuses.home_timeline.get(since_id = account.latest_status.id, count = COUNT).statuses
all_statuses = statuses
while len(statuses) == COUNT:
last_minid = min(map(id_func, statuses))
## The API will return the largest COUNT statuses whose id is larger than since_id
## so here is how we iterate to retrieve the entire set
statuses = client.statuses.home_timeline.get(max_id = last_minid - 1, since_id = account.latest_status.id, count = COUNT).statuses
all_statuses.extend(statuses)
all_statuses.sort(key=id_func)
ids = map(id_func, all_statuses)
assert len(ids) == len(set(ids)) ## Sanity check: no duplicates in the list
saved_statuses = map(store_status, all_statuses)
for status in saved_statuses:
## If we encounter duplicated status, do not create history m2m again
if not status.weiboaccount_set.exists():
h = History()
h.user = account
h.status = status
h.save()
## Move on if the status is 15 minutes old
## This is to deal with API sometimes having missing statuses in between (not even eventually consistent?!)
if saved_statuses:
for i in reversed(range(len(saved_statuses))):
if older_than(all_statuses[i].created_at, 15):
account.latest_status = saved_statuses[i]
break
account.save()
return map(lambda s:s.id, saved_statuses)