如何在python中的Google Cloud Firestore中创建条目以作为时间戳

网skink

我有一个基于python 3.7的云功能。自纪元以来,我有一个秒数的值。我可以为文档添加一系列条目,例如字符串,整数等。但是我无法添加时间戳。

这是一个简单的代码片段。

db = firestore.Client(project=project_id)

# the event dictionary already has some values in it.  Add a timestamp.
#

# This is a reference to javascript api.  Oddly enough this page does not have
# python listed.
# https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp
#
# This will add a timestamp as a string value.
event['mqtt_timestamp_rfc3339'] = mqtt_timestamp_rfc3339 # add the timestamp as a string

# this adds a the value as a number of seconds since epoch
event['timestamp_secs'] = mqtt_timestamp  # add the timestamp as timestamp class

# This fails.
# firestore.types.Value.timestamp_value(seconds=mqtt_timestamp.timestamp())  

# This actually updates the collection
doc_ref = db.collection(u'sensor-data').add(event)

到目前为止,与示例代码相比,我唯一看到的就是添加一个时间戳,该时间戳似乎是服务器时间。在这种情况下,我有一个将其信息中继到第二个设备的设备,第二个设备又将其更新为pub / sub。我真的不在乎何时调用云函数。我想知道第一台设备何时生成了事件,而这可能要花几分钟的时间。

网skink

此方法适用于使用python 3.7的云功能。

doit():

    # stuff snipped for brevity

    # unpack timestamp as string from buffer
    mqtt_timestamp_str = mqtt_timestamp_bytes.decode("utf-8")
    # generate timestamp from string
    mqtt_timestamp = datetime.fromisoformat(mqtt_timestamp_str)
    # create as RFC339 string
    mqtt_timestamp_rfc3339 = rfc3339(mqtt_timestamp, utc=True, use_system_timezone=False)

    # stuff snipped. event is a dictionary with stuff to put in firebase

    # add the timestamp as RFC339 String
    event['mqtt_timestamp_rfc3339'] = mqtt_timestamp_rfc3339 
    event['timestamp'] = mqtt_timestamp  

    # update firebase
    doc_ref = db.collection(u'sensor-data').add(event)
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在 Cloud Functions 中按时间戳从 Cloud Firestore 查询

来自分类Dev

Kotlin:将当前日期存储在Firestore中作为时间戳

来自分类Dev

Cloud Firestore如何从时间戳减去小时

来自分类Dev

如何在Python google.cloud.storage上传方法中访问错误原因?

来自分类Dev

如何在Google Cloud Platform中以编程方式(Python)附加静态IP地址

来自分类Dev

Google Cloud Engine - 如何在 Python 3.7 中接收电子邮件和处理?

来自分类Dev

如何在 Cloud Firestore 中仅查询日期(而非时间)?

来自分类Dev

如何在新的Google Cloud Console中访问Blobstore?

来自分类Dev

如何在Windows中卸载Google Cloud SDK

来自分类Dev

如何在Google Cloud Storage中获取项目ID

来自分类Dev

如何在Google Cloud Storage中存储Wordpress媒体

来自分类Dev

如何在Android Studio中访问Google Cloud Save API?

来自分类Dev

如何在Google Cloud SQL中追踪MySQL日志?

来自分类Dev

如何在Google Cloud Scheduler作业中设置内容类型

来自分类Dev

如何在Google Cloud Functions中调试Axios错误?

来自分类Dev

如何在Google Cloud Platform中备份本地SSD

来自分类Dev

如何在Google Cloud Datastore中获取各种信息:java

来自分类Dev

如何在Google Cloud Cloud SQL中授权我的动态IP网络地址?

来自分类Dev

如何在Google Cloud Datalab的另一个笔记本中执行python笔记本

来自分类Dev

如何在Google Cloud计算引擎中升级到Python3.6深度学习VM映像?

来自分类Dev

如何在Google Cloud Datalab的另一个笔记本中执行python笔记本

来自分类Dev

如何在Google Cloud Firestore中删除项目的所有集合?

来自分类Dev

如何在Google Cloud中创建或找到SERVICE_PROJECT_ID?

来自分类Dev

如何在Android的Google Cloud存储中创建存储图像的公共链接

来自分类Dev

如何在生产环境中从Google Compute Engine连接到Google Cloud SQL?

来自分类Dev

如何在Google Cloud Composer中安装PYPI软件包(Facebook-business,Google-cloud-secret-manager)

来自分类Dev

Cloud Firestore 中的 IN 查询

来自分类Dev

Python代码中的Google Cloud Datastore API

来自分类Dev

Python代码中的Google Cloud Datastore API

Related 相关文章

  1. 1

    在 Cloud Functions 中按时间戳从 Cloud Firestore 查询

  2. 2

    Kotlin:将当前日期存储在Firestore中作为时间戳

  3. 3

    Cloud Firestore如何从时间戳减去小时

  4. 4

    如何在Python google.cloud.storage上传方法中访问错误原因?

  5. 5

    如何在Google Cloud Platform中以编程方式(Python)附加静态IP地址

  6. 6

    Google Cloud Engine - 如何在 Python 3.7 中接收电子邮件和处理?

  7. 7

    如何在 Cloud Firestore 中仅查询日期(而非时间)?

  8. 8

    如何在新的Google Cloud Console中访问Blobstore?

  9. 9

    如何在Windows中卸载Google Cloud SDK

  10. 10

    如何在Google Cloud Storage中获取项目ID

  11. 11

    如何在Google Cloud Storage中存储Wordpress媒体

  12. 12

    如何在Android Studio中访问Google Cloud Save API?

  13. 13

    如何在Google Cloud SQL中追踪MySQL日志?

  14. 14

    如何在Google Cloud Scheduler作业中设置内容类型

  15. 15

    如何在Google Cloud Functions中调试Axios错误?

  16. 16

    如何在Google Cloud Platform中备份本地SSD

  17. 17

    如何在Google Cloud Datastore中获取各种信息:java

  18. 18

    如何在Google Cloud Cloud SQL中授权我的动态IP网络地址?

  19. 19

    如何在Google Cloud Datalab的另一个笔记本中执行python笔记本

  20. 20

    如何在Google Cloud计算引擎中升级到Python3.6深度学习VM映像?

  21. 21

    如何在Google Cloud Datalab的另一个笔记本中执行python笔记本

  22. 22

    如何在Google Cloud Firestore中删除项目的所有集合?

  23. 23

    如何在Google Cloud中创建或找到SERVICE_PROJECT_ID?

  24. 24

    如何在Android的Google Cloud存储中创建存储图像的公共链接

  25. 25

    如何在生产环境中从Google Compute Engine连接到Google Cloud SQL?

  26. 26

    如何在Google Cloud Composer中安装PYPI软件包(Facebook-business,Google-cloud-secret-manager)

  27. 27

    Cloud Firestore 中的 IN 查询

  28. 28

    Python代码中的Google Cloud Datastore API

  29. 29

    Python代码中的Google Cloud Datastore API

热门标签

归档