Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Indexer:
- def __init__(self, index_dir, reports_year, downloading_date):
- self.index_dir = index_dir
- self.index_json = None
- self.reports_year = reports_year
- self.downloading_date = downloading_date
- def parse_index(self):
- index = open(self.index_dir, "r")
- index_str = index.read()
- self.index_json = json.loads(index_str)
- def is_in_index(self, company_id):
- if company_id not in self.index_json.keys():
- self.index_json[company_id] = [{self.reports_year: {
- self.downloading_date: ""
- }}]
- return False
- for year_dict in self.index_json[company_id]:
- if self.reports_year in year_dict.keys():
- for key in year_dict[self.reports_year].keys():
- if key == self.downloading_date:
- print('Report for {} - {} already tried to be downloaded!'.format(company_id, self.downloading_date))
- return True
- for download_period in year_dict[self.reports_year]:
- if year_dict[self.reports_year][download_period] == 'y':
- print('Report already downloaded! - {}!'.format(company_id))
- return True
- else:
- self.index_json[company_id].append({self.reports_year: {
- self.downloading_date: ""
- }})
- return False
- def add_to_index(self, company_id, is_downloaded):
- self.index_json[company_id][len(self.index_json[company_id]) - 1][self.reports_year][self.downloading_date] = is_downloaded
- # {
- # "1914": [{
- # "2018": {
- # "102019": "n"
- # }
- # }]
- # }
- #
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement