Advertisement
Poganu

Varianta1-Dictionary-Loop

Apr 9th, 2022
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. for client in Results_Database['client']:
  2.     for car in Results_Database['client'][client]:
  3.         for year in Results_Database['client'][client][car]['year']:
  4.             if str(year) == str(current_year):
  5.                 print("same year, look for month")
  6.                 for month in Results_Database['client'][client][car]['year'][year]['month']:
  7.                     if str(month) == str(current_month):
  8.                         print("same month, look for day")
  9.                         for day in Results_Database['client'][client][car]['year'][year]['month'][month]['day']:
  10.                             if str(day) == str(current_day):
  11.                                 print("same day, look for hour")
  12.                                 for hour in Results_Database['client'][client][car]['year'][year]['month'][month]['day']['hour'][hour]:
  13.                                     print(f"Let's add a new hour for {day} {month} {year}")
  14.  
  15.                                     Results_Database['client'][client][car]['year'][year]['month'][month]['day'].update({"hour": current_hour})
  16.  
  17.                             else: #different day
  18.                                 print("add a new day entry")
  19.                                 print(Results_Database['client'][client][car]['year'][year]['month'][month]['day'])
  20.                                 Results_Database['client'][client][car]['year'][year]['month'][month]['day'].update({str(current_day): {'hour': {str(current_hour): {'Engine_ON': 0, 'Car_at_base': 0, 'Car_speed': 0, 'PING_respose': 0, 'CPU_usage': 0, 'CPU_temp': 0, 'All_Errors': 0, 'Video0_Errors': 0, 'Camera_connected': 0, 'USB_Drive_connected': 0, 'Disk_full': 0, 'Files_list': 0, 'Uploading_gap': 0, 'Latest_video_tdelta': 0, 'Python_processes': 0}}}})
  21.                                 #{str(current_day) : {}})#'hour':{'02':{'Engine_ON':0,'Car_at_base':0,'Car_speed':0,'PING_respose':0,'CPU_usage':0,'CPU_temp':0,'All_Errors':0,'Video0_Errors':0,'Camera_connected':0,'USB_Drive_connected':0,'Disk_full':0,'Files_list':0,'Uploading_gap':0,'Latest_video_tdelta':0,'Python_processes':0}}}})
  22.                    
  23.                     else: # different month
  24.                         print("add a new month entry")
  25.                         #Results_Database['client'][client][car]['year'][year]['month'] = current_month
  26.  
  27.             else: # different year
  28.                 print("add a new year entry")
  29.                 #Results_Database['client'][client][car]['year'] = current_year
  30.            
  31. print("------------------------")
  32. print(Results_Database)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement