Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Zack Beucler
- #https://github.com/ckoepp/TwitterSearch
- #https://pypi.org/project/TwitterSearch/
- '''
- XXXXXXXXXXXXXXXX READ ME XXXXXXXXXXXXXXXX
- - install required packages
- - pip install TwitterSearch
- - Make a developer Account with Twitter (developer.twitter.com) and get your:
- 1. consumer_key
- 2. consumer_secret
- 3. access_token
- 4. access_token_secret
- - Input your four keys ^^^^ into line 36-39 as strings
- '''
- from TwitterSearch import *
- def runSearch(keyword):
- print("-----------------------------------")
- while keyword == "EXIT":
- print("Bye!")
- return
- try:
- tso = TwitterSearchOrder() # create a TwitterSearchOrder object
- tso.set_keywords([keyword]) # let's define all words we would like to have a look for
- tso.set_language('en') # we want to see english tweets only
- 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_key',
- consumer_secret = 'consumer_secret',
- access_token = 'access_token',
- access_token_secret = 'access_token_secret'
- )
- # this is where the API data is collected and sorted for printing
- count = 0
- for tweet in ts.search_tweets_iterable(tso):
- if count == 250:
- print("250 Tweets ==> Max Limit Reached, Program stopping")
- return
- else:
- print( '@%s tweeted: %s' % ( tweet['user']['screen_name'], tweet['text'] ) )
- count = count + 1
- print()
- print("#################################################")
- print()
- print(count, " Total tweets")
- except TwitterSearchException as e: # take care of all those ugly errors if there are some
- print(e)
- ########################################################################################################
- def main():
- keyword = ""
- while keyword != "EXIT":
- print()
- print("TWITTER POST SCRAPPER")
- print("### WARNING ###")
- print("### Popular keywords (EX: IDK) will bring up a fuck ton of results, press control+c to stop the program ### ")
- keyword = input("Please enter a keyword (Type EXIT to leave program): ")
- runSearch(keyword)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement