Skip to content

Commit

Permalink
create empty files yaml files if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Nov 2, 2023
1 parent f70d011 commit 83fc320
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions freshnessUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ def get_server_data(endpoint_path, data=None, method='GET', auth=None, max_lengt
data = None
base = None
id = YamlStruct.get_id()
# Look for a corresponding .data.yaml file
if os.path.exists(fileData):

if not os.path.exists(fileData):
base = YamlStruct.get_base()
data = YamlStruct.get_data()
base["article"] = article
base["data"].append(data)
else:
with open(fileData, 'r') as data_yaml_file:
tmp_base = yaml.safe_load(data_yaml_file)
if tmp_base is not None and tmp_base["article"] == article and len(tmp_base["data"]) > 0:
Expand Down Expand Up @@ -208,12 +213,12 @@ def get_server_data(endpoint_path, data=None, method='GET', auth=None, max_lengt
elif updated:
fileData = last_yaml_info["fileData"]
base = last_yaml_info["base"]
print_data(last_yaml_info["id"])

base["last-update"] = int(time.time())
base["data"][0]["ids"].insert(0, last_yaml_info["id"])

with open(fileData, "w") as yaml_file:
yaml.safe_dump(base, yaml_file, default_flow_style=False, sort_keys=False, allow_unicode=True)
print(f'Updated data for article {article} to {fileData}:')
print_data(last_yaml_info["id"])

0 comments on commit 83fc320

Please sign in to comment.