# 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
        key = self.request.get('site_key')
        batch_size = 10
        query = models.Keyword.all(keys_only=True).filter('site = ', db.Key(key))
        count = query.count()
        kw_keys = query.fetch(batch_size)
        for kw_key in kw_keys:
            models.Keyword.cascade_delete(kw_key)
        db.delete(kw_keys)
        if count > batch_size:
            queue = taskqueue.Queue("default")
            task = taskqueue.Task(url = '/tasks/delete/keywords', params = {'site_key' : key })
            queue.add(task)

# Cascade delete on KeywordSearchEngine when deleting a Keyword
class DeleteKeywordSearchEnginesHandler(webapp.RequestHandler):
    def post(self, *ar, **kw):
        key = self.request.get('keyword_key')
        batch_size = 10
        query = models.KeywordSearchEngine.all(keys_only = True).filter('keyword = ', db.Key(key))
        count = query.count()
        kw_se_keys = query.fetch(batch_size)
        for kw_se_key in kw_se_keys:
            models.KeywordSearchEngine.cascade_delete(kw_se_key)
        db.delete(kw_se_keys)
        if count > batch_size:
            queue = taskqueue.Queue("default")
            task = taskqueue.Task(url = '/task/delete/keyword_search_engines', params = {'keyword_key' : key})
            queue.add(task)

# Cascade delete on KeywordRankLog when deleting a Keyword Search Engine

# 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

        key = self.request.get('site_key')
        batch_size = 10
        query = models.Keyword.all(keys_only=True).filter('site = ', db.Key(key))
        count = query.count()
        kw_keys = query.fetch(batch_size)
        for kw_key in kw_keys:
            models.Keyword.cascade_delete(kw_key)
        db.delete(kw_keys)
        if count > batch_size:
            queue = taskqueue.Queue("default")
            task = taskqueue.Task(url = '/tasks/delete/keywords', params = {'site_key' : key })
            queue.add(task)

# Cascade delete on KeywordSearchEngine when deleting a Keyword
class DeleteKeywordSearchEnginesHandler(webapp.RequestHandler):
    def post(self, *ar, **kw):
        key = self.request.get('keyword_key')
        batch_size = 10
        query = models.KeywordSearchEngine.all(keys_only = True).filter('keyword = ', db.Key(key))
        count = query.count()
        kw_se_keys = query.fetch(batch_size)
        for kw_se_key in kw_se_keys:
            models.KeywordSearchEngine.cascade_delete(kw_se_key)
        db.delete(kw_se_keys)
        if count > batch_size:
            queue = taskqueue.Queue("default")
            task = taskqueue.Task(url = '/task/delete/keyword_search_engines', params = {'keyword_key' : key})
            queue.add(task)

# Cascade delete on KeywordRankLog when deleting a Keyword Search Engine

class DeleteKeywordRankLogsHandler(webapp.RequestHandler):