Skip to content

Instantly share code, notes, and snippets.

@pral2a
Last active March 6, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pral2a/812402def0cd495a0b95d886e60146db to your computer and use it in GitHub Desktop.
Save pral2a/812402def0cd495a0b95d886e60146db to your computer and use it in GitHub Desktop.
Download all your HackMDs

How to

Log in to HackMD and download your history file by clicking on the save icon.

Then run python dhmd.py yourHistory.json.

import os, sys, wget, json
if len(sys.argv) > 1:
fn = sys.argv[1]
else:
print('Download your HackMD history file run $ python dhmd.py yourHistory.json')
sys.exit()
with open(fn, 'r') as json_data:
history = json.load(json_data)
directory = os.path.join(os.path.dirname(fn), 'notes')
if not os.path.exists(directory):
os.makedirs(directory)
for note in history:
url = '{}/{}/{}'.format('https://hackmd.io', note['id'], 'download')
print('\n\n{}\t{}\n'.format(note['text'], url))
try:
wget.download(url, directory)
except ValueError:
print('Error while downloading: {}'.format(url))
print('Done!')
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment