Skip to content

Instantly share code, notes, and snippets.

@obviyus
Created April 19, 2021 09:54
Show Gist options
  • Save obviyus/042a8c9926e333e36cb17fc3d496fb35 to your computer and use it in GitHub Desktop.
Save obviyus/042a8c9926e333e36cb17fc3d496fb35 to your computer and use it in GitHub Desktop.
A Python script to covert exported Journey JSON files to Markdown
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![{str(readable_date)}]({str(readable_date)}.jpeg)\n\n")
f.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment