|
28 | 28 | { |
29 | 29 | "cell_type": "code", |
30 | 30 | "execution_count": 1, |
31 | | - "metadata": { |
32 | | - "collapsed": true |
33 | | - }, |
| 31 | + "metadata": {}, |
34 | 32 | "outputs": [], |
35 | 33 | "source": [ |
36 | 34 | "import os\n", |
37 | 35 | "import json\n", |
38 | | - "from twittersearch import ResultStream, gen_endpoint, gen_rule_payload" |
| 36 | + "from twittersearch import ResultStream, gen_rule_payload" |
39 | 37 | ] |
40 | 38 | }, |
41 | 39 | { |
|
49 | 47 | }, |
50 | 48 | { |
51 | 49 | "cell_type": "code", |
52 | | - "execution_count": 4, |
| 50 | + "execution_count": 22, |
53 | 51 | "metadata": {}, |
54 | | - "outputs": [ |
55 | | - { |
56 | | - "name": "stdout", |
57 | | - "output_type": "stream", |
58 | | - "text": [ |
59 | | - "https://gnip-api.twitter.com/search/fullarchive/accounts/<account_name>/ogformat.json\n" |
60 | | - ] |
61 | | - } |
62 | | - ], |
| 52 | + "outputs": [], |
63 | 53 | "source": [ |
64 | 54 | "# set your environment variables here for enterprise access if you need to\n", |
65 | 55 | "# os.environ[\"TWITTER_SEARCH_ACCOUNT_NAME\"] = \"\"\n", |
66 | 56 | "# os.environ[\"TWITTER_SEARCH_PW\"] = \"\"\n", |
67 | 57 | "\n", |
68 | | - "\n", |
69 | | - "enterprise_search_endpoint = gen_endpoint(kind=\"enterprise\", \n", |
70 | | - " search_api=\"fullarchive\",\n", |
71 | | - " account_name=os.environ[\"TWITTER_SEARCH_ACCOUNT_NAME\"],\n", |
72 | | - " label=\"ogformat.json\",\n", |
73 | | - " count_endpoint=False)\n", |
74 | | - "\n", |
| 58 | + "enterprise_endpoint = \"<ENTER YOUR ENDPOINT HERE>\"\n", |
75 | 59 | "enterprise_search_args = {\"username\": \"agonzales@twitter.com\",\n", |
76 | 60 | " \"password\": os.environ[\"TWITTER_SEARCH_PW\"],\n", |
77 | | - " \"url\": enterprise_search_endpoint,\n", |
78 | | - " }\n", |
79 | | - "\n", |
80 | | - "\n", |
81 | | - "\n", |
82 | | - "print(enterprise_search_endpoint.replace(os.environ[\"TWITTER_SEARCH_ACCOUNT_NAME\"], '<account_name>'))" |
| 61 | + " \"endpoint\": enterprise_endpoint\n", |
| 62 | + " }" |
83 | 63 | ] |
84 | 64 | }, |
85 | 65 | { |
|
93 | 73 | }, |
94 | 74 | { |
95 | 75 | "cell_type": "code", |
96 | | - "execution_count": 20, |
| 76 | + "execution_count": 23, |
97 | 77 | "metadata": {}, |
98 | 78 | "outputs": [ |
99 | 79 | { |
|
108 | 88 | "# set your environment variables here for premium access if you need to\n", |
109 | 89 | "# os.environ[\"TWITTER_SEARCH_BEARER_TOKEN\"] = \"\"\n", |
110 | 90 | "\n", |
111 | | - "\n", |
112 | | - "premium_search_endpoint = gen_endpoint(kind=\"premium\",\n", |
113 | | - " search_api=\"30day\",\n", |
114 | | - " label=\"dev\",\n", |
115 | | - " count_endpoint=False)\n", |
| 91 | + "premium_search_endpoint = \"https://api.twitter.com/1.1/tweets/search/30day/dev.json\"\n", |
116 | 92 | "\n", |
117 | 93 | "premium_search_args = {\"bearer_token\": os.environ[\"TWITTER_SEARCH_BEARER_TOKEN\"],\n", |
118 | | - " \"url\": premium_search_endpoint,\n", |
| 94 | + " \"endpoint\": premium_search_endpoint,\n", |
119 | 95 | " }\n", |
120 | 96 | "\n", |
121 | 97 | "print(premium_search_endpoint)" |
|
130 | 106 | }, |
131 | 107 | { |
132 | 108 | "cell_type": "code", |
133 | | - "execution_count": 8, |
| 109 | + "execution_count": 24, |
134 | 110 | "metadata": {}, |
135 | 111 | "outputs": [ |
136 | 112 | { |
|
178 | 154 | }, |
179 | 155 | { |
180 | 156 | "cell_type": "code", |
181 | | - "execution_count": 22, |
| 157 | + "execution_count": 5, |
182 | 158 | "metadata": { |
183 | 159 | "collapsed": true |
184 | 160 | }, |
|
189 | 165 | }, |
190 | 166 | { |
191 | 167 | "cell_type": "code", |
192 | | - "execution_count": 23, |
| 168 | + "execution_count": 6, |
193 | 169 | "metadata": {}, |
194 | 170 | "outputs": [ |
195 | 171 | { |
|
206 | 182 | }, |
207 | 183 | { |
208 | 184 | "cell_type": "code", |
209 | | - "execution_count": 24, |
| 185 | + "execution_count": 7, |
210 | 186 | "metadata": {}, |
211 | 187 | "outputs": [ |
212 | 188 | { |
|
218 | 194 | " ('920383435209891841', '@robotprincessfi hi there Fiona', [])]" |
219 | 195 | ] |
220 | 196 | }, |
221 | | - "execution_count": 24, |
| 197 | + "execution_count": 7, |
222 | 198 | "metadata": {}, |
223 | 199 | "output_type": "execute_result" |
224 | 200 | } |
|
241 | 217 | }, |
242 | 218 | { |
243 | 219 | "cell_type": "code", |
244 | | - "execution_count": 27, |
245 | | - "metadata": {}, |
| 220 | + "execution_count": 25, |
| 221 | + "metadata": { |
| 222 | + "collapsed": true |
| 223 | + }, |
246 | 224 | "outputs": [], |
247 | 225 | "source": [ |
248 | 226 | "rs = ResultStream(**premium_search_args, rule_payload=rule, max_results=500, max_pages=1, )" |
249 | 227 | ] |
250 | 228 | }, |
251 | 229 | { |
252 | 230 | "cell_type": "code", |
253 | | - "execution_count": 28, |
| 231 | + "execution_count": 26, |
254 | 232 | "metadata": {}, |
255 | 233 | "outputs": [ |
256 | 234 | { |
|
260 | 238 | "ResultStream: \n", |
261 | 239 | "\t{\n", |
262 | 240 | " \"username\":null,\n", |
263 | | - " \"url\":\"https:\\/\\/api.twitter.com\\/1.1\\/tweets\\/search\\/30day\\/dev.json\",\n", |
| 241 | + " \"endpoint\":\"https:\\/\\/api.twitter.com\\/1.1\\/tweets\\/search\\/30day\\/dev.json\",\n", |
264 | 242 | " \"rule_payload\":{\n", |
265 | 243 | " \"query\":\"@robotprincessfi\",\n", |
266 | 244 | " \"maxResults\":100\n", |
|
272 | 250 | } |
273 | 251 | ], |
274 | 252 | "source": [ |
275 | | - "print(str(rs).replace(os.environ[\"TWITTER_SEARCH_ACCOUNT_NAME\"], '<account_name>'))" |
| 253 | + "print(rs)" |
276 | 254 | ] |
277 | 255 | }, |
278 | 256 | { |
|
284 | 262 | }, |
285 | 263 | { |
286 | 264 | "cell_type": "code", |
287 | | - "execution_count": 29, |
| 265 | + "execution_count": 10, |
288 | 266 | "metadata": {}, |
289 | 267 | "outputs": [ |
290 | 268 | { |
|
308 | 286 | }, |
309 | 287 | { |
310 | 288 | "cell_type": "code", |
311 | | - "execution_count": 30, |
| 289 | + "execution_count": 11, |
312 | 290 | "metadata": {}, |
313 | 291 | "outputs": [ |
314 | 292 | { |
|
320 | 298 | " ('920383435209891841', '@robotprincessfi hi there Fiona', [])]" |
321 | 299 | ] |
322 | 300 | }, |
323 | | - "execution_count": 30, |
| 301 | + "execution_count": 11, |
324 | 302 | "metadata": {}, |
325 | 303 | "output_type": "execute_result" |
326 | 304 | } |
|
338 | 316 | }, |
339 | 317 | { |
340 | 318 | "cell_type": "code", |
341 | | - "execution_count": 31, |
| 319 | + "execution_count": 27, |
342 | 320 | "metadata": {}, |
343 | 321 | "outputs": [ |
344 | 322 | { |
345 | 323 | "name": "stdout", |
346 | 324 | "output_type": "stream", |
347 | 325 | "text": [ |
348 | | - "{\"query\":\"from:jack\",\"maxResults\":100,\"toDate\":\"201710150000\",\"fromDate\":\"201709010000\"}\n" |
| 326 | + "{\"query\":\"from:jack\",\"maxResults\":100,\"toDate\":\"201710300000\",\"fromDate\":\"201709010000\"}\n" |
349 | 327 | ] |
350 | 328 | } |
351 | 329 | ], |
352 | 330 | "source": [ |
353 | | - "rule = gen_rule_payload(\"from:jack\", from_date=\"2017-09-01\", to_date=\"2017-10-15\", max_results=100)\n", |
| 331 | + "rule = gen_rule_payload(\"from:jack\", from_date=\"2017-09-01\", to_date=\"2017-10-30\", max_results=100)\n", |
354 | 332 | "print(rule)" |
355 | 333 | ] |
356 | 334 | }, |
357 | 335 | { |
358 | 336 | "cell_type": "code", |
359 | | - "execution_count": 32, |
| 337 | + "execution_count": 16, |
360 | 338 | "metadata": {}, |
361 | 339 | "outputs": [ |
362 | 340 | { |
|
373 | 351 | }, |
374 | 352 | { |
375 | 353 | "cell_type": "code", |
376 | | - "execution_count": 33, |
| 354 | + "execution_count": 17, |
377 | 355 | "metadata": {}, |
378 | 356 | "outputs": [ |
379 | 357 | { |
380 | 358 | "data": { |
381 | 359 | "text/plain": [ |
382 | | - "[('2017-10-14 22:57:23',\n", |
383 | | - " 'I love to see Palestinians dancing and having fun. Good &positive stories deserve to go viral as well. Watch this: https://t.co/42vOrC40Fu',\n", |
384 | | - " []),\n", |
385 | | - " ('2017-10-14 22:55:25',\n", |
386 | | - " \"But don't argue with people on twitter about whether policies and laws are racist. Argue with your City Council and your state reps and senators and Mayor and alderman. And if you don't like how that argument went\\nfire em.\",\n", |
387 | | - " []),\n", |
388 | | - " ('2017-10-14 21:30:26',\n", |
389 | | - " 'I saw @solangeknowles perform at Chinati last weekend. It was the most beautiful thing I’ve ever seen. Can’t stop thinking about it. https://t.co/1wNLiNCaxb',\n", |
390 | | - " []),\n", |
391 | | - " ('2017-10-14 19:17:33', '1', []),\n", |
392 | | - " ('2017-10-14 17:30:01',\n", |
393 | | - " '@monteiro @JohnPaczkowski @cwarzel Never asked for credit Mike',\n", |
394 | | - " []),\n", |
395 | | - " ('2017-10-14 17:26:00',\n", |
396 | | - " '@cwarzel @JohnPaczkowski Will keep everyone updated on the original thread',\n", |
| 360 | + "[('2017-10-27 18:22:07',\n", |
| 361 | + " 'More clarity on our private information policy and enforcement. Working to build as much direct context into the product too https://t.co/IrwBexPrBA\\nTo provide more clarity on our private information policy, we’ve added specific examples of what is/is not a violation and insight into what we need to remove this type of content from the service. https://t.co/NGx5hh2tTQ',\n", |
397 | 362 | " []),\n", |
398 | | - " ('2017-10-14 17:03:38',\n", |
399 | | - " '@davewiner Listened to it all. Doesn’t mean we are going to implement everything! ;)',\n", |
| 363 | + " ('2017-10-27 18:17:37',\n", |
| 364 | + " 'Launching violent groups and hateful images/symbols policy on November 22nd https://t.co/NaWuBPxyO5\\nWe will now launch our policies on violent groups and hateful imagery and hate symbols on Nov 22. During the development process, we received valuable feedback that we’re implementing before these are published and enforced. See more on our policy development process here 👇 https://t.co/wx3EeH39BI',\n", |
400 | 365 | " []),\n", |
401 | | - " ('2017-10-14 17:00:56',\n", |
402 | | - " '@davewiner @realDonaldTrump Also not true. It’s a moment in time',\n", |
| 366 | + " ('2017-10-27 01:25:39', '@WillStick @lizkelley Happy birthday Liz!', []),\n", |
| 367 | + " ('2017-10-26 14:24:05',\n", |
| 368 | + " 'Off-boarding advertising from all accounts owned by Russia Today (RT) and Sputnik.\\n\\nWe’re donating all projected earnings ($1.9mm) to support external research into the use of Twitter in elections, including use of malicious automation and misinformation. https://t.co/zIxfqqXCZr',\n", |
403 | 369 | " []),\n", |
404 | | - " ('2017-10-14 17:00:20',\n", |
405 | | - " '@davewiner Come on. This isn’t true. We care. We have to build a business to fund the service',\n", |
| 370 | + " ('2017-10-26 13:50:40', '@TMFJMo @anthonynoto Thank you', []),\n", |
| 371 | + " ('2017-10-26 13:36:19', '@gasca @stratechery @Lefsetz letter', []),\n", |
| 372 | + " ('2017-10-26 13:35:57',\n", |
| 373 | + " '@gasca @stratechery Bridgewater’s Daily Observations',\n", |
406 | 374 | " []),\n", |
407 | | - " ('2017-10-14 16:59:21',\n", |
408 | | - " '@yaelwrites @JohnPaczkowski @cwarzel @jilliancyork Never said that. We are considering. Need to prioritize.',\n", |
| 375 | + " ('2017-10-26 02:40:25',\n", |
| 376 | + " 'Yup!!!! ❤️❤️❤️❤️ #davechappelle https://t.co/ybSGNrQpYF',\n", |
| 377 | + " ['davechappelle']),\n", |
| 378 | + " ('2017-10-26 00:07:23', '@ndimichino Sometimes', []),\n", |
| 379 | + " ('2017-10-25 20:15:19',\n", |
| 380 | + " 'Setting up at @CampFlogGnaw https://t.co/nVq8QjkKsf',\n", |
409 | 381 | " [])]" |
410 | 382 | ] |
411 | 383 | }, |
412 | | - "execution_count": 33, |
| 384 | + "execution_count": 17, |
413 | 385 | "metadata": {}, |
414 | 386 | "output_type": "execute_result" |
415 | 387 | } |
|
0 commit comments