Advertisement
Guest User

Untitled

a guest
Oct 11th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. # ----- удалить завершенные файлы по времени -----
  2.     timedict = {}
  3.     datadict = {}
  4.  
  5.     error1 = error2 = False
  6.  
  7.     try:
  8.       with open(path_for_queue+json_time_data) as ftd:
  9.         timedict = json.load(ftd)
  10.     except:
  11.       error1 = True
  12.  
  13.     try:
  14.       with open(path_for_queue+json_data) as fd:
  15.         datadict = json.load(fd)
  16.     except:
  17.       error2 = False
  18.  
  19.     no_errors = (error1 == False and error2 == False)
  20.     have_data = (len(timedict)>0 and len(datadict)>0)
  21.  
  22.     # удалить запись из основного словаря по временному словарю, где обработанные файлы
  23.     if have_data and no_errors:
  24.       with double_semaphore:
  25.         for dc in timedict:
  26.           for dc2 in datadict:
  27.             if re.findall(dc, datadict[dc2]) and len(dc) > 0 and len(datadict[dc2]) > 0:
  28.               del datadict[dc2]
  29.  
  30.         # перезапись словаря, если есть данные
  31.         if len(datadict) > 0:
  32.           with open(path_for_queue+json_data, "w") as fd:
  33.             json.dump(datadict, fd, ensure_ascii=False, sort_keys=True, indent=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement