summaryrefslogtreecommitdiff
path: root/apps/links/retriever.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/links/retriever.py')
-rw-r--r--apps/links/retriever.py120
1 files changed, 35 insertions, 85 deletions
diff --git a/apps/links/retriever.py b/apps/links/retriever.py
index 35bd41a..f876405 100644
--- a/apps/links/retriever.py
+++ b/apps/links/retriever.py
@@ -1,75 +1,46 @@
-import time, datetime, urllib
+import datetime
from django.core.exceptions import ObjectDoesNotExist
-from django.template.defaultfilters import slugify,striptags
+from django.template.defaultfilters import striptags
from django.core.mail import EmailMessage
-from django.utils.encoding import smart_unicode
from django.conf import settings
from utils.strutils import safestr,unquotehtml
-from utils.APIClients import MagnoliaClient
-from utils import pydelicious as delicious
-from utils import markdown2 as markdown
-
from links.models import Link
+from utils import pinboard
-def flickr_datetime_to_datetime(fdt):
- from datetime import datetime
- from time import strptime
- date_parts = strptime(fdt, '%Y-%m-%dT%H:%M:%S%Z')
- return datetime(*date_parts[0:6])
-
-def sync_magnolia_links(*args, **kwargs):
- #Number of links to retrieve at one time
- get_num = 15
- BASE_PATH = 'http://ma.gnolia.com/api/rest/1/'
- client = MagnoliaClient(BASE_PATH, settings.MAGNOLIA_API_KEY)
- data = client.bookmarks_find(person="luxagraf",limit=get_num)
+def sync_pinboard_links():
+ """
+ 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
- for post in data.findall('bookmarks/bookmark'):
- taglist = []
- info = dict((k, smart_unicode(post.get(k))) for k in post.keys())
+ links = p.posts(count=30)
+ for link in links:
try:
- row = Link.objects.get(magnolia_id=safestr(info['id']))
- # If the row exists already, set the dupe flag
- dupe = True
+ #check to see if link exists
+ row = Link.objects.get(link_id=safestr(link['hash']))
except ObjectDoesNotExist:
- f = copy_file(safestr(post.findtext('screenshot')), safestr(info['id']))
- local_image_url = "%s/%s.jpg" %(safestr(datetime.datetime.today().strftime("%b").lower()), safestr(info['id']))
-
- for t in post.findall('tags/tag'):
- tag = dict((k, smart_unicode(t.get(k))) for k in t.keys())
- taglist.append(tag['name'])
- print tag['name']
- for tag in taglist:
- if tag == '2lux':
- status = 1
- break
- else:
- status = 0
- descr = markdown.markdown(unquotehtml(safestr(post.findtext('description'))), safe_mode = False)
l, created = Link.objects.get_or_create(
- title = post.findtext('title'),
- magnolia_id = safestr(info['id']),
- url = safestr(post.findtext('url')),
- description = descr,
- screen_url = local_image_url,
- rating = safestr(info['rating']),
- pub_date = datetime.datetime(*(time.strptime(str(info['created'][:-6]), '%Y-%m-%dT%H:%M:%S')[0:6])),
- status = status,
- enable_comments = True,
- tags = ", ".join(t for t in taglist if t != "2lux")
+ title = link['description'],
+ link_id = safestr(link['hash']),
+ url = safestr(link['href']),
+ description = safestr(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)
email_link(l)
- send_to_delicious(l)
- if l.status == 1:
- post_to_tumblr(l)
- send_to_deliciousfb(l)
- if(dupe):
- break
-
+
+'''
def sync_delicious_links(*args, **kwargs):
b = delicious.get_all(settings.DELICIOUS_USER, settings.DELICIOUS_PASS)
dupe = False
@@ -116,8 +87,7 @@ def sync_delicious_links(*args, **kwargs):
break
-
-
+'''
def email_link(link):
"""
@@ -125,9 +95,12 @@ def email_link(link):
"""
subject = link.title
body = "%s\n\n%s\n\n\nvisit site:%s\n" %(link.title, link.description, link.url)
- msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['luxagraf@gmail.com'])
+ msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['luxagraf+links@gmail.com'])
msg.send()
-
+ msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['sng+links@luxagraf.net'])
+ msg.send()
+
+'''
def send_to_delicious(link):
del_tags = ''
tags = link.tags.split(',')
@@ -135,27 +108,4 @@ def send_to_delicious(link):
del_tags += tag.strip().replace(' ','_')+' '
delicious.add(settings.DELICIOUS_USER, settings.DELICIOUS_PASS, link.url, link.title, tags = del_tags, extended = striptags(link.description), dt =safestr(link.pub_date), replace="no")
-def copy_file(url, id):
- filename="/home/luxagraf/webapps/static/images/magnolia_thumbs/%s/%s.jpg" %(datetime.datetime.today().strftime("%b").lower(), id)
- urllib.urlretrieve(url, filename)
- return id
-
-def post_to_tumblr(link):
- from links import tumblr
- blog = settings.TUMBLR_URL
- user= settings.TUMBLR_USER
- password = settings.TUMBLR_PASSWORD
- api = tumblr.Api(blog,user,password)
- post = api.write_link(link.url,name=link.title,description=link.description,date=safestr(link.pub_date))
-
-def send_to_deliciousfb(link):
- """Wanted my links to go to Facebook and since the Facebook API is needlessly complex
- I just created a second delicious account and added the feed via facebook"""
- del_tags = ''
- tags = link.tags.split(',')
- for tag in tags:
- del_tags += tag.strip().replace(' ','_')+' '
- desc = link.description.replace('<blockquote>','\n&#8220;')
- desc = desc.replace('</blockquote>','&#8221;\n')
- desc = striptags(desc)
- delicious.add(settings.DELTOFACEUSER, settings.DELTOFACEPASS, link.url, link.title, tags = del_tags, extended = desc, dt =safestr(link.pub_date), replace="no")
+''' \ No newline at end of file