diff options
Diffstat (limited to 'bin/pinboard_links_to_markdown_files.py')
-rwxr-xr-x | bin/pinboard_links_to_markdown_files.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bin/pinboard_links_to_markdown_files.py b/bin/pinboard_links_to_markdown_files.py new file mode 100755 index 0000000..700d1aa --- /dev/null +++ b/bin/pinboard_links_to_markdown_files.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +import os +import requests + + +def get_pinboard_links(): + with open(os.environ['HOME'] + '/.pinboard-credentials') as credentials: + for line in credentials: + me, token = line.split(':') + url = 'https://api.pinboard.in/v1/posts/all?results=80&format=json&auth_token=' + me + ':' + token + r = requests.get(url, timeout=9.001) + print(url) + data = r.json() + print(date) + for item in data: + print(item['description']) + md = get_markdown(item['href']) + body = md['markdown'] + body.encode("utf-8") + file_name = str(item['description']).replace("/", "") + file_path = "%s/Documents/bookmarks-tmp/%s.txt" % (os.environ['HOME'], file_name.lower()) + date = item['time'] + tags = ", ".join(t for t in str(item['tags']).split(' ')) + preamble = "---\ntitle: %s\ndate: %s\nsource: %s\ntags: %s\n\n---\n\n" % (md['title'], date, item['href'], tags) + import codecs + f = codecs.open(file_path, "w", 'utf8') + f.write(preamble) + f.write(body) + f.close() + + +def get_markdown(source): + url = "http://heckyesmarkdown.com/go/?read=1&preview=0&showframe=0&output=json&u=%s" % (source) + print(url) + r = requests.get(url, timeout=15.001) + data = r.json() + return data + +get_pinboard_links() |