-
Notifications
You must be signed in to change notification settings - Fork 16
/
manage.py
48 lines (30 loc) · 1.03 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sqlalchemy as sa
import prettytable
from flask.ext.script import Manager
from iatilib.frontend import create_app, db
from iatilib import magic_numbers
from iatilib.model import IndexedResource, RawXmlBlob
manager = Manager(create_app())
def qtable(itr, headers=None):
if headers is None:
headers = next(itr)
tbl = prettytable.PrettyTable(headers)
for row in itr:
tbl.add_row(row)
return tbl
@manager.command
def status():
print "Database: %s" % manager.app.config["SQLALCHEMY_DATABASE_URI"]
print
resource_status = db.session.query(
IndexedResource.state, sa.func.count()).group_by(IndexedResource.state)
print "Download"
print qtable(
((magic_numbers.label[n], c) for n, c in resource_status),
["state", "no of urls"])
print "Parsing"
parse_status = db.session.query(
RawXmlBlob.parsed, sa.func.count()).group_by(RawXmlBlob.parsed)
print qtable(parse_status, ["status", "no of blobs"])
if __name__ == "__main__":
manager.run()