Exemplo n.º 1
0
 def get(cls, owner_key):
   books_owned = memcache.get(cls.key(owner_key))
   if not books_owned:
     books_owned = []
     for book_key in Book.owned_by(owner_key):
         books_owned.append(str(book_key))
     memcache.set(cls.key(owner_key), books_owned)
   return books_owned
Exemplo n.º 2
0
 def get():
     feed = memcache.get(feed_key)
     if not feed:
         new_book_keys = [str(key_obj) for key_obj in Book.new_books()]
         new_books = [CachedBook.get(book_id) for book_id in new_book_keys]
         template_values = {
           'root': "http://whotookmybook.appspot.com/",
           'books': new_books,
           'updated_feed': datetime.now().isoformat() + 'Z'
         }
         path = os.path.join(os.path.dirname(__file__), 'whats_new.template')
         feed = template.render(path, template_values)
         memcache.set(feed_key, feed)
     return feed
Exemplo n.º 3
0
# hardcode created date to 10-May-2009 for all books without a  created date

from google.appengine.ext import db
from wtmb import Book
import datetime

print 'starting'
all_books = db.GqlQuery("SELECT __key__ from Book LIMIT 1000").fetch(1000)
print 'all books count = ' + str(len(all_books))
books_with_cdate = db.GqlQuery("SELECT __key__ from Book WHERE created_date > DATE(2009, 5, 14) LIMIT 1000").fetch(1000)
print 'new books count = ' + str(len(books_with_cdate))
for key in books_with_cdate:
    all_books.remove(key)
print 'old books count = ' + str(len(all_books))
for key in all_books:
    oldBook = Book.get(key)
    print "<br>updating date for " + oldBook.title
    oldBook.created_date = datetime.datetime(2009, 5, 10)
    oldBook.put()
Exemplo n.º 4
0
 def get(cls, book_id):
     book = memcache.get(cls.key(book_id))
     if not book:
       book = Book.get(book_id).to_hash()
       memcache.set(cls.key(book_id), book)
     return book
Exemplo n.º 5
0
 def get(cls, user_key):
   books = memcache.get(cls.key(user_key))
   if not books:
     books = set(str(book_key) for book_key in Book.borrowed_by(user_key))
     memcache.set(cls.key(user_key), books)
   return books
Exemplo n.º 6
0
#800 Literature
#900 History, geography, Biography
# 823 = fiction

def resolve(dewey):
    if dewey is None:
        return "unclassified" 
    num = float(dewey)
    if num - 823 < 1:
        return "fiction"
    if num < 100:
        return "computers"
    return "others"

d = {}
for bk in Book.all():
    category = resolve(bk.dewey)
    if None == d.get(category):
        d[category] = []
    titles = memcache.get(category)        
    if not titles:
        titles = []
        memcache.set(category, titles)
    d[category].append(bk.title)
    titles.append(bk.key())
    
for key in d.keys():
    print "CATEGORY"
    print key
    for t in d[key]:
        print unicode(t).encode("utf-8") 
Exemplo n.º 7
0
from google.appengine.api.labs import taskqueue
from wtmb import Book

keycsv = ""
keylist = []
batches = []

for bk_key in Book.all_books():
    keylist.append(str(bk_key))

for i in range(0, len(keylist), 100):
    batches.append(keylist[i:i+100])

for batch in batches:
    taskqueue.add(url='/indexbook', params={'keycsv': ','.join(batch)})