]> git.0d.be Git - panikdb.git/commitdiff
load-piwik-stats: make request using requests module
authorFrédéric Péters <fpeters@0d.be>
Wed, 8 Jan 2020 15:07:19 +0000 (16:07 +0100)
committerFrédéric Péters <fpeters@0d.be>
Wed, 8 Jan 2020 15:07:19 +0000 (16:07 +0100)
panikdb/stats/management/commands/load-piwik-stats.py

index 33908568c70d4f101cb8408327f5a533eba4ccc5..8aa4750d46f2c0f8a01a90f85ed510dfc8bf0e23 100644 (file)
@@ -1,6 +1,6 @@
 import datetime
 import json
-import urllib2
+import requests
 
 from django.conf import settings
 from django.core.management.base import BaseCommand, CommandError
@@ -18,11 +18,10 @@ class Command(BaseCommand):
               'secondaryDimension=eventName&idSite=%(piwik_site_id)s&'\
               'period=day&date=last2&format=json&'\
               'token_auth=%(piwik_token_auth)s&expanded=1' % locals()
-        request = urllib2.Request(url)
-        request.add_header('Accept', 'application/json')
         if self.verbose:
             print('calling piwik')
-        result = json.load(urllib2.urlopen(request))
+        response = requests.get(url, headers={'Accept': 'application/json'})
+        result = response.json()
         if self.verbose:
             print('collecting results')
         for day in result: