From ba353c71d4f1058841299382c57ae15942f35874 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Sun, 22 Jan 2012 14:03:56 +0000 Subject: [PATCH] Latest 10 apps (not entirely correct yet, missing some data) --- common.py | 18 ++++++++++++++++++ updatestats.py | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/common.py b/common.py index d4552375..e651e542 100644 --- a/common.py +++ b/common.py @@ -20,6 +20,7 @@ import glob, os, sys, re import shutil import subprocess import time +import operator def getvcs(vcstype, remote, local): if vcstype == 'git': @@ -821,3 +822,20 @@ class KnownApks: if apkname in self.apks: return self.apks[apkname] return None + + def getlatest(self, num): + apps = {} + for apk, app in self.apks.iteritems(): + appid, added = app + if added: + if appid in apps: + if apps[appid] > added: + apps[appid] = added + else: + apps[appid] = added + sortedapps = sorted(apps.iteritems(), key=operator.itemgetter(1))[-num:] + lst = [] + for app, added in sortedapps: + lst.append(app) + return lst + diff --git a/updatestats.py b/updatestats.py index 4c7b1c57..61feb845 100755 --- a/updatestats.py +++ b/updatestats.py @@ -121,6 +121,7 @@ for logfile in glob.glob(os.path.join(logsdir,'access-*.log')): if not apkname in unknownapks: unknownapks.append(apkname) +# Calculate and write stats for total downloads... f = open('stats/total_downloads_app.txt', 'w') lst = [] alldownloads = 0 @@ -133,6 +134,13 @@ for line in sorted(lst): f.write(line + '\n') f.close() +# Write list of latest apps added to the repo... +latest = knownapks.getlatest(10) +f = open('stats/latestapps.txt', 'w') +for app in latest: + f.write(app + '\n') +f.close() + if len(unknownapks) > 0: print '\nUnknown apks:' for apk in unknownapks: