Skip to content

Commit f845269

Browse files
author
Aaron Gonzales
committed
updated readmes
1 parent a242a44 commit f845269

File tree

3 files changed

+591
-257
lines changed

3 files changed

+591
-257
lines changed

README.rst

Lines changed: 178 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,12 @@ basic username/password method. You can specify that here:
195195

196196
.. code:: python
197197
198-
enterprise_search_args, enterprise_count_args = load_credentials("~/.twitter_keys.yaml",
199-
account_type="enterprise")
198+
from twittersearch import infer_endpoint
199+
200+
.. code:: python
201+
202+
enterprise_search_args = load_credentials("~/.twitter_keys.yaml",
203+
account_type="enterprise")
200204
201205
Premium Setup
202206
-------------
@@ -206,8 +210,8 @@ following cell for setup:
206210

207211
.. code:: python
208212
209-
premium_search_args, premium_count_args = load_credentials("~/.twitter_keys.yaml",
210-
account_type="premium")
213+
premium_search_args = load_credentials("~/.twitter_keys.yaml",
214+
account_type="premium")
211215
212216
There is a function that formats search API rules into valid json
213217
queries called ``gen_rule_payload``. It has sensible defaults, such as
@@ -267,30 +271,45 @@ Let's see how it goes:
267271
268272
tweets = collect_results(rule,
269273
max_results=100,
270-
resut_stream_args=enterprise_search_args) # change this if you need to
274+
result_stream_args=enterprise_search_args) # change this if you need to
271275
272276
By default, tweet payloads are lazily parsed into a ``Tweet`` object. An
273277
overwhelming number of tweet attributes are made available directly, as
274278
such:
275279

