Is it possible to get users email by hosting gadget on appspot?

Google App Engine provides its User API service, using which you can allow people with Google Accounts to easily access your application. It works in a manner much similar to Google’s other login services. When you login, you are taken to a central page, common for all google services and then after you have authenticated yourself, you are redirected back to the service.

Since Google uses a central page for login and logout and it is a cookie based authentication, it might trigger question – if someone is logged into gmail or orkut or other such google service is it possible to get their Google Accounts using App Engine’s Users API? In order to do so, i deployed an application on App Engine, which would write “hello World!” on the canvas. This gadget XML is generated pragmatically and at the backend, there is a code which checks for a valid Google Account Holder.

The corresponding code goes as follows:
(There is no space at line 39, the space are mentioned here to go according to the syntax highlighter)

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class Users(db.Model):
user = db.UserProperty()
created = db.DateTimeProperty(auto_now = True)
updated = db.DateTimeProperty(auto_now_add = True)

class Log(db.Model):
msg = db.TextProperty()
created = db.DateTimeProperty(auto_now=True)
level = db.StringProperty(default=’info’)

class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
Users.get_or_insert(‘u_’+user.nickname(), user=user)
else:
Log(msg=’User is None’).put()

self.response.headers[‘Content-Type’] = “application/xml”
self.response.out.write(“””

<![CDATA[

hello World!

] ] >

“””)

application = webapp.WSGIApplication([(‘/’, MainPage)], debug=True)

def main():
run_wsgi_app(application)

if __name__ == “__main__”:
main()

]]>

Upon deploying the gadget on orkut and gmail, i found that everytime the gadget loads, i just see a new entry in the Log, saying “User is None”.

This means that you can authenticate only users for your own domain/application, not for all of the Google products services 🙂

The complete source code of the application can be found at its Google Code repository http://code.google.com/p/codecontrol-samples/source/browse/user-authentication/src/.

PyCon India 2010

PyCon India 2010 is the primary Python conference in India. A purely volunteer effort, it is being hosted for the second time in India, and will attract some of the best Python developers in India and abroad.
The conference will take place on 25th and 26th, September 2010.
The conference will consist of a number of full length presentations, a number of shorter lightning talks and open sprints and BoFs.

Links

Indian Python Software Society

Off recently, the trends in Python language usage is growing in India. To give a more professional touch to this community effort, the Indian Python Software Society (IPSS) has been formed. The mailing list of IPSS is at http://mail.python.org/mailman/listinfo/ipss. Other significant details can be found out at http://wiki.python.org/moin/IPSS.

The growing trends of Python will definitely make changes in the way Indian Computer Generation looks at programming languages.

Love Python 🙂

The mutability of Python Dictionaries

I have been working with Python dictionaries and came to learn quite a lot about it. Well first of all, Python dictionaries are a mapping object types. Said that, it means we can create a mapping and store it in dictionary objects.

It goes on something like this

>> my_dict = {‘food’ : ‘something that we eat’, ‘car’ : ‘something that we drive’}
>>> my_dict[‘food’]
‘something that we eat’
>>> my_dict[‘car’]
‘something that we drive’
]]>

Python dictionary objects are mutable. That means, once created it can be modified later.

>> my_dict[‘food’] = ‘pizza’
>>> my_dict
{‘food’ : ‘pizza’, ‘car’ : ‘something that we drive’}
]]>

There are various ways in which the mutability of dictionaries in Python is useful, let’s look at the following scenario

>> his_dict = my_dict
>>> his_dict
{‘food’ : ‘pizza’, ‘car’ : ‘something that we drive’}
>>> his_dict[‘food’] = ‘cookie’
>>> his_dict
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’}
>>> my_dict
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’}
]]>

As can be seen, changing the value of his_dict has changed the value of my_dict too. This phenomenon can be extended to n number of assigned dictionaries

