Remote Control your android with Airdroid

So I found this free android app, which allows remote control an android phone using a web browser. Once the app is install, you can start it pretty easily, with the url on displayed on the app. 
What you get after open a browser, is a desktop like interface where one can use it to do quite a lot of stuff. 
You can manage app from it, it install by redirect to the android marketplace web interface, but you can uninstall using the application Icon.
You can manage app install
You get a file manager that manipulate your sdcard, you can copy file from the PC, using the import button, and download the file using the export button on the file manager. 
File manager like what you use in normal desktop OS
Write or reply sms
There is also photo, and musics on the browser, view the contact list, etc. It is really have a lot of feature. 
For a free app, this actually offer a lot of stuff. For a webapp, it sure look like a full blown desktop. You can control the apps on the phone, but it is ok. It is useful enough for me. 
The app is free on android market place, https://market.android.com/details?id=com.sand.airdroid. I recommend that you guys try it out. 

Adventure in Bottle( the web framework)

So I have been scraping data online for sometime. While scraperwiki have an API that allow third party app to get data in json/xml form. I think I can make it easier, because scraperwiki query involve doing a sql query on the sqlite datastore. Thus I take the opportunity to learn new python web framework.

The framework only need to handle request, and spit data in json(maybe xml later). It does not need a template, it is json. It don’t need an ORM, the data most probably scrape from somewhere else. It do not need session, it is meant to be use by library. The data is open anyway. 
The first framework I try out is Bottle
The first thing I notice is the amount of setup that I have to do, coming from a django background. Which is well known for the big settings.py file. The amount of setup is small. Just install using ‘pip install bottle’.
Essentially just an application defined, with the object Bottle()
And pass to the run function. 
By default bottle already have a default application, so you don’t strictly need it, I just to put it there to show that it is there.
Another thing I have noticed is, there is no url route in a separate file. A route decorator is added to a function that I want to serve in the web app. The route is part of the application(the Bottle() object), and I can limit the type of request I can do on it, like POST/GET. I found that this approach is pretty clean, it reduces the boiler plate like in django views. 
Another thing to notice is. I do not specify a response method/object(like django). That is another nice thing about bottle. If the function returns a dict, the response will be in json. If string then the mimetype is text, etc. There is no need to specify a function for response.

Finally to run the app, just run python server.py (or any python file with the bottle run function). You have an webapp. 

For this project I didn’t test the template, but from the doc, it is specified with a view decorator, which I think is nice, but I don’t need it now. From the doc, I found that it is pretty clean.

Because bottle is a micro framework, there is no manage.py script like django, no ORM, I uses sqlalchemy here. There is no session support too. But interestingly I don’t feel that I missed anything. In fact, it is pretty pleasant to use. Though session will definitely bite me if I ever have to implement login, but solution is on the documentation.

Overall, it is a fun framework to use, even though this is a small project. The documentation is pretty good. I might use it for future project.

Using Python Function with sqlite

Note: You can find the docs in the python doc page http://docs.python.org/library/sqlite3.html#sqlite3.Connection.create_function

This is more of a experience. Not too long ago, I have scrape from the parliament website on profiles of Member’s of Parliament, you can find the result here.

The thing is, as I use the data from the sqlite database, I download from the site, I realized that, the Title is part of the name of the MP’s. So one would get “XXX , Y.B Tuan”. Y.B Tuan is the title.

That would make query like ‘select Parti from swdata where Nama=name’ hard. Because this is precisely what I am looking at, for another project.

On the other hand, sqlite3 module, apart comes with python standard library since 2.6. Actually have a function called, Connection.create_function.

So I wrote a little function called get_name, and the example show how it works.

import sqlite3 

def get_name(name):
    return name.split(‘,’)[0]
 

s = sqlite3.connect(‘dbname’)
# attach the python function
s.create_function(‘get_name’,1,get_name)
# and use it
result = s.execute(‘select get_name(Nama) from swdata’)
print result.next()[0]

Just define a python function,  make sure it return datatype that is compatible with sqlite, attach it with create_function. Now you can use it in your sqlite query in python

Hope this is useful for someone. CHEERS

A little plug, this is something we try to work on in this little group call Sinar Project, and this is still in an early stage