diff options
Diffstat (limited to 'apps/links/utils.py')
-rw-r--r-- | apps/links/utils.py | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/apps/links/utils.py b/apps/links/utils.py index a575f4f..2649dde 100644 --- a/apps/links/utils.py +++ b/apps/links/utils.py @@ -1,4 +1,4 @@ -import time, datetime +import time, datetime, urllib from django.core.exceptions import ObjectDoesNotExist from django.template.defaultfilters import slugify,striptags @@ -7,7 +7,6 @@ from django.utils.encoding import smart_unicode from strutils import safestr,unquotehtml from APIClients import MagnoliaClient -from urlgrabber.grabber import URLGrabber import pydelicious as delicious import markdown2 as markdown @@ -64,6 +63,9 @@ def sync_magnolia_links(*args, **kwargs): email_link(l) send_to_delicious(l) + if l.status == 1: + post_to_tumblr(l) + send_to_deliciousfb(l) if(dupe): break """ @@ -123,11 +125,29 @@ def send_to_delicious(link): tags = link.tags.split(',') for tag in tags: del_tags += tag.strip().replace(' ','_')+' ' - print del_tags - delicious.add('luxagraf', 'translinguis#', link.url, link.title, tags = del_tags, extended = link.description, dt =safestr(link.pub_date), replace="no") + 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): - g = URLGrabber() - filename="/home2/luxagraf/webapps/images/magnolia_thumbs/%s/%s.jpg" %(datetime.datetime.today().strftime("%b").lower(), id) - local_filename = g.urlgrab(url, filename) - return id
\ No newline at end of file + 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“') + desc = desc.replace('</blockquote>','”\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") |