>> her_dict = his_dict
>>> her_dict[‘party_place’] = ‘howzzat’
>>> her_dict
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’, ‘party_place’: ‘howzzat’}
>>> his_dict
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’, ‘party_place’: ‘howzzat’}
>>> my_dict
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’, ‘party_place’: ‘howzzat’}
]]>

Now this behavior is exploited in various situations, but there can be cases when this behavior is not desired. In those cases, we need to use the copy method. The copy method creates a shallow copy of the dictionary.

>> her_copy = his_dict.copy()
>>> her_copy
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’, ‘party_place’: ‘howzzat’}
>>> her_copy[‘food’] = ‘Indian’
>>> her_copy
{‘food’: ‘Indian’, ‘car’: ‘something that we drive’, ‘party_place’: ‘howzzat’}
>>> his_dict
{‘food’: ‘cookie’, ‘car’: ‘something that we drive’, ‘party_place’: ‘howzzat’}
>>>
]]>

This feature of Python was quite unaware to me, unless i encountered a bug in my application and the tracking lead me to this !!

Using Appstats in Glashammer

If you are using Google App Engine for developing and deploying your web application written in Python, chances are high that you must be using AppStats for measuring the performance of your application. Well, if you haven’t its the right time for you to start using it.
The details about how to use AppStats with Google App Engine in WebApp framework and the Django framework are available at the official app engine documentation.

Here, i will tell you how to use AppStats in your Glashammer application.

AppStats is a middleware, so it stands somewhere between your client and the app engine server. It measures each request coming and its response generated and provides valuable data for developers to tune up their app.

So here are the steps

  1. Setup your application
  2. Most probably, you might be performing setup of your application in the main.py. You need to add the middleware to the application. For this first import the appstats_wsgi_middleware class.
    <![CDATA[
    from google.appengine.ext.appstats.recording import appstats_wsgi_middlewareNext add the middleware where you are setting your application

    app.add_middleware(appstats_wsgi_middleware)
  3. Create a config file
  4. The config file is a file named appengine_config.py located at the application root level. You can get a sample file from the location

    google/appengine/ext/appstatus

    in your SDK, and copy that file as appengine_config.py and save it in application root.

  5. Adjust URL mappings in app.yaml
  6. After you are done with these two you now need to map the URLs to the views of appstats view handler. In order to do this, modify your app.yaml file by adding the following line <![CDATA[- url: /stats.* script: $PYTHON_LIB/google/appengine/ext/appstats/ui.pyIf you have any mapping as /.*, make sure that you add the line above that mappings.

That’s it. You are done. Now when you run your application, you will see appstats details in the terminal log. You can also view the details for all prev records at /stats.

AtoZ-Help : version 0.2 released

The version 0.2 of AtoZ-help Framework is available for download and testing purposes. AtoZ-help is a framework written in Pure Python and runs on Google AppEngine for creating feature rich help pages online. The help pages can be integrated with your existing website or can be released as an independent site.

Check out the source code at : http://code.google.com/p/atoz-help/
Got a buF? Report it at : http://code.google.com/p/atoz-help/issues/list
The latest version is available for download. Download it here

AtoZ Help – An Engine for creating online help section on AppEngine

So, this Christmas, i had nothing better to do than sit and do this project named AtoZ-help.

The project aims at creating an engine that can create and manage the help sections of a website in a very efficient and hassles-less manner.

Website : http://atoz-help.appspot.com
Repository: http://atoz-help.googlecode.com

The project is under rapid development and this release has been completed in 2 days (starting from scratch), and although serious issues are not quite expected, there needs a lot of tuning, refining and features to be added.

If you have a bug report/ feature request. kindly so in the issues list here. Please search the issue list to avoid duplicacy.

As of now, it is not recommended to use this project for business purposes just because the project is evolving very fast, and so some features might get changed or discontinued. It is however, good if you are a developer and want to try things out.

I will be releasing a complete tutorial and a much convenient template for AtoZ, but they are not in my priority list. The roadmap for this project is listed at the RoadMap Wiki Page.