• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AntiCompositeNumber / AntiCompositeBot / 8384694893

22 Mar 2024 02:39AM UTC coverage: 48.048%. Remained the same
8384694893

push

github

AntiCompositeNumber
Relicense from Apache-2.0 to GPL-3.0-or-later

296 of 554 branches covered (53.43%)

Branch coverage included in aggregate %.

664 of 1444 relevant lines covered (45.98%)

0.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/redwarnusers.py
1
#!/usr/bin/env python3
2
# coding: utf-8
3
# SPDX-License-Identifier: GPL-3.0-or-later
4
# Copyright 2020 AntiCompositeNumber
5

6
import pywikibot  # type: ignore
×
7
import toolforge
×
8
import datetime
×
9
import itertools
×
10
from typing import NamedTuple
×
11
import acnutils as utils
×
12

13
site = pywikibot.Site("en", "wikipedia")
×
14
__version__ = "1.3"
×
15

16

17
class Row(NamedTuple):
×
18
    username: str
×
19
    edit_count: int
×
20
    registration_date: datetime.datetime
×
21
    ext_conf: bool
×
22
    redwarn_edits: int
×
23
    redwarn_pct: float
×
24
    blocked: bool
×
25

26
    def tablerow(self):
×
27
        return "|" + "||".join(str(val) for val in self)
×
28

29
    @staticmethod
×
30
    def header():
×
31
        return "!" + "!!".join(
×
32
            [
33
                "Username",
34
                "Edit count",
35
                "Registration date",
36
                "30/500",
37
                "RedWarn edits",
38
                "RedWarn %",
39
                "Blocked",
40
            ]
41
        )
42

43

44
def run_query():
×
45
    query = """
×
46
SELECT
47
    actor_name as `username`,
48
    user_editcount as `edit_count`,
49
    user_registration as `registration_date`,
50
    NOT(ug_group IS NULL)  as `ext_conf`,
51
    COUNT(*) as `redwarn_edits`,
52
    COUNT(*)/user_editcount*100 as `redwarn_pct`,
53
    ipb_sitewide as `blocked`
54
FROM revision_userindex
55
JOIN change_tag ON ct_rev_id = rev_id
56
JOIN actor_revision ON rev_actor = actor_id
57
JOIN `user` ON actor_user = user_id
58
LEFT JOIN user_groups ON ug_user = user_id AND ug_group = "extendedconfirmed"
59
LEFT JOIN ipblocks ON user_id = ipb_user
60
WHERE ct_tag_id in (577, 618) -- RedWarn, Ultraviolet
61
GROUP BY actor_name
62
ORDER BY user_registration DESC
63
"""
64
    conn = toolforge.connect("enwiki_p")
×
65
    with conn.cursor() as cur:
×
66
        cur.execute(query)
×
67
        data = cur.fetchall()
×
68
    for line in data:
×
69
        yield Row(
×
70
            username=f"[[User:{str(line[0], encoding='utf-8')}]]",
71
            edit_count=line[1],
72
            registration_date=datetime.datetime.strptime(
73
                str(line[2], encoding="utf-8"), "%Y%m%d%H%M%S"
74
            ),
75
            ext_conf=bool(line[3]),
76
            redwarn_edits=line[4],
77
            redwarn_pct=line[5],
78
            blocked=bool(line[6]),
79
        )
80

81

82
def make_table(data):
×
83
    info = f"Last updated by AntiCompositeBot at {datetime.datetime.now()}\n\n"
×
84
    return info + "\n|-\n".join(
×
85
        itertools.chain(
86
            ['{| class="wikitable sortable"', Row.header()],
87
            [row.tablerow() for row in data],
88
            ["|}"],
89
        )
90
    )
91

92

93
def main():
×
94
    utils.check_runpage(site, "redwarnusers")
×
95
    data = run_query()
×
96
    table = make_table(data)
×
97
    page = pywikibot.Page(site, "User:AntiCompositeBot/RedWarn users")
×
98
    utils.save_page(
×
99
        text=table,
100
        page=page,
101
        summary=f"Updating statistics (RWU {__version__}) (Bot)",
102
        mode="replace",
103
        bot=False,
104
        minor=True,
105
    )
106

107

108
if __name__ == "__main__":
×
109
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc