forked from millayr/cloudant_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_stats.py
executable file
·50 lines (38 loc) · 1.24 KB
/
db_stats.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
49
50
import requests
import json
from cloudant.client import Cloudant
from cloudant.database import CloudantDatabase
import config
def main():
client = Cloudant(config.username, config.password, account=config.account)
client.connect()
dbs = client.all_dbs()
output = []
for db in dbs:
print 'Retrieving stats for {0}...'.format(db)
db = CloudantDatabase(client, db)
print "db: " + json.dumps(db)
output.append(db.doc_count())
print json.dumps(output, indent=4)
print json.dumps(sort(output), indent=4)
client.disconnect()
def sort(array):
less = []
equal = []
greater = []
if len(array) > 1:
pivot = array[0]
for x in array:
if x < pivot:
less.append(x)
if x == pivot:
equal.append(x)
if x > pivot:
greater.append(x)
# Don't forget to return something!
return sort(less)+equal+sort(greater) # Just use the + operator to join lists
# Note that you want equal ^^^^^ not pivot
else: # You need to hande the part at the end of the recursion - when you only have one element in your array, just return the array.
return array
if __name__ == "__main__":
main()