简体   繁体   English

Python-在Firebase中发布

[英]Python - post in firebase

I want to make a python script that serves as a backend for my firebase application. 我想制作一个Python脚本作为Firebase应用程序的后端。

I would like to post, at a specific time, an object in firebase. 我想在特定时间发布Firebase中的对象。 but it is published 3,4 or 5 times.. while I only want a single record of jobStoreAllum () for example. 但是它被发布了3,4或5次。.例如,我只希望记录单个jobStoreAllum()。

Thank you for your help 谢谢您的帮助

 from time import sleep
 import time
 import datetime
 from firebase import firebase
 import urllib2, urllib, httplib
 import json
 import os 
 from functools import partial
 firebase = firebase.FirebaseApplication('https://plante-.firebaseio.com/', None)
 import schedule


 def jobAllum():
     x=1
     y=True
     firebase.put("/Interuptors/Elec01", "/value", x)
     firebase.put("/Interuptors/Elec01", "/state", y)

 def jobStoreAllum():
     dateString = '%d/%m/%Y %H:%M:%S'
     y=True
     data = {"State": y,"Horodate":datetime.datetime.now().strftime(dateString) }
     firebase.post('/Storage/Journee', data)


 while True:
     Hallum= firebase.get("/Autom/Prog1/Hallum", None)
     schedule.every().day.at(Hallum).do(jobAllum)
     schedule.every().day.at(Hallum).do(jobStoreAllum)
     schedule.run_pending()
     time.sleep(10)

You can use Cloud Scheduler. 您可以使用Cloud Scheduler。 Make sure you terminate your function returning a value. 确保终止返回值的函数。 And watchout for function timeout, default is 1 minute and maximum is 9 minutes. 并注意函数超时,默认为1分钟,最大为9分钟。 You will have to enable Billing for the project and you have 3 jobs free per month, over 3 are charged $0.10/job, not execution. 您将必须为该项目启用计费,并且您每月有3个免费工作,超过3个的费用为每作业$ 0.10,而不是执行费用。

See This 这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM