Permalink
Browse files

add most_watched report

SQL query from MZMcBride https://en.wikipedia.org/w/index.php?title=User_talk:BernsteinBot&diff=762334008&oldid=762110908 (Public domain; bjweeks, MZMcBride; 2009, 2017)
  • Loading branch information...
framawiki committed Jan 30, 2017
1 parent 5651f9a commit e66d11797e6f0eee05c79d69f41f1941279d826e
Showing with 47 additions and 1 deletion.
  1. +18 −0 i18n/i18n.py
  2. +3 −0 main.py
  3. +26 −1 reports.py
View
@@ -89,6 +89,12 @@
"most_edited_page_last_month-desc": "Articles ranked by number of edits during last 30 days, limit to the 25 firsts.",
"most_edited_page_last_month-title": "Title",
"most_edited_page_last_month-editcount": "Revisions",
"most_watched-page-title": "Most-watched pages",
"most_watched-desc": "Most-watched non-deleted pages (limited to the first 1000 entries)",
"most_watched-namespace": "Namespace",
"most_watched-title": "Title",
"most_watched-watchers": "Count"
},
'esdict' : {
@@ -200,6 +206,12 @@
"most_edited_page_last_month-desc": "Articles ranked by number of edits during last 30 days, limit to the 25 firsts.",
"most_edited_page_last_month-title": "Title",
"most_edited_page_last_month-editcount": "Revisions",
"most_watched-page-title": "Most-watched pages",
"most_watched-desc": "Most-watched non-deleted pages (limited to the first 1000 entries)",
"most_watched-namespace": "Namespace",
"most_watched-title": "Title",
"most_watched-watchers": "Count"
},
'frdict' : {
@@ -289,5 +301,11 @@
"most_edited_page_last_month-desc": "Liste des 25 articles ayant eu le plus de modifications durant les 30 derniers jours. Il est possible de trier une colonne en cliquant sur les deux flèches de son libellé.",
"most_edited_page_last_month-title": "Titre",
"most_edited_page_last_month-editcount": "Nombre d'éditions",
"most_watched-page-title": "Pages les plus suivies",
"most_watched-desc": "Liste des pages non-supprimées les plus suivies (limitée aux 1 000 premières entrées)",
"most_watched-namespace": "[[Aide:Espace de noms|NS]]",
"most_watched-title": "Titre",
"most_watched-watchers": "Nombre"
}
}
View
@@ -65,5 +65,8 @@ def article_by_size( self ):
def most_edited_page_last_month( self ):
self.rep.most_edited_page_last_month()
def most_watched(self):
self.rep.most_watched()
if __name__ == '__main__':
main(sys.argv)
View
@@ -407,6 +407,31 @@ def article_by_size( self ):
text = display_report( self.wiki, content , 'article_by_size-desc' )
self.publish_report( 'article_by_size-page-title', text )
def most_watched( self ):
cur = self.db.cursor()
# query on Public domain; bjweeks, MZMcBride; 2009, 2017
query = """SELECT
wl_namespace,
wl_title,
watchers
FROM watchlist_count
JOIN page
ON wl_namespace = page_namespace
AND wl_title = page_title
WHERE wl_namespace mod 2 = 0
AND wl_namespace >= 0
ORDER BY watchers DESC, wl_title ASC
LIMIT 1000;"""
cur.execute(query)
content = []
content.append( ['most_watched-namespace', 'most_watched-title', 'most_watched-watchers'] )
for row in cur.fetchall():
content.append( [ row[0], self.linkify( row[1], row[0] ), row[2] ])
# Format the data as wikitext
text = display_report(self.wiki, content, 'most_watched-desc')
self.publish_report('most_watched-page-title', text)
''' Publish report on page with given title, with the given content
@param title Page title
@param content Content to be displayed on page
@@ -415,7 +440,7 @@ def publish_report( self, title, content ):
dict_obj = i18n.lang_dicts[ str( self.wiki + 'dict') ]
reports_base_url = dict_obj[ str( 'reports_base_url' ) ]
report_title = dict_obj[ str( title ) ]
print str( reports_base_url + report_title )
print(str( reports_base_url + report_title ))
page = self.site.Pages[ reports_base_url + report_title ]
page.save( content, summary = dict_obj[ 'summary' ] , minor=True)

0 comments on commit e66d117

Please sign in to comment.