Advertisement
Guest User

Untitled

a guest
Feb 9th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. @app.route('/')
  2. def index():
  3. day_of_week = date.today().strftime('%A')
  4. json_file = str(os.getcwd()) + "\\static\\data.json"
  5. with open(json_file, 'r+') as file:
  6. json_data = json.load(file)
  7.  
  8. return render_template('test_table.html', name="Hot Rack", json_data=json_data, return_day_value = day_values, save_data = save_data , day_of_week = day_of_week, build_table_rows = build_table_rows)
  9.  
  10. def day_values(day, json_data):
  11. return json_data[day]
  12.  
  13. def save_data(json_data):
  14. json_file_path = str(os.getcwd())+'\\static\\data.json'
  15. with open(json_file_path, 'w') as file:
  16. json.dumps(json_data)
  17. def build_table_rows(day, json_data, mode):
  18. header = """<tr class="row100 body">"""
  19. rows = []
  20. for item in json_data[day]['Items']:
  21. foodItem = ""
  22. row = ""
  23. foodItem += """<td class="cell100 column1">{0}</td>""".format(item)
  24. if mode == "AM":
  25. hours = ['TWELVEAM', 'ONEAM','TWOAM', 'THREEAM', 'FOURAM', 'FIVEAM', 'SIXAM','SEVENAM','EIGHTAM','NINEAM','TENAM','ELEVENAM']
  26. for hour in hours:
  27. foodItem += """<td class="cell100 column2">{0}</td>""".format(json_data[day]['Items'][item][hour])
  28.  
  29. elif mode == "PM":
  30. hours = ['TWELVEPM', 'ONEPM','TWOPM', 'THREEPM', 'FOURPM', 'FIVEPM', 'SIXPM','SEVENPM','EIGHTPM','NINEPM','TENPM','ELEVENPM']
  31. for hour in hours:
  32. foodItem += """<td class="cell100 column2">{0}</td>""".format(json_data[day]['Items'][item][hour])
  33. foodItem += '</tr>'
  34. row = header + foodItem
  35. rows.append(row)
  36. tables = ""
  37. for row in rows:
  38. tables += row
  39. return tables
  40.  
  41.  
  42.  
  43.  
  44. -------------------------
  45. html :
  46.  
  47. <html>
  48. <head>
  49. <title> test page</title>
  50. </head>
  51. <body>
  52. <div class="table100-body js-pscroll">
  53. <table>
  54. <tbody>
  55. {{build_table_rows(day_of_week, json_data, 'AM')}}
  56. </tbody>
  57. </table>
  58. </div>
  59. </body>
  60. </html>
  61. ---------------
  62.  
  63. OUPUT:
  64.  
  65. <tr class="row100 body"><td class="cell100 column1">Hamburger</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td></tr><tr class="row100 body"><td class="cell100 column1">Egg Rolls</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td></tr><tr class="row100 body"><td class="cell100 column1">Pork Steaks</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td></tr>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement