Running Standalone SQLAlchemy Scripts in Pyramid

From time to time there comes the need to run automated scripts managed by either Python or Cron. In a recent project I had to run a standalone script that checks records on a database at certain hours. So here’s what I came up with. Most of the script is based on this post by [...]

Facebook FQL Request Error

Today while attempting to query Events data through FQL, I received the following error: Impersonated access tokens can only be used with the Graph API. It was a strange error since I had already created my access token with the right scope. To query the data I’m using the pythonforfacebook SDK which uses https://api.facebook.com/method/fql.query as [...]

Simpleform Localization in Pyramid

In a recent project I had to localize the errors thrown by the pyramid_simpleform package. Googling for information I couldn’t find how to do it, so here’s what worked for me at the end. from pyramid.i18n import get_locale_name from pyramid_simpleform import Form,State   from formencode import api as formencode_api   def includeme(config): config.scan(__name__) config.add_route(’login’, ‘/login’) [...]

Manage cron jobs with python-crontab

Cron is the main time based scheduler for any linux based system and is available in almost every distro. And in a recent project I had the task to manage jobs in cron from python. Searching for a good cron manager I came across python-crontab. It makes it really easy to manage jobs directly from [...]

Facebook SDK For Python Deprecated

Yesterday Facebook without a notice or warning decided it to delete their SDK github repo for Python. Today the repo is back online but with a notice saying that they have no plans to update it anymore. I’ve been seeing this coming since they stop adding new features awhile ago. So anyways there’s an alternative [...]

UUID Objects in Pylons with SQLAlchemy

Recently I had to generate and store uuid objects into a Postgres database, but to my surprise SQLAlchemy kept showing the following error: sqlalchemy.exc.ProgrammingError: (ProgrammingError) can’t adapt type ‘UUID’ So the solution was that I had to change my field type from varchar to uuid on my Postgres database, import the psycopg2 extras functions and [...]

Implementing a text based captcha in Pylons

One of the must have elements on any html form as an anti-spam measure is a captcha, and the captcha technique that has worked pretty well for me is text based. So here’s how to implement one. Create a controller and name it captcha ~$ paster controller captcha Add this function to your helpers.py file [...]

Pylons and Twitter Based Authorization

Implementing Twitter authorization in Pylons is easy as butter, I will show you how to do it in the next steps. Download python-twitter and install it https://code.google.com/p/python-twitter python setup.py build python setup.py install Download and install dependencies https://github.com/simplegeo/python-oauth2 http://code.google.com/p/httplib2/ http://cheeseshop.python.org/pypi/simplejson Now you’re almost there. There’s a file called get_access_token.py that you need to call in [...]

Pylons and Facebook based Authorization with OAuth 2.0

Authorizing a user using Facebook OAuth 2.0 based login it’s pretty straighfoard. This is for the person who asked a question on stackoverflow.com I hope it helps. Add the apikey, appid and secret of my Facebook app to the development.ini file facebook.apikey = 42bc5a4051b274ede5cb73a6cd6fad56 facebook.secret = a355e66e8c0293390896a170f9d5r4c3 facebook.appid = 20894420580890 Configure my model/init.py file: from [...]

repoze.what with reflected tables using SQLAlchemy in Pylons

One of the many things I like about SQLAlchemy is the feature of reflected tables, this means I can develop dashboards for existing applications with my current favorite framework(Pylons). So I had to create an authorization mechanism for my dashboard and this recipe from the Pylons cookbook was just what I needed. The only thing I [...]