Created
October 11, 2019 22:55
-
-
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
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
''' | |
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