Advertisement
Guest User

indexer

a guest
Feb 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. class Indexer:
  2.     def __init__(self, index_dir, reports_year, downloading_date):
  3.         self.index_dir = index_dir
  4.         self.index_json = None
  5.         self.reports_year = reports_year
  6.         self.downloading_date = downloading_date
  7.  
  8.     def parse_index(self):
  9.         index = open(self.index_dir, "r")
  10.         index_str = index.read()
  11.         self.index_json = json.loads(index_str)
  12.  
  13.     def is_in_index(self, company_id):
  14.         if company_id not in self.index_json.keys():
  15.             self.index_json[company_id] = [{self.reports_year: {
  16.                 self.downloading_date: ""
  17.             }}]
  18.             return False
  19.         for year_dict in self.index_json[company_id]:
  20.             if self.reports_year in year_dict.keys():
  21.                 for key in year_dict[self.reports_year].keys():
  22.                     if key == self.downloading_date:
  23.                         print('Report for {} - {} already tried to be downloaded!'.format(company_id, self.downloading_date))
  24.                         return True
  25.                 for download_period in year_dict[self.reports_year]:
  26.                     if year_dict[self.reports_year][download_period] == 'y':
  27.                         print('Report already downloaded! - {}!'.format(company_id))
  28.                         return True
  29.             else:
  30.                 self.index_json[company_id].append({self.reports_year: {
  31.                     self.downloading_date: ""
  32.                 }})
  33.                 return False
  34.  
  35.     def add_to_index(self, company_id, is_downloaded):
  36.         self.index_json[company_id][len(self.index_json[company_id]) - 1][self.reports_year][self.downloading_date] = is_downloaded
  37.  
  38.  
  39.  
  40.  
  41. # {
  42. #     "1914": [{
  43. #         "2018": {
  44. #             "102019": "n"
  45. #         }
  46. #     }]
  47. # }
  48. #
  49. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement