Simori.com

Where Art meets Science and falls in love.

Archive for the ‘Projects’ Category

As we know Brightkite is a location based social network where users can checkin into a location and make posts. I always had a thought on how we can acheive this functionality using django framework. Last week I started off this project with an eye on contributing it to Pinax project. I talked to Jtauber and I was lucky enough to get a chance before the feature freeze of pinax.

To start this project we need to recollect the basic requirements. 
1. Registration for users. This can be acheived by django registration 
2. Search for a location and get its proper place name, latitude and longitude data 
3. Ability to checkin to that location. In simple words store the userid, place name, latitude, longitude and datetime of the checkin.

Implementation:

I am not going to start a brand new django project and build it upon it. Instead I recommend you to check out pinax project source code. Or you start a new project and add django-registration app to INSTALLED_APPS and set the urls. There are a bunch of tutorials on web on how to do that. Now we can create a new application called “locations”.

#!/bin/sh
$ python manage.py startapp locations

You now have the basic skeleton of the location application. Lets start creating the model “Location”. As discussed in the basic requirements above.

from django.db import models
from django.contrib.auth.models import User

class Location(models.Model):
    user = models.ForeignKey(User)
    time_checkin = models.DateTimeField()
    place = models.CharField(max_length=100)
    latitude = models.FloatField()
    longitude = models.FloatField()

    class Meta:
        ordering            = (‘-time_checkin’,)
        get_latest_by       = ‘time_checkin’

The model is pretty self explanatory. It has a foriegn key to User, so that each user can have his own checkins. After the model is created our objective is to search for a location and get the geo data for that location. For this we will take help of GeoPy a geocoding toolbox for python. We can query web services like Yahoo, Google, Geocoders to get geo data for a location.

We create an entry in urls.py for this lcoations search.

urlpatterns = patterns(,
    (r’new/$’, ‘locations.views.new’),
)

To create a form, just create a file forms.py in locations and

class LocationForm(forms.Form):
         place = forms.CharField()

This means when somebody tries to access the url ‘/new/’ the request is routed to the view ‘new’. Lets create a definition for the ‘new’. Open view.py

@login_required
def new(request):
    if request.method == ‘POST’:
         location_form = LocationForm(request.POST)
         if location_form.is_valid():
               y = geocoders.Yahoo(‘yahoo_map_api’)
               p = location_form.cleaned_data[‘place’]
               place, (lat, lng) = y.geocode(p)
               location = {‘place’: place, ‘latitude’: lat, ‘longitude’: lng}
               checkin_form = CheckinForm()
               return render_to_response(“locations/checkin.html”, {“location”: location,
        “checkin_form”: checkin_form})
    else:
         location_form = LocationForm()
         return render_to_response(“locations/new.html”, {“location_form”: location_form})

First of all I am protecting this view, so that only logged in users(@login_required) will be able to search locations. Next if the request of the type POST only the loop gets executed. If some tries to access with a GET/anything the else part will be executed there by rendering an empty form again. I’m extracting the data from request.POST and putting in location_form variable.

Next we import geocoders from geopy and then instantiate its Yahoo class. We can use Google or Geocoders as well, but I chose Yahoo. Pass your YAHOO_API_KEY as argument to Yahoo class. I am extracting the form data into a variable ‘p’ and then performing a geocode using the yahoo object. A request is made to Yahoo Geocoding service and geo data is returned. I created 3 variables place, lat & lng which contains place name, latitude & longitude. I pass all these variables into a dictionary and pass them to a template(checkin.html). In this process I am also creating a blank checkin_form which is also passed to the tempalte. I will discuss those details in the next part. You can check out the checkin.html which is pretty simple. It contains just a form.

More is part-2…

 

I am disabling comments for this posts as I already wrote this post in my personal blog. Head over to my blog to share some feedback with me.

Yahoo’s new API BOSS

So this will be my first post on simori. I had been observing this site for quite sometime and found very useful information. In case you have n’t got me yet, I am yashh. So here I am to add a few tidbits of mine.

