Skip to content

Commit 9c050dd

Browse files
committed
Migrate to Stretch
* Create a requirements file * Use virtualenv * Switch to pymysql for DB access. Bug: https://phabricator.wikimedia.org/T218747
1 parent 35d67fc commit 9c050dd

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.config.py
2-
32
.DS_STORE
4-
53
*.pyc
4+
venv
5+
config.py

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Database Reports
2-
Generates statistical reports which are used by community members to improve Wikipedia.
2+
Generates statistical reports which are used by community members to improve Wikipedia.
33

4-
This project allows the [Community Tech bot](https://en.wikipedia.org/wiki/User:Community_Tech_bot) to make periodic updates to these reports on different language Wikipedias. As of now the project support report generation for English ([see here](https://en.wikipedia.org/wiki/Wikipedia:Database_reports)), Vietnamese, Korean and French Wikipedia.
4+
This project allows the [Community Tech bot](https://en.wikipedia.org/wiki/User:Community_Tech_bot) to make periodic updates to these reports on different language Wikipedias. As of now the project support report generation for English ([see here](https://en.wikipedia.org/wiki/Wikipedia:Database_reports)), Vietnamese, Korean and French Wikipedia.
55

6-
## Specific statistics that the reports support:
6+
## Specific statistics that the reports support:
77
* Unused templates
88
* Forgotten articles
99
* Most used templates
@@ -13,21 +13,30 @@ This project allows the [Community Tech bot](https://en.wikipedia.org/wiki/User:
1313
* Unused file redirects
1414
* Forgotten articles
1515
* Page with most revisions
16-
* Page count by namespace
17-
* Most edited articles last month
16+
* Page count by namespace
17+
* Most edited articles last month
1818
* PRODed articles with deletion logs
1919
* Editors eligible for autopatrol privileges
2020
* Active editors with the longest-established accounts
2121

22-
## Generating a report
22+
## Installation
23+
Virtualenv is recommended:
24+
25+
virtualenv venv
26+
source venv/bin/activate
27+
pip install -r requirements.txt
28+
29+
After installation, either activate virtualenv like above or use `venv/bin/python` to run scripts.
30+
31+
## Generating a report
2332
* Log into the Toolforge bastion using your Wikimedia developer account ```ssh username@login.tools.wmflabs.org```
2433
* Become your tool account ```become database-reports```
25-
* Run ```python main.py test articles_by_size```. It takes two arguments; in this example test refers to `test.wikipedia.org` and `articles_by_size` is the type of statistics you're requesting. This command outputs the name of the page on which the report got dumped
34+
* Run ```python main.py test articles_by_size```. It takes two arguments; in this example test refers to `test.wikipedia.org` and `articles_by_size` is the type of statistics you're requesting. This command outputs the name of the page on which the report got dumped
2635
* To alter the default settings for periodic updates, make changes to the crontab file ```crontab -e```
2736

2837
## Adding support for a report
29-
* To add support for a specific statistics that you would like to see in a report, declare a function in `main.py` and define it in `reports.py`
30-
* To provide support for translations in a specific language, include the dictionary in `i18n/i18n.py`
38+
* To add support for a specific statistics that you would like to see in a report, declare a function in `main.py` and define it in `reports.py`
39+
* To provide support for translations in a specific language, include the dictionary in `i18n/i18n.py`
3140

3241
## Contributing
3342
Bug reports, fixes, and new features are welcomed. If you'd like to contribute code please:

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mwclient
2-
import MySQLdb
2+
import pymysql
33
from displayTable import *
44
from config import *
55
from reports import *
@@ -18,7 +18,7 @@ def main ( args ):
1818

1919
class Run:
2020
def __init__( self, wiki ):
21-
self.db = MySQLdb.connect( host = wiki + 'wiki.labsdb', user = credentials['user'], passwd = credentials['pass'], db = wiki + 'wiki_p' )
21+
self.db = pymysql.connect( host = wiki + 'wiki.labsdb', user = credentials['user'], passwd = credentials['pass'], db = wiki + 'wiki_p' )
2222
self.site = mwclient.Site( wiki + '.wikipedia.org' )
2323
self.site.login( cttbot['user'], cttbot['pass'] )
2424
self.rep = Reports( self.site, self.db, wiki )

reports.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mwclient
2-
import MySQLdb
2+
import pymysql
33
from i18n import i18n
44
import datetime
55
from displayTable import *
@@ -13,6 +13,8 @@ def __init__( self, site, db, wiki ):
1313
self.db = db
1414
self.site = site
1515
self.wiki = wiki
16+
# 30s is not enough
17+
self.site.requests['timeout'] = 120
1618

1719
# Oldest edited articles
1820
# Run time on enwiki 5 hours 23 minutes as of 8 Sept 2015

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mwclient == 0.9.3
2+
PyMySQL == 0.9.3

test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mwclient
2-
import MySQLdb
2+
import pymysql
33
import datetime
44
from .config import *
55
from reports import *
@@ -8,7 +8,7 @@
88

99
def forgotten_articles():
1010

11-
db = MySQLdb.connect( host = 'enwiki.labsdb', user = credentials['user'], passwd = credentials['pass'], db = 'enwiki_p' )
11+
db = pymysql.connect( host = 'enwiki.labsdb', user = credentials['user'], passwd = credentials['pass'], db = 'enwiki_p' )
1212
site = mwclient.Site( 'en.wikipedia.org' )
1313
site.login( cttbot['user'], cttbot['pass'] )
1414
print 'initiated'

0 commit comments

Comments
 (0)