blob: 700d1aa8aecc28c9821ae0ebc786b046f814aeee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()
|