Monday, November 15, 2010

App Engine Helper for Django - Part I

Even with the easy instructions on installing GAE Django Helper I ran into several problems. Most of these were Import Error.

from google.appengine.ext import db
ImportError: No module named google.appengine.ext

django.core.exceptions.ImproperlyConfigured: 'appengine' isn't an available database backend. 
Try using django.db.backends.XXX, where XXX is one of:
    'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named appengine.base

google.appengine.dist._library.UnacceptableVersionError

Turns out settings.py was not pointing correctly to appengine_django. I had copied the app directory to my project's directory but the path didn't include the project name. The app was still running fine when using launcher. 

Here's how the correct entry should look

INSTALLED_APPS = (
     'djproject.appengine_django',
     'djprorject.mydjapp',
#    'django.contrib.auth',
#    'django.contrib.contenttypes',
#    'django.contrib.sessions',
#    'django.contrib.sites',
)

Another point, although instructions here say that you don't need django.zip in your project folder...it didn't work for me without it.

I will do another post giving step by step for using django helper for GAE.

Here's a successful run of runserver with django and GAE helper.

ruch:djproject ruchi$ ./manage.py runserver
WARNING:root:Could not read datastore data from /var/folders/d9/d92Wee6VGY4YhfNUP1rgnU+++TM/-Tmp-/django_mixq.datastore
WARNING:root:Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO:root:zipimporter('/Users/ruchi/djproject/django.zip', 'django/contrib/')
INFO:google.appengine.tools.appengine_rpc:Server: appengine.google.com
INFO:root:Checking for updates to the SDK.
INFO:root:The SDK is up to date.
WARNING:root:Could not read datastore data from /var/folders/d9/d92Wee6VGY4YhfNUP1rgnU+++TM/-Tmp-/django_mixq.datastore
WARNING:root:Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO:root:Running application mydjapp on port 8000: http://localhost:8000

Friday, November 12, 2010

Exporting Contacts from Facebook - How many care?

There have been discussions around how Facebook is evil about not letting "everyone" get their contact data out unless they happen to have a free yahoo or hotmail account. The discussions 

Techcrunch has an article today about how to create a new yahoo account to get most of your contact data out.

Do people care about their contact data? How many of them do?

The contact data I'm importing to Facebook is already with me on gmail, why do I care if Facebook is gonna lock it down? Even if we consider that I might need contact data of my new Facebook friends, how many people are still use email anyways? Isn't most communication thru Facebook status and messages or IM's.

People who care about the data are in minority. Techcrunch reaches 0.7% global users while Facebook has 37.3% global reach. Even if 10 fold techcrunch readers cared about their data, they are still not enough.

I know it can be debated that people have no option but to join where their friends are. Would you make deposits in a bank where you cannot withdraw the interest that your money generates? The point being people don't value their contacts like Facebook does.

Thursday, November 11, 2010

GAE Error when displaying datastore entity key

Error
TypeError: write() argument 1 must be string or read-only character buffer, not Key

Reason
I was trying to display key for an entity. Python/ Java API returns keys as an instance of the entity class. Convert it to string to pass it or to display.

Running Django on Google App Engine

It took about five hours but I did it!!!

Google has this simple tutorial on how to start first Django project on GAE. It's helpful but not enough to debug all the errors novices run into. Here's the step by step instructions for someone familiar with basic Django.

1. Create the GAE app. 

Let's call it gaeapp.

I use GUI to provide app name and it creates a directory with following files.
app.yaml
index.yaml
main.py

2. Create the django project INSIDE the GAE app directory.
If you have created a Django project before, you would know to do so using

django-admin.py startproject djprj

Now we have a directory called djprj with following files.
__init__.py
manage.py
settings.py
urls.py

3. OPTIONAL
If you want, you can copy all the django files to GAE dir. Make sure to remove all refrences to Django project name. e.g. djprj.settings would become settings.

4. Edit app.yaml
I followed the instructions on the google's tutorial and kept getting error message - "unknown URL handler type". Turns out the code was not indented properly. 

"ERROR    2010-11-11 06:42:51,957 dev_appserver_main.py:407] Fatal error when loading application configuration:

while scanning a simple key
  in "~/gaeapp/app.yaml", line 8, column 1
could not found expected ':'"

Received above error since static_dir: and static were not separated by space. 

So this is how my appl.yaml looks
application: gaeapp
version: 1
runtime: python
api_version: 1

handlers:
- url: /static
  static_dir: static
- url: .*
  script: main.py

5. Edit main.py
Here's how my main.py looks. Note that if both django and GAE files are in the same folder, you should point DJANGO_SETTINGS_MODULE to the current directory and omit the Django project name unlike the google tutorial.

