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

AntiCompositeNumber / AntiCompositeBot / 8384674972

22 Mar 2024 02:34AM UTC coverage: 48.048%. Remained the same
8384674972

Pull #314

github

AntiCompositeNumber
Relicense from Apache-2.0 to GPL-3.0-or-later
Pull Request #314: Update LICENSE

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/uncat.py
1
#!/usr/bin/env python3
2
# coding: utf-8
3
# SPDX-License-Identifier: GPL-3.0-or-later
4
# Copyright 2021 AntiCompositeNumber
5

6
import toolforge  # type: ignore
×
7
import acnutils
×
8
import datetime
×
9

10
__version__ = "0.3"
×
11

12
logger = acnutils.getInitLogger("uncat", level="VERBOSE")
×
13

14

15
def run_query():
×
16
    query = """
×
17
SELECT page_title, COUNT(*)
18
FROM page
19
JOIN templatelinks ON tl_from = page_id
20
JOIN linktarget ON lt_id = tl_target_id
21
JOIN globalimagelinks ON page_title = gil_to
22
WHERE
23
    lt_title = "Uncategorized"
24
    AND lt_namespace = 10
25
    AND page_namespace = 6
26
GROUP BY page_id
27
ORDER BY COUNT(*) DESC
28
"""
29
    conn = toolforge.connect("commonswiki_p")
×
30
    with conn.cursor() as cur:
×
31
        cur.execute(query)
×
32
        data = cur.fetchall()
×
33
    for file, count in data:
×
34
        if count >= 20:
×
35
            yield str(file, encoding="utf-8"), count
×
36

37

38
def make_table(data):
×
39
    out = f"""
×
40
<!DOCTYPE html>
41
<html>
42
<body>
43
<p>Last updated {datetime.datetime.now().ctime()}</p>
44
<table>
45
<tr><th>File</th><th>Links</th></tr>
46
"""
47
    out += "\n".join(
×
48
        f"<tr><td><a href='https://commons.wikimedia.org/wiki/File:{file}'>"
49
        f"File:{file}</a></td><td>{count}</td></tr>"
50
        for file, count in data
51
    )
52
    out += "</table></body></html>"
×
53
    return out
×
54

55

56
def save_page(table):
×
57
    if acnutils.on_toolforge():
×
58
        filename = "/data/project/anticompositebot/www/static/uncat.html"
×
59
    else:
60
        filename = "uncat.html"
×
61
    with open(filename, "w") as f:
×
62
        f.write(table)
×
63

64

65
def main():
×
66
    logger.info("Starting up")
×
67
    data = run_query()
×
68
    table = make_table(data)
×
69
    logger.info("Query complete, saving page")
×
70
    save_page(table)
×
71

72

73
if __name__ == "__main__":
×
74
    try:
×
75
        main()
×
76
    except Exception as err:
×
77
        logger.exception(err)
×
78
        raise
×
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