如何在更新时发布新的Json结构

时间:2017-12-04 23:42:55

标签: python json firebase firebase-realtime-database

我有一个从firebase数据库获取更新的应用程序。它在REST方法中的更新运行良好,但是,我无法在更改之前保存最近的值。

我试着循环一切,但这只是一团糟 我有一个想法截图整个事情,然后在更新后将其保存到某个地方,然后将其粘贴到底部。但是,这不是一个好习惯。我是json和python同步的新手,所以我不确定我应该怎么做。你有什么建议吗?

顺便说一句,这是我的代码

@app.route("/room1")
def room1():



#USE THIS LATER
#%b %d, %Y %I:%M:%S %p
result1date = firebase.get('/Rooms/Room1/', None)

for key in result1date.keys():
    key = sorted(result1date.keys())[-2]
    currentdate = key

    print currentdate

result1 = firebase.get('/Rooms/Room1/' + currentdate + '/Inspection/Scan-in/Inspector/', None)
result2 = firebase.get('/Rooms/Room1/' + currentdate + '/Inspection/Scan-out/Inspector/', None)
print result1


print currentdate

for key in result1.keys():
   inspector = key
timeout = result2[inspector]["Time"]

# for key in result1date.keys():
#    Date = key

result1datetime = firebase.get('/Rooms/Room1/'+ currentdate +'/Inspection/Scan-in/Inspector/'+ inspector +'/', None)





for key in result1datetime.keys():
    key = sorted(result1datetime.keys())[-2]
    time = key
    print time



print time

ch1 = result1datetime[time]["Checklist"]["Entrance louver clean and dust-free"]
# ch2 = result1datetime[time]["Checklist"]["Room plate number – clean and well-polished"]
ch3 = result1datetime[time]["Checklist"]["Appearance door surface- in good condition"]
# ch4 = result1datetime[time]["Checklist"]["Let the door close by itself to test the door closure – in working order"]
ch5 = result1datetime[time]["Checklist"]["Eye viewer and fire escape plan in order"]
ch6 = result1datetime[time]["Checklist"]["Privacy Sign or Make Up Room Sign"]
# ch7 = result1datetime[time]["Checklist"]["Key card holder – in working order"]
ch8 = result1datetime[time]["Checklist"]["Switches at the entrance working correctly"]



return render_template('new.html', ch1=ch1,ch3=ch3,ch5=ch5,ch6=ch6,ch8=ch8, inspector=inspector, date=currentdate, time=time, timeout=timeout, timedif = timedif)

这是我的 html

<!doctype html>
<html>
   <body>
      <h1>Room 1</h1>
      <h1>Scan-in: 
      {{date}} </h1>


  <h2>Time: {{time}}</h2>
  <h2>Time-out: {{timeout}}</h2>
  <h2>Inspection time: {{timedif}}</h2>


  <h1>Inspector: {{inspector}} </h1>
   <h1>Checklist: </h1>
   <h4> Entrance louver –clean and dust-free: {{ch1}} </h4>
   <h4> Room plate no. – clean and well-polished: {{ch2}} </h4>
   <h4> Appearance door surface- in good condition: {{ch3}} </h4>
   <h4> Let the door close by itself to test the door closure – in working order: {{ch4}} </h4>
   <h4> Eye viewer and fire escape plan in order: {{ch5}} </h4>
   <h4> Privacy Sign/Make Up Room Sign: {{ch6}} </h4>
   <h4> Key card holder – in working order: {{ch7}} </h4>
   <h4> Switches at the entrance working correctly: {{ch8}} </h4>

  <h2><a href = "\">Go back to home page</a></h2>

&LT;

我尝试循环这些,我得到了一个表格形式。我真的不想要。

我希望每次价值变化时发布,让我们说

第一次更新

...更新发生

第二次更新

第一次更新

而不是以表格形式。或者另一个想法是将所有内容保存在一个数据中,然后将其作为rows=rows传递,然后循环通过它?

0 个答案:

没有答案