Difference between revisions of "Python: TwitterSearch"

From OnnoWiki
Jump to navigation Jump to search
Line 54: Line 54:
 
  # it's about time to create a TwitterSearch object with our secret tokens
 
  # it's about time to create a TwitterSearch object with our secret tokens
 
  ts = TwitterSearch(
 
  ts = TwitterSearch(
     consumer_key = '',
+
     consumer_key = ' ',
     consumer_secret = '',
+
     consumer_secret = ' ',
     access_token = '',
+
     access_token = ' ',
     access_token_secret = ''
+
     access_token_secret = ' '
 
     )
 
     )
 
   
 
   
Line 71: Line 71:
 
  @onnowpurbo tweeted: openwrt dulunya utk router, cuma dengan kemampuan yang ada bisa utk macem2 :) .. https://t.co/3VZgng1RLd
 
  @onnowpurbo tweeted: openwrt dulunya utk router, cuma dengan kemampuan yang ada bisa utk macem2 :) .. https://t.co/3VZgng1RLd
 
  @onnowpurbo tweeted: bisa diskusi via email onno@indo.net.id, beraba besar komunitas pulpstone? https://t.co/GEksxU49Zy
 
  @onnowpurbo tweeted: bisa diskusi via email onno@indo.net.id, beraba besar komunitas pulpstone? https://t.co/GEksxU49Zy
 
  
 
==Referensi==
 
==Referensi==

Revision as of 08:58, 28 January 2017

Instalasi

pip install TwitterSearch

atau

easy_install TwitterSearch


Search Twitter

Contoh search Everybody knows how much work it is to study at a university. So why not take a small shortcut? So in this example we assume we would like to find out how to copy a doctorate thesis in Germany. Let’s have a look what the Twitter users have to say about Mr Guttenberg.

from TwitterSearch import *

tso = TwitterSearchOrder() # create a TwitterSearchOrder object
keywords=("ahok","anies","sylv")
tso.set_keywords(keywords, or_operator=True)
tso.set_language('id') # bahasa Indonesia saja
tso.set_include_entities(False) # and don't give us all those entity information
 
# it's about time to create a TwitterSearch object with our secret tokens
ts = TwitterSearch(
    consumer_key = ' ',
    consumer_secret = ' ',
    access_token = ' ',
    access_token_secret = ' '
    )

# this is where the fun actually starts :)
for tweet in ts.search_tweets_iterable(tso):
    print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )

Hasilnya kira-kira sebagai berikut,

@Babannic2 tweeted: RT @Beritasatu: Pendeta Stephen Tong Sebut Jokowi dan Ahok Tipe Pemimpin Antikorupsi https://t.co/YJomhnXBVW
@JSJkrysx tweeted: Sekjen PDIP: Ahok-Djarot Konkret, Paslon Lain Retorika https://t.co/Vs6KKYSHiV
@FirmanRenold tweeted: RT @jokoanwar: “Rakyat adalah BOS kami. Kami adalah pelayan rakyat.” —Ahok https://t.co/cKkR3kOcbK
@Takviri tweeted: RT @AtunSumiatun: Ahok bermain tanpa beban. https://t.co/uyRBQ3j0aS
@NKRIndonesia79 tweeted: Siapapun yang "melawan" Ahok pasti jadi salah? Sepertinya iya... https://t.co/gPyn8HpnkP
@antonkerenz1 tweeted: RT @mantriss: Wah hebat pendukung Pak Ahok bicara kesopanan .... Semoga betul2 sudah berubah.... 😃😃 https://t.co/sh1DDadg5K
@tom_psp tweeted: RT @Beritasatu: #PopulerB1 1: Diajak Sandi Keroyok Ahok, Sylvi Tak Paham https://t.co/0KxkEgr8NJ https://t.co/CGj6qVUHvJ

Access User Timelines

Alternatif lain adalah mengakses timeline seorang user saja, caranya,

from TwitterSearch import *

tuo = TwitterUserOrder('onnowpurbo') # create a TwitterUserOrder

# it's about time to create a TwitterSearch object with our secret tokens
ts = TwitterSearch(
    consumer_key = ' ',
    consumer_secret = ' ',
    access_token = ' ',
    access_token_secret = ' '
    )

# start asking Twitter about the timeline
for tweet in ts.search_tweets_iterable(tuo):
	print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )

Hasilnya kira-kira,

@onnowpurbo tweeted: alhamdulillah :) ...  https://t.co/JRQotgThNF
@onnowpurbo tweeted: keren! ... https://t.co/xuCqpVJMAd
@onnowpurbo tweeted: sama2 lihat aktifitas di pulpstone kayanya menarik nih .. https://t.co/PN3nnf0ztW
@onnowpurbo tweeted: openwrt dulunya utk router, cuma dengan kemampuan yang ada bisa utk macem2 :) .. https://t.co/3VZgng1RLd
@onnowpurbo tweeted: bisa diskusi via email onno@indo.net.id, beraba besar komunitas pulpstone? https://t.co/GEksxU49Zy

Referensi