276280
.. code:: python
277281
278-
[print(unidecode(tweet.all_text)) for tweet in tweets[0:10]];
282+
[print(tweet.all_text) for tweet in tweets[0:10]];
279283
280284
281285
.. parsed-literal::
282286
283-
3 years ago today, beyonce surprise dropped the fastest selling album on itunes EVER then posted this on instagram like nothing happened https://t.co/F416MG2aCZ
284-
.@Beyonce sells OVER 80,000 copies of her new album in 3 hours: http://t.co/PKSARIvE67
285-
Perfect Duet with Beyonce and Ed Sheeran is the perfect combo ughhh
286-
As we celebrate the anniversary of 'BEYONCE,' I would just like to say that it is easily THE swankiest vinyl I own.
287-
Beyonce talks about natural disasters and climate change at 'Hand In Hand' Harvey Relief Telethon https://t.co/rP0wTIoUGx
288-
Perfect Duet (with Beyonce) by Ed Sheeran is number 2 in Austria #iTunes top 100 songs https://t.co/qqlBFLHpzl
289-
beyonce has truly delivered within the past week https://t.co/DDboQFBIgG
290-
I'll never forget waking up in the morning to a number of tweets from my friends. I was so confused. I switched on my computer, got onto iTunes and there it was... Beyonce EVERYWHERE! I screamed & jumped up & down in excitement and disbelief! Iconic! https://t.co/peN7Oyc5po
291-
Beyonce explaining her intent behind the BEYONCE visual album & how she wanted to reinstate the idea of an album release as a significant, exciting event which had lost meaning in the face of hype created around singles. https://t.co/pK2MB35vYl
292-
i had like 25 dollars in my account and used half of them to buy that album. songs AND VIDEOS??? BEYONCE WYD???? Man what a night.
293-
Ed Sheeran released the song without Beyonce and it didn't go #1. He released the song with Beyonce and it did go #1. it's clear and simple. he needed her to go #1 https://t.co/RteEZBzJu8
287+
That deep sigh Beyoncé took once she realized she wouldn’t be able to get the earpiece out of her hair before the dance break 😂. https://t.co/dU1K2KMT7i
288+
4 Years ago today, "BEYONCÉ" by Beyoncé was surprise released. It received acclaim from critics, debuted at #1 and certified 2x Platinum in the US. https://t.co/wB3C7DuX9o
289+
me mata la gente que se cree superior por sus gustos de música escuches queen beyonce o el polaco no sos mas ni menos que nadie
290+
I’m literally not Beyoncé https://t.co/LwIkllCx6P
291+
#BEYONCÉ ‣ 𝐌𝐄𝐀𝐃𝐃𝐅𝐀𝐍 𝐎𝐅𝐈𝐂𝐈𝐀𝐋 - I Am... 𝐖𝐎𝐑𝐋𝐃 𝐓𝐎𝐔𝐑! https://t.co/TyyeDdXKiM
292+
Beyoncé on how nervous she was to release her self-titled... https://t.co/fru23c6DYC
293+
AAAA ansiosa por esse feat da Beyoncé com Jorge Ben Jor <3 https://t.co/NkKJhC9JUd
294+
I am world tour, the Beyonce experience, revamped hmt. https://t.co/pb07eMyNka
295+
Tell me what studio versions of any artists would u like me to do? https://t.co/Z6YWsAJuhU
296+
Billboard's best female artists over the last decade:
297+
298+
2017: Ariana Grande
299+
2016: Adele
300+
2015: Taylor Swift
301+
2014: Katy Perry
302+
2013: Taylor Swift
303+
2012: Adele
304+
2011: Adele
305+
2010: Lady Gaga
306+
2009: Taylor Swift
307+
2008: Rihanna
308+
309+
Beyonce = 0
310+
311+
Taylor Swift = 3 👑
312+
Beyoncé explaining her intent behind the BEYONCÉ visual album & how she wanted to reinstate the idea of an album release as a significant, exciting event which had lost meaning in the face of hype created around singles. 👑 https://t.co/pK2MB35vYl
294313
295314
296315
.. code:: python
@@ -300,16 +319,16 @@ such:
300319
301320
.. parsed-literal::
302321
303-
2017-10-27 18:22:07
304-
2017-10-27 18:17:37
305-
2017-10-27 01:25:39
306-
2017-10-26 14:24:05
307-
2017-10-26 13:50:40
308-
2017-10-26 13:36:19
309-
2017-10-26 13:35:57
310-
2017-10-26 02:40:25
311-
2017-10-26 00:07:23
312-
2017-10-25 20:15:19
322+
2017-12-13 21:18:17
323+
2017-12-13 21:18:16
324+
2017-12-13 21:18:16
325+
2017-12-13 21:18:15
326+
2017-12-13 21:18:15
327+
2017-12-13 21:18:13
328+
2017-12-13 21:18:12
329+
2017-12-13 21:18:12
330+
2017-12-13 21:18:11
331+
2017-12-13 21:18:10
313332
314333
315334
.. code:: python
@@ -319,16 +338,16 @@ such:
319338
320339
.. parsed-literal::
321340
341+
Twitter for Android
342+
Twitter for Android
343+
Twitter for Android
322344
Twitter for iPhone
345+
Meadd
323346
Twitter for iPhone
347+
Twitter for Android
324348
Twitter for iPhone
325349
Twitter for iPhone
326-
Twitter for iPhone
327-
Twitter for iPhone
328-
Twitter for iPhone
329-
Twitter for iPhone
330-
Twitter for iPhone
331-
Twitter for iPhone
350+
Twitter for Android
332351
333352
334353
Voila, we have some tweets. For interactive environments and other cases
@@ -349,9 +368,7 @@ stop on number of pages to limit your API call usage.
349368
max_results=500,
350369
max_pages=1,
351370
**premium_search_args)
352-
353-
.. code:: python
354-
371+
355372
print(rs)
356373
357374
@@ -384,39 +401,42 @@ easily extractable.
384401
.. code:: python
385402
386403
# using unidecode to prevent emoji/accents printing
387-
[print(unidecode(tweet.all_text)) for tweet in tweets[0:10]];
404+
[print(tweet.all_text) for tweet in tweets[0:10]];
388405
389406
390407
.. parsed-literal::
391408
392-
BEYONCE WANTS ME DEAD https://t.co/6ztOJpz9dt
393-
in my college dorm and the Beyonce album popped up on iTunes and I thought it was fake because there was a Drake feature and I was like "bey would never" LITTLE DID I KNOW.... then this bitch gon post vegan cupcakes on instagram like she didn't just fuck the industry up... https://t.co/tRNo4O11uh
394-
When in doubt , watch a Beyonce documentary .
395-
Beyonce changed the game w/ that digital drop 4 years ago today!
409+
Everyone: *still dragging Jay for cheating*
410+
411+
Beyoncé: https://t.co/2z1ltlMQiJ
412+
Beyoncé changed the game w/ that digital drop 4 years ago today! 🎉
396413
397-
* #1 debut on Billboard
398-
* Sold 617K in the US / over 828K WW in only 3 days
399-
* Fastest-selling album on iTunes of all time
400-
* Reached #1 in 118 countries
401-
* Widespread acclaim; hailed as her magnum opus https://t.co/lDCdVs6em3
402-
Beyonce x JAY Z https://t.co/czJoAwt4eJ
403-
On this very day 4 years ago, as we were finishing up Scandal season finale and putting on our bonnets and Durags to sleep Beyonce said https://t.co/YFBGRmTWVY
414+
• #1 debut on Billboard
415+
• Sold 617K in the US / over 828K WW in only 3 days
416+
• Fastest-selling album on iTunes of all time
417+
• Reached #1 in 118 countries
418+
• Widespread acclaim; hailed as her magnum opus https://t.co/lDCdVs6em3
419+
Beyoncé 🔥 #444Tour https://t.co/sCvZzjLwqx
420+
Se presentan casos de feminismo pop basado en sugerencias de artistas famosos en turno, Emma Watson, Beyoncé.
421+
Beyonce. Are you kidding me with this?! #Supreme #love #everything
422+
Dear Beyoncé, https://t.co/5visfVK2LR
423+
At this time 4 years ago today, Beyoncé released her self-titled album BEYONCÉ exclusively on the iTunes Store without any prior announcement. The album remains the ONLY album in history to reach #1 in 118 countries & the fastest-selling album in the history of the iTunes Store. https://t.co/ZZb4QyQYf0
424+
4 years ago today, Beyoncé released her self-titled visual album "BEYONCÉ" and shook up the music world forever. 🙌🏿 https://t.co/aGtUSq9R3u
404425
Everyone: *still dragging Jay for cheating*
405426
406-
Beyonce: https://t.co/2z1ltlMQiJ
407-
quem e que tem dificuldades a admitir que a beyonce e a voz mais iconica da nossa geracao
408-
Beyonce on how nervous she was to release her self-titled... https://t.co/fru23c6DYC
409-
i'm bout to jump into my feelings because four years ago today i was so broke and dusty and beyonce came into my life and took the pain away.
427+
Beyoncé: https://t.co/2z1ltlMQiJ
428+
And Beyonce hasn't had a solo #1 hit since the Bush administration soooo... https://t.co/WCd7ni8DwN
410429
411430
412431
Counts API
413432
----------
414433

