Skip to content

Instantly share code, notes, and snippets.

@ShannonScott
Created October 11, 2019 22:55
Show Gist options
  • Save ShannonScott/35db3e32da57635659b2c77b137e6709 to your computer and use it in GitHub Desktop.
Save ShannonScott/35db3e32da57635659b2c77b137e6709 to your computer and use it in GitHub Desktop.
[Pinboard Export as Text] Print Pinboard's JSON bookmark export as text. #tags: python, utility
'''
Print Pinboard's JSON export as text
'''
import sys
import json
import gzip
if len(sys.argv) < 2:
# Read from stdin pipe
data = json.load(sys.stdin)
else:
# Try reading a gzip file
try:
with gzip.open(sys.argv[1], 'r') as fp:
data = json.load(fp)
except OSError:
# Try reading from a non-gzip file
with open(sys.argv[1], 'r') as fp:
data = json.load(fp)
if data is None:
print('Failed to read JSON file')
sys.exit(1)
for entry in data:
print(entry[u'description'])
print(entry[u'href'])
print(entry[u'tags'])
print(entry[u'time'])
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment