# Path: ranking_engine/models.py
# def serialize_entities(models):
# def deserialize_entities(data):
#     def get_cache_namespace(self):
#     def update_cache_namespace(self):
#     def _get_cache_namespace_key(self):
#     def _init_cache_namespace(self):
#     def get_cache_parent(self):
#     def instance_cache_key_by_user(self):
#     def cache_key_by_user(cls, user):
#     def delete(self):
#     def put(self):
#     def cascade_delete(cls, key):
#     def remaining_sites(self):
#     def remaining_keywords(self):
#     def sites(self):
#     def get_user_account(cls, user):
#     def get_cache_parent(self):
#     def put(self):
#     def delete(self):
#     def cascade_delete(cls, key):
#     def keywords(self):
#     def report_url(self):
#     def delete_url(self):
#     def get_cache_parent(self):
#     def delete(self):
#     def put(self):
#     def delete_url(self):
#     def graph_url(self):
#     def cascade_delete(cls, key):
#     def search_engines(self):
#     def get_cache_parent(self):
#     def delete(self):
#     def put(self):
#     def cascade_delete(cls, key):
#     def search_engine(self):
#     def last_log(self):
#     def full_log(self):
#     def variation(self):
#     def enqueue_update_rank_task(self):
#     def enqueue_update_rank_task_key(cls, key):
#     def plot_data(self):
#     def get_cache_parent(self):
#     def delete(self):
#     def put(self):
# class BaseModel(db.Model):
# class Account(BaseModel):
# class Site(BaseModel):
# class Keyword(BaseModel):
# class KeywordSearchEngine(BaseModel):
# class KeywordRankLog(BaseModel):
# 
# Path: ranking_engine/ranking.py
# def get_ranking(url, keyword, server):
# def _google_ajax_api_ranking(url, keyword, server_info):
# def _bing_api_ranking(url, keyword, server_info):


from google.appengine.ext import webapp
from google.appengine.api.labs import taskqueue
from google.appengine.ext import db
from ranking_engine import models
from ranking_engine import ranking
import datetime
import time
import logging
import config
        entities = query.fetch(100)
        if entities:
            default_queue = taskqueue.Queue("default")
            se_calls_queue = taskqueue.Queue("search-engine-calls")
            for key in entities:
                task = taskqueue.Task(url = '/tasks/update_keyword_se_rank', params = {'key': key})
                se_calls_queue.add(task)
                last_key = key
            task = taskqueue.Task(url = '/tasks/update_ranks',
                                  params = {'time': time, 'last_key' : last_key})
            default_queue.add(task)


class UpdateKeywordSearchEngineRanksHandler(webapp.RequestHandler):

    def update_trx(self, kw_se, result):
        # Insert KeywordRankLog
        rankLog = models.KeywordRankLog(parent = kw_se)
        rankLog.keyword_se = kw_se
        if result and result.get('rank'):
            rankLog.rank = result.get('rank')
            rankLog.url = result.get('url')
            rankLog.total = result.get('total')
        rankLog.put()

        # Update kw_se.last_update
        kw_se.last_update = datetime.datetime.today()
        kw_se.put()
        return


# Path: ranking_engine/models.py
# def serialize_entities(models):
# def deserialize_entities(data):
#     def get_cache_namespace(self):
#     def update_cache_namespace(self):
#     def _get_cache_namespace_key(self):
#     def _init_cache_namespace(self):
#     def get_cache_parent(self):
#     def instance_cache_key_by_user(self):
#     def cache_key_by_user(cls, user):
#     def delete(self):
#     def put(self):
#     def cascade_delete(cls, key):
#     def remaining_sites(self):
#     def remaining_keywords(self):
#     def sites(self):
#     def get_user_account(cls, user):
#     def get_cache_parent(self):
#     def put(self):
#     def delete(self):
#     def cascade_delete(cls, key):
#     def keywords(self):
#     def report_url(self):
#     def delete_url(self):
#     def get_cache_parent(self):
#     def delete(self):
#     def put(self):
#     def delete_url(self):
#     def graph_url(self):
#     def cascade_delete(cls, key):
#     def search_engines(self):
#     def get_cache_parent(self):
#     def delete(self):
#     def put(self):
#     def cascade_delete(cls, key):
#     def search_engine(self):
#     def last_log(self):
#     def full_log(self):
#     def variation(self):
#     def enqueue_update_rank_task(self):
#     def enqueue_update_rank_task_key(cls, key):
#     def plot_data(self):
#     def get_cache_parent(self):
#     def delete(self):
#     def put(self):
# class BaseModel(db.Model):
# class Account(BaseModel):
# class Site(BaseModel):
# class Keyword(BaseModel):
# class KeywordSearchEngine(BaseModel):
# class KeywordRankLog(BaseModel):
# 
# Path: ranking_engine/ranking.py
# def get_ranking(url, keyword, server):
# def _google_ajax_api_ranking(url, keyword, server_info):
# def _bing_api_ranking(url, keyword, server_info):


# Path: handlers/tasks.py
from google.appengine.ext import webapp
from google.appengine.api.labs import taskqueue
from google.appengine.ext import db
from ranking_engine import models
from ranking_engine import ranking
import datetime
import time
import logging
import config

        entities = query.fetch(100)
        if entities:
            default_queue = taskqueue.Queue("default")
            se_calls_queue = taskqueue.Queue("search-engine-calls")
            for key in entities:
                task = taskqueue.Task(url = '/tasks/update_keyword_se_rank', params = {'key': key})
                se_calls_queue.add(task)
                last_key = key
            task = taskqueue.Task(url = '/tasks/update_ranks',
                                  params = {'time': time, 'last_key' : last_key})
            default_queue.add(task)


class UpdateKeywordSearchEngineRanksHandler(webapp.RequestHandler):

    def update_trx(self, kw_se, result):
        # Insert KeywordRankLog
        rankLog = models.KeywordRankLog(parent = kw_se)
        rankLog.keyword_se = kw_se
        if result and result.get('rank'):
            rankLog.rank = result.get('rank')
            rankLog.url = result.get('url')
            rankLog.total = result.get('total')
        rankLog.put()

        # Update kw_se.last_update
        kw_se.last_update = datetime.datetime.today()
        kw_se.put()
        return


    def post(self, *ar, **kw):