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 3390856..8aa4750 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: