From: Charles Connell Date: Mon, 23 Dec 2013 22:55:25 +0000 (-0500) Subject: Different URL shortening system X-Git-Tag: release-20150131~366^2~3 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=79f8b9f6533fee18550762c09da77ea16637f40b;p=oweals%2Fkarmaworld.git Different URL shortening system --- diff --git a/karmaworld/apps/notes/tasks.py b/karmaworld/apps/notes/tasks.py index b627ccf..16cb438 100644 --- a/karmaworld/apps/notes/tasks.py +++ b/karmaworld/apps/notes/tasks.py @@ -4,28 +4,33 @@ from celery import task from karmaworld.apps.notes.models import Note -from karmaworld.secret.twitter import * import twitter import logging -from pyshorteners.shorteners import Shortener +import gdshortener logger = logging.getLogger(__name__) + @task(name="tweet_note") def tweet_note(): """Tweet about a new note.""" - api = twitter.Api(consumer_key=CONSUMER_KEY, - consumer_secret=CONSUMER_SECRET, - access_token_key=ACCESS_TOKEN_KEY, - access_token_secret=ACCESS_TOKEN_SECRET) + try: + import karmaworld.secret.twitter as secrets + except ImportError: + logger.warn("No twitter secrets found, not running tweet_note") + return + + api = twitter.Api(consumer_key=secrets.CONSUMER_KEY, + consumer_secret=secrets.CONSUMER_SECRET, + access_token_key=secrets.ACCESS_TOKEN_KEY, + access_token_secret=secrets.ACCESS_TOKEN_SECRET) newest_notes = Note.objects.all()[:100] for n in newest_notes: if not n.tweeted: update = tweet_string(n) - logger.info("Tweeting:") - logger.info(update) + logger.info("Tweeting: " + update) # Mark this tweeted before we actually tweet it # to be extra safe against double tweets @@ -38,11 +43,11 @@ def tweet_note(): def tweet_string(note): - # This url will use 13 characters - shortener = Shortener('GoogleShortener') + # This url will use 12 or less characters + shortener = gdshortener.VGDShortener() url = "https://www.karmanotes.org" + \ note.get_absolute_url() - short_url = shortener.short(url) + short_url = shortener.shorten(url)[0] # space character @@ -58,9 +63,8 @@ def tweet_string(note): # space and colon characters # 57 characters - short_note = note.name[:57] + short_note = note.name[:58] return short_url + " #" + short_school + " " + \ short_course + ": " + \ short_note - diff --git a/reqs/common.txt b/reqs/common.txt index 850d8b9..bc168ee 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -17,4 +17,4 @@ requests beautifulsoup4 pyopenssl python-twitter -pyshorteners +gdshortener