equal
deleted
inserted
replaced
25 import cPickle |
25 import cPickle |
26 import operator |
26 import operator |
27 import sys |
27 import sys |
28 |
28 |
29 import interactive |
29 import interactive |
|
30 |
|
31 |
|
32 def dateFetch(queryGen, last=None, batchSize=100): |
|
33 """Iterator that yields an entity in batches. |
|
34 |
|
35 Args: |
|
36 queryGen: should return a Query object |
|
37 last: used to .filter() for last_modified_on |
|
38 batchSize: how many entities to retrieve in one datastore call |
|
39 |
|
40 Retrieved from http://tinyurl.com/d887ll (AppEngine cookbook). |
|
41 """ |
|
42 |
|
43 from google.appengine.ext import db |
|
44 |
|
45 # AppEngine will not fetch more than 1000 results |
|
46 batchSize = min(batchSize,1000) |
|
47 |
|
48 query = None |
|
49 done = False |
|
50 count = 0 |
|
51 |
|
52 while not done: |
|
53 print count |
|
54 query = queryGen() |
|
55 query.order('last_modified_on') |
|
56 if last: |
|
57 query.filter("last_modified_on > ", last) |
|
58 results = query.fetch(batchSize) |
|
59 for result in results: |
|
60 count += 1 |
|
61 yield result |
|
62 if batchSize > len(results): |
|
63 done = True |
|
64 else: |
|
65 last = results[-1].last_modified_on |
30 |
66 |
31 |
67 |
32 def addKey(target, fieldname): |
68 def addKey(target, fieldname): |
33 """Adds the key of the specified field. |
69 """Adds the key of the specified field. |
34 """ |
70 """ |