-
Notifications
You must be signed in to change notification settings - Fork 1
/
flagged_lib.py
60 lines (55 loc) · 2.03 KB
/
flagged_lib.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
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
import time
import datetime
import create_flagged_data
from general_lib import database_name as myDB
def create_lagging_user(db):
"""This functions creates a table with users sorted by unflagged changes.
It will populate replag_users
"""
cursor = db.cursor()
now = datetime.datetime.now()
timestamp = time.mktime(now.timetuple())
#
cursor.execute('drop table if exists %s.replag_users ' % myDB)
query = """
create table %s.replag_users as
select count(*), fp_page_id, fp_stable, rev_id, rev_user,
rev_user_text, rev_timestamp, %s as updated_at
from dewiki_p.flaggedpages fp
inner join dewiki_p.revision r on fp.fp_page_id = r.rev_page
#inner join dewiki_p.page p on p.page_id = fp.fp_page_id
where fp_reviewed=0 and r.rev_id > fp.fp_stable group by fp_page_id, rev_user_text
%s
""" % (myDB, int(timestamp) , create_flagged_data.slow_ok_text[True])
#
#f = open('tmp_mysql.query', 'w'); f.write( query ); f.close()
cursor.execute( query )
cursor.execute( 'commit;' )
def create_never_reviewed(db):
cursor = db.cursor()
now = datetime.datetime.now()
timestamp = time.mktime(now.timetuple())
#
cursor.execute('drop table if exists %s.never_review ' % myDB )
query = """
create table %s.never_review as
select page_title, page_id, rev_user, rev_timestamp,
%s as updated_at
from dewiki_p.page p
inner join dewiki_p.revision r on r.rev_page = p.page_id
#not flagged
where page_id not in (select distinct fp_page_id from dewiki_p.flaggedpages)
#not a redirect
and page_is_redirect = 0
#and page_id not in (select distinct rd_from from dewiki_p.redirect)
#and in article namespace
and page_namespace = 0
group by page_id
order by page_id, rev_timestamp DESC
%s
""" % (myDB, int(timestamp) , create_flagged_data.slow_ok_text[True])
#
#f = open('tmp_mysql.query', 'w'); f.write( query ); f.close()
cursor.execute( query )
cursor.execute( 'commit;' )