Created
April 19, 2021 09:54
-
-
Save obviyus/042a8c9926e333e36cb17fc3d496fb35 to your computer and use it in GitHub Desktop.
A Python script to covert exported Journey JSON files to Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
from datetime import datetime | |
from shutil import copyfile | |
json_files = [json_file for json_file in os.listdir( | |
'.') if json_file.endswith('json')] | |
for each_file in json_files: | |
with open(each_file) as json_file: | |
data = json.load(json_file) | |
location = data["address"] | |
date = int(str(data["date_journal"])[:-3]) | |
readable_date = datetime.utcfromtimestamp(date).strftime('%Y-%m-%d') | |
try: | |
photo = data["photos"][0] | |
copyfile(photo, f"converted/{readable_date}.jpeg") | |
except IndexError: | |
photo = None | |
temperature = data["weather"]["degree_c"] | |
content = data["text"] | |
with open(f"converted/{str(readable_date)}.md", "w") as f: | |
f.write(f"# {str(readable_date)}") | |
f.write(f"\n\n{temperature}° C - {location}") | |
if photo: | |
f.write( | |
f"\n\n}.jpeg)\n\n") | |
f.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment