Writing an Android Twitter Client with Python

import android       # core Android routines
import httplib       # for talking to web servers
import urllib        # to format our status update nicely
import base64        # to encode our username and password for Basic authentication

print ‘Cool, we\’re running!’       # sorry, had to do this…

# get an instance of Android
droid = android.Android()

# where are we posting data to?
twitterhost = ‘twitter.com’
uri = ‘/statuses/update.xml?’

# get our status update from user
statusmsg = droid.getInput(‘Twitter Update’,’Whatcha Doin?’)

#extract the “textual” portion of the response
statusdata = “%(result)s” % statusmsg

# uncomment the next line to display the message to the terminal screen
#print statusdata

# uncomment the next line to display a notification to the user
#droid.makeToast(statusdata)

# clean up the data so it can be sent as the ‘querystring’
statusupdate = urllib.urlencode({‘status’:statusdata})

# setup your username and password here…
username = ‘yourusername’
password = ‘yourpassword’
credentials = username + “:” + password

# uncomment the next line to see what credentials you are using….
#print credentials

encodedcredentials = base64.encodestring(credentials)

# connect to server
h = httplib.HTTP(twitterhost)

# build url we want to request
fullurl = uri + statusupdate

#uncomment the next line to see the url printed
#print fullurl

# POST our data.  Twitter requires status updates to be POSTed
h.putrequest(‘POST’,uri + statusupdate)

# setup the authentication header
h.putheader(‘Authorization’,’Basic ‘ + base64.encodestring(credentials))

# setup the user agent
h.putheader(‘user-agent’,’Android-Scripting-Engine-Python’)

# we’re done with the headers….
h.endheaders()

# get the response from the request
returncode,returnmsg,headers = h.getreply()

# should compare the returncode to 200 for a good response, etc.

#display whatever the results are….
f = h.getfile()
print f.read()

Source http://code.google.com

  1. #1 by hack on June 28, 2013 - 12:15 pm

    Hi there! I know this is kind of off-topic but I had to ask.
    Does operating a well-established blog like yours require a large amount of work?
    I’m completely new to operating a blog but I do write in my journal everyday. I’d like to start a blog so I can
    easily share my personal experience and feelings online. Please
    let me know if you have any kind of ideas or tips for new aspiring
    blog owners. Thankyou!

    • #2 by hvera1981 on July 1, 2013 - 2:42 pm

      Hi there, usually I am trying to publish more stuff weekly.

      I try to keep this a easy to consult page since I cannot trust my memory anymore :), if you do that I am pretty sure you will get lots of stuff in your blog.
      When it is ready please let me know about it.

      Thanks!

  2. #3 by Perfect Kick Hack Cheat on July 3, 2013 - 3:55 am

    With havin so much written content do you ever run into any issues of plagorism
    or copyright violation? My site has a lot of exclusive content I’ve either authored myself or outsourced but it seems a lot of it is popping it up all over the internet without my authorization. Do you know any techniques to help prevent content from being ripped off? I’d definitely appreciate it.

    • #4 by hvera1981 on July 4, 2013 - 2:36 pm

      Hi, not yet.

      I always link the reference with the legit information source, so until now I have no complains

      I would suggest that you deploy a user/login strategy to your website. It will grant some control.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: