-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstatus.cgi
More file actions
executable file
·73 lines (57 loc) · 1.39 KB
/
status.cgi
File metadata and controls
executable file
·73 lines (57 loc) · 1.39 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
###############
# IMPORTS
import cgitb; cgitb.enable() # for debugging
#import cgi # for getting query keys/values
from ClientDB import DB
db = DB('reddit.db')
import_failed = True
try:
import json
import_failed = False
except ImportError: pass
if import_failed:
# Older versions of python don't work with 'json', so we use simplejson
try:
import simplejson as json
import_failed = False
except ImportError: pass
if import_failed:
# If simplejson isn't found, we must be on Python 2.5 or below
try:
from JSON import json
except ImportError:
print '\un Unable to load JSON library! exiting'
exit(1)
######################
# METHODS
def start():
print to_json()
def get_count(table):
return db.select("count(*)", table)[0][0]
def count_subs_db():
return db.select("count(distinct subreddit)", "Posts")[0][0]
def count_subs_txt():
f = open('subs.txt', 'r')
subs = f.read().split('\n')
f.close()
while subs.count("") > 0:
subs.remove("")
return len(subs)
def to_json():
dict = {
'status' : {
'posts' : get_count('Posts'),
'comments' : get_count('Comments'),
'albums' : get_count('Albums'),
'images' : get_count('Images'),
'subreddits' : count_subs_txt(),
'subreddits_pending' : count_subs_txt()
},
}
return json.dumps(dict)
if __name__ == '__main__':
print "Content-Type: application/json"
print ""
start()
print '\n\n'