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


Python Event.metadata_json方法代码示例

本文整理汇总了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
开发者ID:cathychen95,项目名称:jarvis-chatbot,代码行数:37,代码来源:manage.py


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