Category Archives: google

Google App Engine Adventure: The Experiment.

Yesterday google have release their App Engine. Which provides hosting, database, scaling and load balancing, and also API’s. Which currently uses python. But there is more to come.

So I got an account, which probably not available anymore. Either way and spend an afternoon, write up a prototype. It is actually longer, since I need to refresh my html, and missed a wrong unclose { in the template. Then fixed up the database support. And check out a python doc, because not sure how, datetime work.

First thing first, assume you already have everything, is the configuration, app.yaml

application: testapp
version: 1
runtime: python
api_version: 1
handlers:
– url: /
script: main.

so far pretty simple, but as application getting complex, it will have more configuration. For simple apps this would do.

Second is the code.

import os
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from datetime import *
class Events(db.Model):
name=db.StringProperty(required=True)
date=db.DateTimeProperty(required=True)

class MainPage(webapp.RequestHandler):
def get(self):
day=range(1,31)
month=range(1,12)
year=range(2008,2020)
hours=range(0,23)
minutes=range(0,59)
events=Events.all().order(‘-date’)
templ={‘events’:events,
‘day’:day,
‘month’:month,
‘year’:year,
‘hours’:hours,
‘minutes’:minutes}
path = os.path.join(os.path.dirname(__file__), ‘main.html’)
self.response.out.write(template.render(path,templ))

def post(self):
dt=self.request.get(‘year’)+’-‘+self.request.get(‘month’)+’-‘+\
self.request.get(‘day’)+’ ‘+self.request.get(‘hour’)+’:’+\
self.request.get(‘minute’)+’:00′
event=Events(name=self.request.get(‘name’),
date=datetime.strptime(dt,’%Y-%m-%d %H:%M:%S’),
location=self.request.get(‘address’),
description=self.request.get(‘description’))
event.put()
day=range(1,31)
month=range(1,12)
year=range(2008,2020)
hours=range(0,23)
minutes=range(0,59)
events=Events.all().order(‘-date’)
templ={‘events’:events,
‘day’:day,
‘month’:month,
‘year’:year,
‘hours’:hours,
‘minutes’:minutes}
path = os.path.join(os.path.dirname(__file__), ‘main.html’)
self.response.out.write(template.render(path,templ))

def main():
apps = webapp.WSGIApplication([(‘/’,MainPage)],debug=True)
wsgiref.handlers.CGIHandler().run(apps)

if __name__==”__name__”:
main()

Basically, now I’m worried that, it will get more complex, when it got longer.

Lastly the template. Which I can’t really show on the block

Then start the dev_appserver.py. Then it runs. It’s ugly, but it shows a few thing to me.

google release their chart api

Just now, google have release their chart api, basically it is a api, that generate chart, using a rest interface.

http://code.google.com/apis/chart/

Here is an example what it can do,


Basically it is a hello world.
http://chart.apis.google.com/chart?cht=lc&chs=200x125&chd=s:helloWorld

a more practical example is this, it is a rough statistics on internet user in the dorm:
http://chart.apis.google.com/chart?cht=p&chs=200x125&chd=s:Nu&chl=niu|iu

niu=non internet user
iu=internet user

the catch is you need to encode your data into a string, notice the chd, that is the data encoded.
you can find more info on the links above.

The thing is this is an easy way for us to actually, visualize data for our website. the fact that it uses a rest interface, does make it easy, to write script to automate task

Google Android on Ubuntu

So google have release android sdk. So I just have to install it. To get it working on ubuntu.
First download the SDK here.

This instruction is specific from ubuntu.
After you uncompress the file.
In /home/ .
There is a .bashrc file. Just add this line

PATH=”$PATH:the path of android tools

at the end of .bashrc file.

Then just install eclipse, and download the android eclipse integration. And just setup in windows->preference menu in eclipse. Then it is done