scripts/get_traffic.py
def get_data(self, url='',headers={}, date=str(datetime.date.today()),
        dict_to_store={}, type='', repo_name=''):
        """
        Retrieves data from json and stores it in the supplied dict. Accepts
        'clones' or 'views' as type.
        """
        #JSON
        url = (url + '/traffic/' + type)
        r3 = requests.get(url, headers=headers)
        json = r3.json()
        if type == 'views':
            self.views_json[repo_name] = json
        elif type == 'clones':
            self.clones_json[repo_name] = json
        #CSV
        for day in json[type]:
            timestamp_seconds = day['timestamp']/1000
            try:
                date_timestamp = datetime.datetime.utcfromtimestamp(
                    timestamp_seconds).strftime('%Y-%m-%d')
                #do not add todays date, some views might not be recorded yet
                if date_timestamp != date:
                    tuple_in = (day['count'], day['uniques'])
                    tuple = (dict_to_store[timestamp_seconds][0] + tuple_in[0],
                        dict_to_store[timestamp_seconds][1] + tuple_in[1])
                    dict_to_store[timestamp_seconds] = tuple
            except KeyError:
                tuple = dict_to_store[timestamp_seconds] = (day['count'],
                    day['uniques'])
def get_data(self, url='',headers={}, date=str(datetime.date.today()),
        dict_to_store={}, type='', repo_name=''):
        """
        Retrieves data from json and stores it in the supplied dict. Accepts
        'clones' or 'views' as type.
        """
        #JSON
        url = (url + '/traffic/' + type)
        r3 = requests.get(url, headers=headers)
        json = r3.json()
        if type == 'views':
            self.views_json[repo_name] = json
        elif type == 'clones':
            self.clones_json[repo_name] = json
        #CSV
        for day in json[type]:
            timestamp_seconds = day['timestamp']/1000
            try:
                date_timestamp = datetime.datetime.utcfromtimestamp(
                    timestamp_seconds).strftime('%Y-%m-%d')
                #do not add todays date, some views might not be recorded yet
                if date_timestamp != date:
                    tuple_in = (day['count'], day['uniques'])
                    tuple = (dict_to_store[timestamp_seconds][0] + tuple_in[0],
                        dict_to_store[timestamp_seconds][1] + tuple_in[1])
                    dict_to_store[timestamp_seconds] = tuple
            except KeyError:
                tuple = dict_to_store[timestamp_seconds] = (day['count'],
                    day['uniques'])
Retrieves data from json and stores it in the supplied dict. Accepts
        'clones' or 'views' as type.