Untitled
unknown
python
2 years ago
1.0 kB
4
Indexable
fetch data with s3 stored in /tmp import json import os def fetch_data(self) -> None: s3_file_path = f"{self.environment}/{self.client_name}-{self.culture}/fuzzy/kws.json" local_file_path = f"/tmp/{self.client_name}_{self.culture}_kws.json" if os.path.exists(local_file_path): with open(local_file_path, 'r') as f: self.kws = json.load(f) else: s3=S3(self.client_name,self.culture,self.environment,cfg.AWS_REGION) i=0 while i<3: i+=1 try: self.kws=s3.read(f"{self.environment}/{self.client_name}-{self.culture}/fuzzy/kws.json") with open(local_file_path, 'w') as f: json.dump(self.kws, f) break except Exception as e: print(e) time.sleep(5) if i==3 : raise Exception("couldn't read kws.json file")
Editor is loading...