415434
We can also use the counts api to get counts of tweets that match our
416435
rule. Each request will return up to *30* results, and each count
417-
request can be done on a minutely, hourly, or daily basis. There is a
418-
utility function that will convert your regular endpoint to the count
419-
endpoint.
436+
request can be done on a minutely, hourly, or daily basis. The
437+
underlying ``ResultStream`` object will handle converting your endpoint
438+
to the count endpoint, and you have to specify the ``count_bucket``
439+
argument when making a rule to use it.
420440

421441
The process is very similar to grabbing tweets, but has some minor
422442
differneces.
@@ -428,7 +448,7 @@ API.**
428448
429449
count_rule = gen_rule_payload("beyonce", count_bucket="day")
430450
431-
counts = collect_results(count_rule, result_stream_args=enterprise_count_args)
451+
counts = collect_results(count_rule, result_stream_args=enterprise_search_args)
432452
433453
Our results are pretty straightforward and can be rapidly used.
434454

@@ -441,27 +461,27 @@ Our results are pretty straightforward and can be rapidly used.
441461
442462
.. parsed-literal::
443463
444-
[{'count': 68745, 'timePeriod': '201712130000'},
445-
{'count': 95305, 'timePeriod': '201712120000'},
446-
{'count': 114641, 'timePeriod': '201712110000'},
447-
{'count': 166070, 'timePeriod': '201712100000'},
448-
{'count': 102049, 'timePeriod': '201712090000'},
449-
{'count': 87710, 'timePeriod': '201712080000'},
450-
{'count': 196157, 'timePeriod': '201712070000'},
451-
{'count': 210664, 'timePeriod': '201712060000'},
452-
{'count': 88572, 'timePeriod': '201712050000'},
453-
{'count': 96794, 'timePeriod': '201712040000'},
464+
[{'count': 85660, 'timePeriod': '201712130000'},
465+
{'count': 95231, 'timePeriod': '201712120000'},
466+
{'count': 114540, 'timePeriod': '201712110000'},
467+
{'count': 165964, 'timePeriod': '201712100000'},
468+
{'count': 102022, 'timePeriod': '201712090000'},
469+
{'count': 87630, 'timePeriod': '201712080000'},
470+
{'count': 195794, 'timePeriod': '201712070000'},
471+
{'count': 209629, 'timePeriod': '201712060000'},
472+
{'count': 88742, 'timePeriod': '201712050000'},
473+
{'count': 96795, 'timePeriod': '201712040000'},
454474
{'count': 177595, 'timePeriod': '201712030000'},
455475
{'count': 120102, 'timePeriod': '201712020000'},
456-
{'count': 186758, 'timePeriod': '201712010000'},
476+
{'count': 186759, 'timePeriod': '201712010000'},
457477
{'count': 151212, 'timePeriod': '201711300000'},
458478
{'count': 79311, 'timePeriod': '201711290000'},
459479
{'count': 107175, 'timePeriod': '201711280000'},
460480
{'count': 58192, 'timePeriod': '201711270000'},
461481
{'count': 48327, 'timePeriod': '201711260000'},
462-
{'count': 59638, 'timePeriod': '201711250000'},
482+
{'count': 59639, 'timePeriod': '201711250000'},
463483
{'count': 85201, 'timePeriod': '201711240000'},
464-
{'count': 91542, 'timePeriod': '201711230000'},
484+
{'count': 91544, 'timePeriod': '201711230000'},
465485
{'count': 64129, 'timePeriod': '201711220000'},
466486
{'count': 92065, 'timePeriod': '201711210000'},
467487
{'count': 101617, 'timePeriod': '201711200000'},
@@ -471,7 +491,7 @@ Our results are pretty straightforward and can be rapidly used.
471491
{'count': 81849, 'timePeriod': '201711160000'},
472492
{'count': 58423, 'timePeriod': '201711150000'},
473493
{'count': 78004, 'timePeriod': '201711140000'},
474-
{'count': 118078, 'timePeriod': '201711130000'}]
494+
{'count': 118077, 'timePeriod': '201711130000'}]
475495
476496
477497
@@ -505,24 +525,105 @@ method; please see your developer console for details.
505525
506526
.. code:: python
507527
508-
# using unidecode only to
509-
[print(unidecode(tweet.all_text)) for tweet in tweets[0:10]];
528+
# usiing unidecode only to
529+
[print(tweet.all_text) for tweet in tweets[0:10]];
510530
511531
512532
.. parsed-literal::
513533
514534
More clarity on our private information policy and enforcement. Working to build as much direct context into the product too https://t.co/IrwBexPrBA
515-
To 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
535+
To provide more clarity on our private information policy, weve 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
516536
Launching violent groups and hateful images/symbols policy on November 22nd https://t.co/NaWuBPxyO5
517-
We 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
537+
We 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 were implementing before these are published and enforced. See more on our policy development process here 👇 https://t.co/wx3EeH39BI
518538
@WillStick @lizkelley Happy birthday Liz!
519539
Off-boarding advertising from all accounts owned by Russia Today (RT) and Sputnik.
520540
521-
We'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
541+
Were 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
522542
@TMFJMo @anthonynoto Thank you
523543
@gasca @stratechery @Lefsetz letter
524-
@gasca @stratechery Bridgewater's Daily Observations
525-
Yup!!!! [?][?][?][?] #davechappelle https://t.co/ybSGNrQpYF
544+
@gasca @stratechery Bridgewaters Daily Observations
545+
Yup!!!! ❤️❤️❤️❤️ #davechappelle https://t.co/ybSGNrQpYF
526546
@ndimichino Sometimes
527547
Setting up at @CampFlogGnaw https://t.co/nVq8QjkKsf
528548
549+
550+
.. code:: python
551+
552+
premium_search_args.keys()
553+
554+
555+
556+
557+
.. parsed-literal::
558+
559+
dict_keys(['bearer_token', 'endpoint'])
560+
561+
562+
563+
.. code:: python
564+
565+
rule = gen_rule_payload("from:jack",
566+
from_date="2017-09-20",
567+
to_date="2017-10-30",
568+
count_bucket="day",
569+
results_per_call=500)
570+
print(rule)
571+
572+
573+
.. parsed-literal::
574+
575+
{"query":"from:jack","toDate":"201710300000","fromDate":"201709200000","bucket":"day"}
576+
577+
578+
.. code:: python
579+
580+
counts = collect_results(rule, max_results=500, result_stream_args=enterprise_search_args)
581+
582+
.. code:: python
583+
584+
[print(c) for c in counts];
585+
586+
587+
.. parsed-literal::
588+
589+
{'timePeriod': '201710290000', 'count': 0}
590+
{'timePeriod': '201710280000', 'count': 0}
591+
{'timePeriod': '201710270000', 'count': 3}
592+
{'timePeriod': '201710260000', 'count': 6}
593+
{'timePeriod': '201710250000', 'count': 4}
594+
{'timePeriod': '201710240000', 'count': 4}
595+
{'timePeriod': '201710230000', 'count': 0}
596+
{'timePeriod': '201710220000', 'count': 0}
597+
{'timePeriod': '201710210000', 'count': 3}
598+
{'timePeriod': '201710200000', 'count': 2}
599+
{'timePeriod': '201710190000', 'count': 1}
600+
{'timePeriod': '201710180000', 'count': 6}
601+
{'timePeriod': '201710170000', 'count': 2}
602+
{'timePeriod': '201710160000', 'count': 2}
603+
{'timePeriod': '201710150000', 'count': 1}
604+
{'timePeriod': '201710140000', 'count': 64}
605+
{'timePeriod': '201710130000', 'count': 3}
606+
{'timePeriod': '201710120000', 'count': 4}
607+
{'timePeriod': '201710110000', 'count': 8}
608+
{'timePeriod': '201710100000', 'count': 4}
609+
{'timePeriod': '201710090000', 'count': 1}
610+
{'timePeriod': '201710080000', 'count': 0}
611+
{'timePeriod': '201710070000', 'count': 0}
612+
{'timePeriod': '201710060000', 'count': 1}
613+
{'timePeriod': '201710050000', 'count': 3}
614+
{'timePeriod': '201710040000', 'count': 5}
615+
{'timePeriod': '201710030000', 'count': 8}
616+
{'timePeriod': '201710020000', 'count': 5}
617+
{'timePeriod': '201710010000', 'count': 0}
618+
{'timePeriod': '201709300000', 'count': 0}
619+
{'timePeriod': '201709290000', 'count': 0}
620+
{'timePeriod': '201709280000', 'count': 9}
621+
{'timePeriod': '201709270000', 'count': 41}
622+
{'timePeriod': '201709260000', 'count': 13}
623+
{'timePeriod': '201709250000', 'count': 6}
624+
{'timePeriod': '201709240000', 'count': 7}
625+
{'timePeriod': '201709230000', 'count': 3}
626+
{'timePeriod': '201709220000', 'count': 0}
627+
{'timePeriod': '201709210000', 'count': 1}
628+
{'timePeriod': '201709200000', 'count': 7}
629+

0 commit comments

Comments
 (0)