summaryrefslogtreecommitdiff
path: root/app/links/retriever.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/links/retriever.py')
-rw-r--r--app/links/retriever.py50
1 files changed, 30 insertions, 20 deletions
diff --git a/app/links/retriever.py b/app/links/retriever.py
index 9e7aae5..f807820 100644
--- a/app/links/retriever.py
+++ b/app/links/retriever.py
@@ -7,33 +7,42 @@ from django.conf import settings
from links.models import Link
# https://github.com/mgan59/python-pinboard/
-import pinboard
+#import pinboard
+import requests
+import json
-def safestr(s):
- """
- Safely corerce *anything* to a string. If the object can't be str'd, an
- empty string will be returned.
-
- You can (and I do) use this for really crappy unicode handling, but it's
- a bit like killing a mosquito with a bazooka.
- """
- if s is None:
- return ""
- if isinstance(s, unicode):
- return s.encode('ascii', 'xmlcharrefreplace')
- else:
+def sync_pinboard_links():
+ PB_URL = "https://api.pinboard.in/v1/posts/all?results=150&format=json"
+ r = requests.get(PB_URL, auth=((settings.PIN_USER, settings.PIN_PASS)))
+ links = json.loads(r.text)
+ print(links)
+ for link in links:
try:
- return str(s)
- except:
- return ""
+ #check to see if link exists
+ row = Link.objects.get(link_id=link['hash'])
+ print("already have" + row.title)
+ except ObjectDoesNotExist:
+ l, created = Link.objects.get_or_create(
+ title=link['description'],
+ link_id=link['hash'],
+ url=link['href'],
+ description=link['extended'],
+ rating="3",
+ pub_date=datetime.datetime.strptime(link['time'], "%Y-%m-%dT%H:%M:%SZ"),
+ status=0
+ )
+ print(l.title)
+ if created:
+ print(l.title)
+ for t in link['tags']:
+ l.tags.add(t)
-def sync_pinboard_links():
- """
+"""
+def sync_pinboard_links_old():
sync bookmarks from my pinboard account
dependancies: python-pinboard https://github.com/mgan59/python-pinboard/
- """
p = pinboard.open(settings.PIN_USER, settings.PIN_PASS)
dupe = False
links = p.posts(count=30)
@@ -58,6 +67,7 @@ def sync_pinboard_links():
l.tags.add(t)
email_link(l)
+"""
def email_link(link):
"""