Programming Live Blog

Short comments … produced live while coding.

Authorizing a twitter-bot

So last night I ran into a small issue, how to authorize a twitter bot to use an application without stubbing together a website and logging in with the bot account?  The answer, this little script using twython:

import twython

app_key = raw_input("Your app key: ")
app_secret = raw_input("Your app secret: ")

twitter = twython.Twython(app_key, app_secret)

auth = twitter.get_authentication_tokens()

print "Log into Twitter as the user you want to authorize and visit this URL:"
print "\t" + auth['auth_url']

pin = raw_input("Enter your PIN: ")

twitter = twython.Twython(app_key, app_secret, auth['oauth_token'], auth['oauth_token_secret'])
tokens = twitter.get_authorized_tokens(pin)

print "Your token: " + tokens['oauth_token']
print "Your token secret: " + tokens['oauth_token_secret']

Source: https://gist.github.com/moonmilk/035917e668872013c1bd#gistcomment-1398946

Posted by Chad Dotson in Programming, Programming Live Blog, 0 comments

Virtualenvwrapper / Updating Tools

If you are using virtualenvwrapper with the default version of python on your system (OSX in particular) and I recommend updating pip and setuptools as part of your postmkvirtualenv hook.  Just add the following line to YOURVIRTUALENVDIRECTORY/postmkvirtualenv.

pip install -U pip setuptools

 

Posted by Chad Dotson in Programming Live Blog, Tips, 0 comments

Don’t use parse_requirements in your code

I just ran into trouble while building a setuptools package.  Specifically, I was using pip.req.parse_requirements to process package dependencies from a requirements.txt file and noticed that upgrading pip would break my code.  Upon further investigation, I found out that they(authors of pip) do not guarantee the api of their internal code.  This is because they officially do not provide a programmatic api to pip see (https://github.com/pypa/pip/issues/2286).  My suggestion, just use readlines, its the same thing and dirt simple.

Posted by Chad Dotson in Programming, Programming Live Blog, 0 comments