3 # Copyright (C) 2013 FinalsClub Foundation
5 from celery import task
6 from karmaworld.apps.notes.models import Note
7 from karmaworld.secret.twitter import *
10 from pyshorteners.shorteners import Shortener
12 logger = logging.getLogger(__name__)
14 @task(name="tweet_note")
16 """Tweet about a new note."""
18 api = twitter.Api(consumer_key=CONSUMER_KEY,
19 consumer_secret=CONSUMER_SECRET,
20 access_token_key=ACCESS_TOKEN_KEY,
21 access_token_secret=ACCESS_TOKEN_SECRET)
23 newest_notes = Note.objects.all()[:100]
24 for n in newest_notes:
26 update = tweet_string(n)
27 logger.info("Tweeting:")
30 # Mark this tweeted before we actually tweet it
31 # to be extra safe against double tweets
35 api.PostUpdate(tweet_string(n))
40 def tweet_string(note):
41 # This url will use 13 characters
42 shortener = Shortener('GoogleShortener')
43 url = "https://www.karmanotes.org" + \
44 note.get_absolute_url()
45 short_url = shortener.short(url)
50 school = note.course.school.slug
51 short_school = school[:school.find('-')][:16]
56 short_course = note.course.name[:50]
58 # space and colon characters
61 short_note = note.name[:57]
63 return short_url + " #" + short_school + " " + \
64 short_course + ": " + \