Skip to content

Commit a6f8112

Browse files
committed
Merge pull request #24 from Commonists/pageviewapi
Replacing stats.grok.se by pageviewapi
2 parents 1aa09f9 + 53614d3 commit a6f8112

4 files changed

Lines changed: 13 additions & 20 deletions

File tree

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flake8
2+
git+https://github.com/Commonists/pageview-api.git

surfaceimagecontentgap/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
""" Surface image content gap. """
2-
__version__ = 1.1
2+
__version__ = 1.2

surfaceimagecontentgap/imagegap.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66
from ConfigParser import RawConfigParser
77
import logging
88

9-
import requests
109
import mwclient
1110

1211
import contentgap
1312
import report
1413
import mwtemplate
1514

15+
import pageviewapi.period
16+
1617
# Constants
1718
LOGGER_NAME = 'sicglog'
1819
WIKIPEDIA_URL = '{0}.wikipedia.org'
1920
PROTOCOL = 'https'
2021
USER_AGENT = 'Bot based on mwclient'
21-
GROK_SE_URL = "http://stats.grok.se/json/{0:s}/latest{1:d}/{2:s}"
22-
GROK_MISSING_DAILY_VIEWS = "grok.se invalid result, missing daily_views"
2322
MAX_TIME_WITHOUT_UPDATE = 600
2423

2524
ARTICLE_NAMESPACE = 0
@@ -53,22 +52,13 @@ def latest90(article):
5352
5453
Returns:
5554
int: sum of daily views.
56-
57-
Raises:
58-
MissingDailyViewsException: if daily_views are missing from response.
5955
"""
60-
articlename = article.name.encode('utf-8')
61-
url = GROK_SE_URL.format(article.site.site['lang'],
62-
90,
63-
articlename)
64-
LOG.info('Fetching views on grok.se %s', url)
65-
result = requests.get(url).json()
66-
if 'daily_views' in result:
67-
views = sum([result['daily_views'][d]
68-
for d in result['daily_views']])
69-
return views
70-
else:
71-
raise MissingDailyViewsException(GROK_MISSING_DAILY_VIEWS)
56+
project = '{lang}.wikipedia'.format(lang=article.site.site['lang'])
57+
return pageviewapi.period.sum_last(project,
58+
article.name.encode('utf-8'),
59+
last=90,
60+
access='all-access',
61+
agent='all-agents')
7262

7363

7464
def searcharticles(category, depth=0):

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ envlist = flake8
33
skipsdist = True
44

55
[testenv:flake8]
6-
deps = flake8
6+
deps =
7+
-r{toxinidir}/requirements.txt
78
commands = flake8
89

910
[flake8]

0 commit comments

Comments
 (0)