Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Sep 5, 2010

Best practice to import libraries or frameworks in App engine

Usual procedure is to paste the library in your application's path then upload it with your application using appcfg - update.
This works but sometimes we have to deal with huge libraries consisting of hundreds of python files that sometimes exceed the upper limit of 1000 files / application limit or reduce the number of available files for your application. Also maintaining  those files becomes a nightmare.
So what is the proper way ? :

Sep 3, 2010

Allegro Non Troppo - Using Tropo API in App Engine

I was looking for an SMS - Voice gateway for an application of mine and after thoughtfully looking into Clicatell - twilio etc. I opted for Voxeo's tropo.
Do not ask much for the reasons I am not ready for a war over which one is better or cheaper to use.
I just felt like that tropo's "develop free - pay as you go once in production" business model fits well with App Engine's model that is on the same line, same applies to application scaling which is analogous to App Engine's.

So I decided to give it a try and here are my preliminary assessment of the service:

Jul 17, 2010

A bug in tweepy streaming API

I found a bug in tweepy streaming API .
It can't filter by tag with non Latin characters.
I was astonished coz this was working when I used it some months ago (version 1.3 if I remember well).
So here is my small contribution to the project :
def filter(self, follow=None, track=None, async=False):
   params = {}
   self.headers['Content-type'] = "application/x-www-form-urlencoded"
should be :
def filter(self, follow=None, track=None, async=False):
   params = {}
   self.headers['Content-type'] = "application/x-www-form-urlencoded; charset=utf-8"
I have only tested streaming and only tag filtering - probably this applies to other parts but I am not sure.

Jun 25, 2010

Re: What is the best way to convert a dictionary of data into a datastore entity?

If you are going to use your dictionaries as dictionaries back in your
program then why not save those into a Blob or Text datastore property
(by pickling or repr - eval or other means).

Jun 5, 2010

MultipleChoiceField Django field with select multiple

Yesterday I was trying to find a way to use MultipleChoiceField Django field along with a CheckboxSelectMultiple Django widget for an input form that contains some tags used in an App Engine model field.
There is an excellent solution described in ( better-way-to-use-djangos-selectmultiple-in-google-app-engine-for-a-listproperty/) except that it relies on
google-app-engine-django package which is a nice package bridging App Engine db models and Django models.
But ... for this particular case I needed a light solution with a very small footprint and a minimum of imports.
It was more easy than I though.
First define our input choices and respective labels : tagChoises = ( ('Tag 1', 'Economy'), ('Tag 2','Geograpy'))
Then define your form item: tags = forms.MultipleChoiceField(required=False, choices=tagChoises , widget=forms.CheckboxSelectMultiple)
The form now displays the check boxes which a user can fill.
Problem is, if a user selects multi tags only the one is returned for saving into the db and since this value is a unicode string while a list of string values is expected it results in an form error.
Solution: intercept the retrurned value in Request Handler post this is a UnicodeMultiDict .
It turns out that getall method of this class returns a list of the selected strings so last item of code : self.request.POST['tags']=self.request.POST.getall('tags' ) makes the trick and posted values are ready to be put.
I know this is an ungly hack but still it is ok for situations where the complete Django package is an overkill.