added a function to automatically send new public polls to twitter

This commit is contained in:
phear 2010-05-13 12:42:05 +00:00
parent c6fe7356bf
commit e8d1cb5b12

View file

@ -22,6 +22,7 @@ import datetime
import mimetypes
import uuid
import re
import twitter
CONFIG_FILE = os.path.join(BASE_DIR, "wortschlucker.conf")
@ -145,6 +146,11 @@ class Poll(sqlobject.SQLObject):
poll_setting[0].value = validated_value
elif poll_setting.count() == 0:
PollSetting(poll_id=self.id, key=key, value=validated_value)
if (key == 'public') and (value > 0):
publish_twitter_alert( \
config.get('misc','twitter_alert_prefix')+' '+self.title[0:79]+' http://wortschlucker.de/'+self.hash_key, \
config.get('misc','twitter_alert_user'), \
config.get('misc','twitter_alert_password'))
def get_num_of_submitters(self):
all_submitters = [submission.submitter for submission in ContentSubmission.selectBy(poll_id=self.id)]
@ -352,6 +358,16 @@ def get_new_hash_key(length=16, charset=None):
hash_key = get_hash_string(length)
return hash_key
def publish_twitter_alert(text, user, passwd):
api = twitter.Api(username=user, password=passwd)
try:
api.PostUpdate(text)
except:
#twitter error, most likely because of a duplicate message
pass
@bobo.query('/new')
@bobo.query('/new/:template')
@bobo.query('/new/:author/:title/:description')
@ -525,7 +541,7 @@ def base():
@bobo.query('/')
def show_frontpage(page=None):
return show_poll_list("frontpage.html", 10, page)
return show_poll_list("frontpage.html", 20, page)
@bobo.query('/admin')
@bobo.query('/admin/')