I kept getting message about DJANGO_SETTINGS_MODULE is not defined and then it disappeared. 

import os, logging
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

from django.conf import settings
settings._target=None
os.environ['DJANGO_SETTINGS_MODULE']='djprj.settings'

import django.core.handlers.wsgi
import django.core.signals
import django.db
import django.dispatch.dispatcher

#class MainHandler(webapp.RequestHandler):
#    def get(self):
#        self.response.out.write('Hello World!')

def main():
    #application = webapp.WSGIApplication([('/', MainHandler)], debug=True)
    application=django.core.handlers.wsgi.WSGIHandler()
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

6. Edit settings.py
  1. Comment out all of the middleware parameter else you might get this error "AttributeError: 'module' object has no attribute 'messages'".
  2. Ensure ROOT_URLCONF = 'urls' if  Django files are in GAE dir. Else it will be djprj.urls since our project is called djprj.

7. Done! 
Run the GAE app and the corn blue awaits you.

8. Doing the work - adding code
Standard Django practice is to have code in views.py. So let's 
create a views.py in Django dir. This will contain some code for first Django GAE app. This is what I've got -

from django.http import HttpResponse

def sayhello(request):
    return HttpResponse("This is my first GAE app using Django")

9. Edit urls.py
The standard process of including  code in django url.

from django.conf.urls.defaults import *
from djprj.views import *

from django.conf.urls.defaults import *
from djprj.views import *

urlpatterns = patterns('',
    ('',sayhello),
)

10. Refresh your page or restart your GAE app.

Tuesday, November 09, 2010

An African Elephant Sketch

Here's the original - 

Mine didn't turn out that well. Looks kind of aged. 

Monday, November 08, 2010

Untitled

Contrasted pink with gray just to see how it looks. Not to bad eh :)

Friday, November 05, 2010

Crayon Sketch

Time to draw : 15 mins

Mac OSX Disk Sweeper

With over year and half of data, my mac harddrive is choking. With backups for previous machines and trip photographs and applications etc. Although I've backup on external harddrive, my fingers still refuse to delete anything worthwhile from my mac. So until I bought another harddrive to backup my backup, I had to do some clean up. A quick googling helped me find this awesome software called Disk Sweeper that gives the directories in the descending order of size.
http://www.omnigroup.com/products/omnidisksweeper/

Jeff Dunham Show

Watched the show at the Ohio State Fair last night. I took a "sky ride" ride and had an aerial view of most of the fairground. They have so many rides! The Celeste Center theatre was right in the middle of the fairgrounds. The theatre is huge and clean but the seats suck! With the uncomfortable, narrow and close seats, it manages to seat 10k.

Show itself was good! Jeff showed a new doll - Diane, who plays his wife in the movie - Dinner for Schmucks. Guitar guy played us three songs before Jeff came onstage. It was fun! The theatre had arranged an interpreter for the hearing impaired.

Amazon Kindle has games

If you have an Amazon Kindle and you didn't already know it, go get your Kindle and try it out like now. When on home screen, press SHIFT (the up arrow key ↑)  + ALT + M and voila - there's the hidden Minesweeper. Use joystick to explore and "m" to mark/unmark mines. And if you hit "g" you could play GoMoku. I had never heard of GoMoku and simply explained it's Tic-Tac-Toe but you need 5 consecutive rows to win.

Enjoy!

Minesweeper on Kindle

GoMoku

More on the under the hood working of Kindle here

BumpTop

Checkout the 3D room like appearance of desktop. It looks pretty neat isn't it. You could pile stuff just like in a book store.

The software was developed by bumptop who have been acquired by Google and the software is off the shelves now.

Amazon buying your old books

Amazon is offering a trade in of amazon gift card worth $5 or more for your used books in good condition. These books will be purchased by a Third Party Merchant. How convenient is it that that shipping is free. So no more selling your books for the same amount and wait in queue at halfprice bookstore or reposting those craigslist advts.

Cute Puss sans boots

If you have seen any of the Shrek movies, well not any, but ones after 1st Shrek you know who Puss is. Puss is the ninja cat - nimble, fast, sharp and in the boots at that. This is how Puss looked before.

With Shrek Forever After, Puss gets a make over...a big fat one. One of the most hilarious scenes from the movie, when puss and donkey are drenched are trying to groom themselves.
</object>
 
 
While looking for pics, I learnt that there really is a fairy tale character by the same name and also has a sophisticated French name to boot :-) Le Maistre Chat  (the master cat) and also ou Le Chat Botté (the booted cat).
 
Here's the complete story with colorful illustrations.