Ad

Python - Post In Firebase

I want to make a python script that serves as a backend for my firebase application.

I would like to post, at a specific time, an object in firebase. but it is published 3,4 or 5 times.. while I only want a single record of jobStoreAllum () for example.

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)
Ad

Answer

You can use 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. 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.

See This

Ad
source: stackoverflow.com
Ad