For about an year I was wondering if google provided any API’s for the 3rd party players to utilize google search. In fact google has supported the Soap API for few years. The Soap API provided a lot of freedom for the developers to utilize the Google search remotely. The main advantage was that we could hide the backend queries from the presentation. In simple terms the results do not have the brand name google. Although google limited the queries to 1000 per day it was worth while. As of December 5, 2006, google is no longer issuing any new API keys to the developers and instead started promoting the AJAX search APIwhich does not give the developers the freedom to manipulate the presentation of search results.

Now it is Yahoo which has come the BOSS api which is used to launch search products. The first obvious question is how is it different from the previous Yahoo API.

  1. Unlimited queries per day.
  2. No restriction on presentation.
  3. Search Web, Images & News.
  4. Get Spelling sugestions.
  5. Reorder the search results & many other.

So let’s get started with a small exercise to know how Y! BOSS API works. Sign up for an BOSS Application ID. For this excercise I am using Y! BOSS mashup python library. You can download the library here. Unzip the library. Open config.json file in code editor and edit the application id with yours. Fire up your terminal (if on mac or command prompt on windows).

#!/bin/sh

$ cd Desktop/boss_mashup_framework_0.1
$ export PYTHONPATH=$PYTHONPATH:$PWD
$ python
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
>>> from yos.boss import ysearch
>>> data = ysearch.search(‘python’, count=10)
>>> data
# You find all the top search results for the keyword ‘python’
in a dictionary format. Voila you are able to search the web from your terminal.

Will Larson developed a python wrapper for the Yahoo BOSS boss_array.py. This eases our development by a large amount. Here is a good tutorial using the wrapper.

Conclusion: Yahoo BOSS api is certainly a boon for third party apps and developers. All it needs to improve is the speed and accuracy. It will take some time for the developers to accustom to it and develop new API’s over BOSS.

I am disabling comments for this posts as I already wrote this post in my personal blog. Head over to my blog to share some feedback with me.

What is Android?

What is Android?

What is Android?

Android is a software stack for mobile devices that includes an operating system, middleware and key applications.


The Amazing Features Of Android:

1. Application Framework: Which enables the reuse and replacements of component.

2. The Usage of Dalvi Virtual Machine: It is optimized for low memory requirements, and is designed to allow multiple VM instances to run at once, relying on the underlying operating system for process isolation, memory management and threading support. Dalvik is often referred to as a Java Virtual Machine, but this is not strictly accurate, as the bytecodeJava bytecode. Instead, a tool named dx, included in the Android SDK, transforms the Java Class files of Java classes compiled by a regular Java compiler into another class file format (the .dex format).

3. Integrated browser: Which is based on the open Source WebKit Engine.

4. Optimized graphics: powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)

You can get more information about Optimized Graphics

5. SQLite: Which is mainly for structure Data Storage.

SQLite is a mostly ACID-compliant relational database management system contained in a relatively small (~500kb) C programming library.

Unlike client-server database management systems, the SQLite engine is not a standalone process with which the program communicates. Instead, the SQLite library is linked in and thus becomes an integral part of the program. The program uses SQLite’s functionality through simple function calls, which reduces latency in database access as function calls are more efficient than inter-process communication. The entire database (definitions, tables, indices, and the data itself) is stored as a single cross-platform file on a host machine. This simple design is achieved by locking the entire database file at the beginning of a transaction.

You can get More Information on SQLite about the Features, Adoptions and More.

6. Media support: Android will support advanced audio/video/still media formats such as MPEG-4, H.264, MP3, and AAC, AMR, JPEG, PNG, GIF.

Ref: http://en.wikipedia.org/wiki/Android_(mobile_phone_platform)

7. GSM Telephony: Which is a hardware dependent.

What is GSM?

GSM is a Global System For Mobile Network. GSM uses a variation of Time Division Multiple Access (TDMA) and is the most widely used of the three digital wireless telephone technologies (TDMA, GSM, and CDMA). GSM digitizes and compresses data, then sends it down a channel with two other streams of user data, each in its own time slot. It operates at either the 900 MHz or 1,800 MHz frequency band.

REF: http://www.tech-faq.com/gsm.shtml

8. Hardware Support: Bluetooth, EDGE, 3G, WiFi,Camera, GPS, compass, and accelerometer

Architecture of Android:

Source: code.google.com/android/

  • 2 Comments
  • Filed under: Projects