-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadminstuff.py
More file actions
38 lines (32 loc) · 1.17 KB
/
adminstuff.py
File metadata and controls
38 lines (32 loc) · 1.17 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
from tsundiary import User, Post, db
from datetime import date, datetime, timedelta
def delete_user(sid):
Post.query.filter_by(user_sid=sid).delete()
User.query.filter_by(sid=sid).delete()
db.session.commit()
def user_from_sid(sid):
return User.query.filter_by(sid=sid).first()
def graph_all_posts():
posts = Post.query.all()
d = min(p.posted_date for p in posts)
while d < date.today():
print("%s, %d" % (d, len([p for p in posts if p.posted_date == d])))
d += timedelta(days=1)
def get_active_users(num_days=7):
users = {}
for p in Post.query.filter(Post.posted_date > date.today() - timedelta(days=num_days)).all():
if p.user_sid not in users:
users[p.user_sid] = 0
users[p.user_sid] += 1
upairs = users.items()
upairs.sort()
upairs.sort(key=lambda x:x[1], reverse=True)
print("users by # posts in last %d days:", users)
for sid,count in upairs:
print("%3d: %s" % (count, sid))
def stalk(sid, depth=1):
entries = user_from_sid(sid).posts.order_by(Post.posted_date.desc()).limit(depth)
for e in entries:
print(e.posted_date)
print(e.content)
print "---"