Advertisement
Guest User

Untitled

a guest
Jun 30th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.05 KB | Source Code | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import pywikibot
  5.  
  6. import MySQLdb
  7. conn = MySQLdb.connect(
  8.     read_default_file = "/data/project/sbot/replica.my.cnf",
  9.     host = "commonswiki.labsdb",
  10.     db = "commonswiki_p",
  11. )
  12.  
  13. cursor = conn.cursor()
  14. cursor.execute("""
  15. SELECT REPLACE(page_title, '_', ' ') as tt,
  16.    page_namespace as ns
  17. FROM categorylinks
  18. JOIN page
  19.    ON page_id = cl_from
  20.    AND page_is_redirect = 0
  21.    AND page_id NOT IN ("15708733", "79393705")
  22. JOIN revision
  23.    ON rev_id = page_latest
  24. WHERE cl_to = 'Commons_protected_edit_requests'
  25. ORDER BY rev_timestamp ASC
  26. LIMIT 200;
  27. """)
  28.  
  29. text = '{{Template:Edit request/List/H}}\n'
  30. text += u'=== Commons protected edit requests ===\n'
  31. text += u'[[File:Article-protected.svg|right|60px]]\n'
  32. for tt, ns in cursor.fetchall():
  33.     text += u'* [[:{{subst:ns:%d}}:%s]] - Last edit by [[User:{{REVISIONUSER:{{SUBST:ns:%d}}:%s}}|{{REVISIONUSER:{{SUBST:ns:%d}}:%s}}]] at {{#timel:H:i, d F Y (e)|{{REVISIONTIMESTAMP:{{SUBST:ns:%d}}:%s}}}}\n'  %(ns,tt.decode("utf-8"),ns,tt.decode("utf-8"),ns,tt.decode("utf-8"),ns,tt.decode("utf-8"))
  34.  
  35. cursor.close()
  36.  
  37. cursor = conn.cursor()
  38. cursor.execute("""
  39. SELECT REPLACE(page_title, '_', ' ') as tt,
  40.    page_namespace as ns
  41. FROM categorylinks
  42. JOIN page
  43.    ON page_id = cl_from
  44.    AND page_is_redirect = 0
  45.    AND NOT page_id = 37919039
  46. JOIN revision
  47.    ON rev_id = page_latest
  48. WHERE cl_to = 'Commons_protected_edit_requests_(technical)'
  49. ORDER BY rev_timestamp ASC
  50. LIMIT 200;
  51. """)
  52.  
  53. text += u'\n'
  54. text += u'=== Commons protected edit requests (technical) ===\n'
  55. text += u'[[File:Human-preferences-desktop.svg|right|60px]]\n'
  56. for tt, ns in cursor.fetchall():
  57.     text += u'* [[:{{subst:ns:%d}}:%s]] - Last edit by [[User:{{REVISIONUSER:{{SUBST:ns:%d}}:%s}}|{{REVISIONUSER:{{SUBST:ns:%d}}:%s}}]] at {{#timel:H:i, d F Y (e)|{{REVISIONTIMESTAMP:{{SUBST:ns:%d}}:%s}}}}\n'  %(ns,tt.decode("utf-8"),ns,tt.decode("utf-8"),ns,tt.decode("utf-8"),ns,tt.decode("utf-8"))
  58. cursor.close()
  59.  
  60. cursor = conn.cursor()
  61. cursor.execute("""
  62. SELECT REPLACE(page_title, '_', ' ') as tt,
  63.    page_namespace as ns
  64. FROM categorylinks
  65. JOIN page
  66.    ON page_id = cl_from
  67.    AND page_is_redirect = 0
  68.    AND NOT page_id = 1715141
  69. JOIN revision
  70.    ON rev_id = page_latest
  71. WHERE cl_to = 'Commons_protected_edit_requests_for_interface_administrators'
  72. ORDER BY rev_timestamp ASC
  73. LIMIT 200;
  74. """)
  75.  
  76. text += u'\n'
  77. text += u'=== Commons protected edit requests for interface administrators ===\n'
  78. text += u'[[File:Pliers with yellow handles (rotated).svg|right|60px]]\n'
  79. for tt, ns in cursor.fetchall():
  80.     text += u'* [[:{{subst:ns:%d}}:%s]] - Last edit by [[User:{{REVISIONUSER:{{SUBST:ns:%d}}:%s}}|{{REVISIONUSER:{{SUBST:ns:%d}}:%s}}]] at {{#timel:H:i, d F Y (e)|{{REVISIONTIMESTAMP:{{SUBST:ns:%d}}:%s}}}}\n'  %(ns,tt.decode("utf-8"),ns,tt.decode("utf-8"),ns,tt.decode("utf-8"),ns,tt.decode("utf-8"))
  81.    
  82. site = pywikibot.Site()
  83. page = pywikibot.Page(site, "Template:Edit request/List")
  84. page.put(text, comment=u'Update', minorEdit=False, botflag=False)
  85.  
  86. cursor.close()
  87. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement