How to update twitter account with python
Published on April 2, 2010category: programming Tags : django python tips twitter
To update your twitter account via python you can use the python-twitter api.
Download it and unzip it within your PYTHONPATH ( you can do it inside a django project ... i think so).
In the python interpreter you can :
api = twitter.Api(username='', password='')
message = 'hello twitter from python'
status = api.PostUpdate(message)
and go check your twitter account. Dont forget to enter username and password.
In django i put that code inside my save function in Entry model so when i save an Entry i update twitter, check it:
def save(self, force_insert=False,force_update=False):
self.body_html = markdown(self.body)
if self.excerpt:
self.excerpt_html = markdown(self.excerpt)
super(Entry, self).save(force_insert,force_update)
import twitter
try:
api = twitter.Api(username='', password='')
message = self.title+" "+"http://gkomninos.com"+self.get_absolute_url()
status = api.PostUpdate(message)
except Exception:
pass
try:
ping_google()
except Exception:
# Bare 'except' because we could get a variety
# of HTTP-related exceptions.
pass
