This repository has been archived by the owner on Nov 4, 2021. It is now read-only.
/
realtime.py
242 lines (205 loc) · 8.32 KB
/
realtime.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
"""Module for Realtime Results Api."""
import inspect
from typing import Any, Dict, List
from .base import JSONDict, handle_response, rate_limited
from .session import HexpySession
class RealtimeAPI:
"""Class for working with RealtimeAPI.
# Example usage.
```python
>>> from hexpy import HexpySession, RealtimeAPI
>>> session = HexpySession.load_auth_from_file()
>>> realtime_client = RealtimeAPI(session)
>>> realtime_client.list(team_id)
>>> session.close()
```
"""
def __init__(self, session: HexpySession) -> None:
self.session = session.session
self.TEMPLATE = session.ROOT + "realtime/monitor/"
for name, fn in inspect.getmembers(self, inspect.ismethod):
if name not in ["__init__"]:
setattr(
self, name, rate_limited(fn, session.MAX_CALLS, session.ONE_MINUTE)
)
def cashtags(self, monitor_id: int, start: int = None, top: int = None) -> JSONDict:
"""Get Cashtags associated to a Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
top: Integer, The top N cashtags to retrieve.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "cashtags",
params={"id": monitor_id, "start": start, "top": top},
)
)
def hashtags(self, monitor_id: int, start: int = None, top: int = None) -> JSONDict:
"""Get Hashtags associated to a Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
top: Integer, The top N hashtags to retrieve.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "hashtags",
params={"id": monitor_id, "start": start, "top": top},
)
)
def list(self, team_id: int) -> JSONDict:
"""Get the Monitors which are in Proteus
# Arguments
team_id: Integer, The id of the team to which the listed monitors belong.
"""
return handle_response(
self.session.get(self.TEMPLATE + "list", params={"team_id": team_id})
)
def configure(self, monitor_id: int, data: Dict[str, Any]) -> JSONDict:
"""Configure the Realtime evaluators for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
"""
return handle_response(
self.session.post(
self.TEMPLATE + "configure", params={"id": monitor_id}, json=data
)
)
def enable(self, monitor_id: int) -> JSONDict:
"""Enable Realtime Data.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
"""
return handle_response(
self.session.get(self.TEMPLATE + "enable", params={"id": monitor_id})
)
def disbale(self, monitor_id: int) -> JSONDict:
"""Disable Realtime Data.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
"""
return handle_response(
self.session.get(self.TEMPLATE + "disable", params={"id": monitor_id})
)
def detail(self, monitor_id: int) -> JSONDict:
"""Get the Realtime evaluators details for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
"""
return handle_response(
self.session.get(self.TEMPLATE + "details", params={"id": monitor_id})
)
def retweets(self, monitor_id: int) -> JSONDict:
"""Get the Realtime retweets for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
"""
return handle_response(
self.session.get(self.TEMPLATE + "retweets", params={"id": monitor_id})
)
def full_retweets(self, monitor_id: int, start: int) -> JSONDict:
"""Get the Realtime fullretweets for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, Specifies inclusive start date in epoch seconds
"""
return handle_response(
self.session.get(
self.TEMPLATE + "fullretweets",
params={"id": monitor_id, "start": start},
)
)
def social_guids(
self,
monitor_id: int,
doc_type: str,
start: int = None,
received_after: int = None,
maxresults: int = None,
) -> JSONDict:
"""Get the Realtime social guids for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
doc_type: String, Specifies the document type.
start: Integer, specifies inclusive start date in epoch seconds.
received_after: Integer, Specifies inclusive received after date in epoch seconds.
maxresults: Integer, Specifies maximum results to fetch.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "socialguids",
params={
"id": monitor_id,
"start": start,
"receivedafter": received_after,
"type": doc_type,
"maxresults": maxresults,
},
)
)
def tweets(self, monitor_id: int, start: int = None) -> JSONDict:
"""Get the Realtime tweets for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "tweets", params={"id": monitor_id, "start": start}
)
)
def full_tweets(self, monitor_id: int, start: int = None) -> JSONDict:
"""Get the Realtime fulltweets for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "fulltweets", params={"id": monitor_id, "start": start}
)
)
def volume(
self, monitor_id: int, start: int = None, doc_type: List = None
) -> JSONDict:
"""Get the Realtime volume for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
doc_type: List, specifies the document type to filter.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "volume",
params={"id": monitor_id, "start": start, "type": doc_type},
)
)
def volume_by_sentiment(
self, monitor_id: int, start: int, doc_type: str
) -> JSONDict:
"""Get the Realtime volume by sentiment for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
doc_type: String, specifies the document type to filter.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "volumebysentiment",
params={"id": monitor_id, "start": start, "type": doc_type},
)
)
def volume_by_emotion(self, monitor_id: int, start: int, doc_type: str) -> JSONDict:
"""Get the Realtime volume by emotion for the Monitor.
# Arguments
monitor_id: Integer, the id of the monitor being requested.
start: Integer, specifies inclusive start date in epoch seconds.
doc_type: String, specifies the document type to filter.
"""
return handle_response(
self.session.get(
self.TEMPLATE + "volumebyemotion",
params={"id": monitor_id, "start": start, "type": doc_type},
)
)