本文整理汇总了Python中app.models.Event.metadata_json方法的典型用法代码示例。如果您正苦于以下问题:Python Event.metadata_json方法的具体用法?Python Event.metadata_json怎么用?Python Event.metadata_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Event
的用法示例。
在下文中一共展示了Event.metadata_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scheduleCalReminderEvent
# 需要导入模块: from app.models import Event [as 别名]
# 或者: from app.models.Event import metadata_json [as 别名]
def scheduleCalReminderEvent(event, facebook_id):
print "scheduling cal reminder events"
print event
if 'location' not in event or event['location'] is None:
return False
today = datetime.today()
driving_time_in_sec = google_maps.driving_time_from_work(facebook_id, event['location'])['value']
walking_time_in_sec = google_maps.walking_time_from_work(facebook_id, event['location'])['value']
event_start_time = datetime.strptime(event['start_time'], "%I:%M %p")
event_start_time = datetime(today.year, today.month, today.day, event_start_time.hour, event_start_time.minute, 0)
driving_alert_time = event_start_time - timedelta(seconds=driving_time_in_sec)
walking_alert_time = event_start_time - timedelta(seconds=walking_time_in_sec)
driving_event = Event(facebook_id=facebook_id)
driving_event.trigger_enum = 5
driving_event.send_timestamp = driving_alert_time
driving_event.metadata_json = json.dumps(event)
walking_metadata = event.copy()
walking_metadata['drive_id'] = driving_event.id
walking_event = Event(facebook_id=facebook_id)
walking_event.trigger_enum = 4
walking_event.send_timestamp = walking_alert_time
walking_event.metadata_json = json.dumps(walking_metadata)
db.session.add(driving_event)
db.session.add(walking_event)
print "created driving and walking events!"
try:
db.session.commit()
except IntegrityError:
db.session.rollback()
return False
return True