Commit bfe1687b authored by fred's avatar fred

load-piwik-stats: make request using requests module

parent 77913ccf
import datetime import datetime
import json import json
import urllib2 import requests
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -18,11 +18,10 @@ class Command(BaseCommand): ...@@ -18,11 +18,10 @@ class Command(BaseCommand):
'secondaryDimension=eventName&idSite=%(piwik_site_id)s&'\ 'secondaryDimension=eventName&idSite=%(piwik_site_id)s&'\
'period=day&date=last2&format=json&'\ 'period=day&date=last2&format=json&'\
'token_auth=%(piwik_token_auth)s&expanded=1' % locals() 'token_auth=%(piwik_token_auth)s&expanded=1' % locals()
request = urllib2.Request(url)
request.add_header('Accept', 'application/json')
if self.verbose: if self.verbose:
print('calling piwik') print('calling piwik')
result = json.load(urllib2.urlopen(request)) response = requests.get(url, headers={'Accept': 'application/json'})
result = response.json()
if self.verbose: if self.verbose:
print('collecting results') print('collecting results')
for day in result: for day in result:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment