Skip to content

Commit

Permalink
Updated scripts (encoding fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
darvasd committed Jan 24, 2018
1 parent d00cdf2 commit 75defad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions fill_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def fill_template(template_filename, data_filename):
template = template_file.read()

# Creating the files based on the template and the data descriptor CSV
with open(data_filename,"r") as csv_file:
with open(data_filename,"r", encoding='utf-8-sig') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
output_filename = row["FILENAME"]
Expand All @@ -20,10 +20,10 @@ def fill_template(template_filename, data_filename):
for column in csv_reader.fieldnames:
if column != "FILENAME":
filled_template = filled_template.replace("{%s}" % column, row[column])
print(" {%s} = %s" % (column, row[column]))
print((" {%s} = %s" % (column, row[column])).encode().decode('cp850'))

# Write to output file
with open(output_filename, "w") as output_file:
with open(output_filename, "w", encoding='utf-8') as output_file:
output_file.write(filled_template)


Expand Down
7 changes: 4 additions & 3 deletions upload_to_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def batch_upload(directory):
pdf_file = metadata_file.replace(".json",".pdf")
if os.path.isfile(pdf_file):
print("Uploading %s & %s" % (metadata_file, pdf_file))
with codecs.open(metadata_file, 'r', "utf-8") as f:
with codecs.open(metadata_file, 'r', 'utf-8') as f:
metadata = f.read()
# Re-encoding in order to support UTF-8 inputs
metadata = json.dumps(json.loads(metadata), ensure_ascii=True)
print(metadata)
metadata_json = json.loads(metadata)
metadata = json.dumps(metadata_json, ensure_ascii=True)
#print(metadata)
upload(metadata, pdf_file)
else:
print("The file %s might be a submission metadata file, but %s does not exist." % (metadata_file, pdf_file))
Expand Down

0 comments on commit 75defad

Please sign in to comment.