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

AntiCompositeNumber / AntiCompositeBot / 15325491370

29 May 2025 01:54PM UTC coverage: 46.294%. Remained the same
15325491370

push

github

AntiCompositeNumber
asnblock: handle ipblocks deprecation

210 of 419 branches covered (50.12%)

Branch coverage included in aggregate %.

652 of 1443 relevant lines covered (45.18%)

0.45 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.4"
×
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
    bl_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 block_target ON user_id = bt_user
60
LEFT JOIN block ON bl_target = bt_id AND bl_sitewide = 1
61
WHERE ct_tag_id in (577, 618) -- RedWarn, Ultraviolet
62
GROUP BY actor_name
63
ORDER BY user_registration DESC
64
"""
65
    conn = toolforge.connect("enwiki_p")
×
66
    with conn.cursor() as cur:
×
67
        cur.execute(query)
×
68
        data = cur.fetchall()
×
69
    for line in data:
×
70
        yield Row(
×
71
            username=f"[[User:{str(line[0], encoding='utf-8')}]]",
72
            edit_count=line[1],
73
            registration_date=datetime.datetime.strptime(
74
                str(line[2], encoding="utf-8"), "%Y%m%d%H%M%S"
75
            ),
76
            ext_conf=bool(line[3]),
77
            redwarn_edits=line[4],
78
            redwarn_pct=line[5],
79
            blocked=bool(line[6]),
80
        )
81

82

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

93

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

108

109
if __name__ == "__main__":
×
110
    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