/
traffic.py
86 lines (55 loc) · 2.15 KB
/
traffic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
"""Repository traffic stats logic."""
from .. import models
class ViewsStats(models.GitHubCore):
"""The total number of repository views, per day or week, for the last 14
days.
See also https://developer.github.com/v3/repos/traffic/
.. note::
Timestamps are aligned to UTC midnight of the beginning of the day or
week. Week begins on Monday.
This object has the following attributes:
.. attribute:: count
The total number of views.
.. attribute:: uniques
The total number of unique views.
.. attribute:: views
A list of dictionaries containing daily or weekly statistical data.
"""
def _update_attributes(self, stats_object):
self.count = stats_object["count"]
self.uniques = stats_object["uniques"]
self.views = stats_object["views"]
if self.views:
for view in self.views:
view["timestamp"] = self._strptime(view["timestamp"])
def _repr(self):
return (
"<Views Statistics " "[{s.count}, {s.uniques} unique]>"
).format(s=self)
class ClonesStats(models.GitHubCore):
"""The total number of repository clones, per day or week, for the last 14
days.
See also https://developer.github.com/v3/repos/traffic/
.. note::
Timestamps are aligned to UTC midnight of the beginning of the day or
week. Week begins on Monday.
This object has the following attributes:
.. attribute:: count
The total number of clones.
.. attribute:: uniques
The total number of unique clones.
.. attribute:: clones
A list of dictionaries containing daily or weekly statistical data.
"""
def _update_attributes(self, stats_object):
self.count = stats_object["count"]
self.uniques = stats_object["uniques"]
self.clones = stats_object["clones"]
if self.clones:
for clone in self.clones:
clone["timestamp"] = self._strptime(clone["timestamp"])
def _repr(self):
return (
"<Clones Statistics " "[{s.count}, {s.uniques} unique]>"
).format(s=self)