Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_top10(app_id):
- ts = get_all(app_id)
- cities_str = ""
- cities = {}
- for t in ts:
- city = t.client_city.lower()
- if city != "":
- if "@%s@"%city not in cities_str:
- cities_str += "@%s@"%city
- cities[city] = 1
- else:
- cities[city] += 1
- from operator import itemgetter
- items = cities.items()
- items.sort(key = itemgetter(1), reverse=True)
- return items[:10]
- def get_all(app_id):
- last = None
- all_ts = []
- while True:
- ts = Transaction.all().filter("application_id =",app_id).order("__key__")
- if last is not None:
- ts = ts.filter("__key__ >",last.key())
- ts = ts.fetch(400)
- last = ts[-1]
- all_ts += ts
- if len(ts) != 400:
- print "FINISH"
- return all_ts
Add Comment
Please, Sign In to add comment