Building on yesterday’s fun with Twython, today I looked to expand my Python program (temporary commentating out the option to post a tweet) with an option to search Tweets for a keyword.
Twython brings back a lot of data in its results so I have used the JSON knowledge I got making my NASA NEOΒ Python program to limit what data my Twitter Search program returned.

# geektechstuff
# Twitter Application
from twython import Twython
#Twython is a Twitter Python library
#imports the Twitter API keys
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
# This posts Tweets
# message = "geektechstuff.com Test Tweet aka /'Hello World!/'"
# twitter.update_status(status=message)
# print("Tweeted: %s" % message)
# This searches Tweets
print('GeekTechStuff Twitter Search Python Program')
print('')
search_term = input('What word should I look for? ')
results = twitter.cursor(twitter.search, q=search_term)
print('')
print('Searching Twitter...')
print('')
for result in results:
name = result['user']
screen_name = name['screen_name']
creation_date = result['created_at']
tweet_txt = result['text']
print('Twitter User:', screen_name)
print('Posted:')
print(tweet_txt)
print('at:')
print(creation_date)
print('')
If you want to read up on Twython, check outΒ https://twython.readthedocs.io/en/latest/





2 responses to “Twitter Search (Python)”
Nice post. I will try out something similar in near future so itβs useful to see a similar project. π
One recommendation: You can just add \n to start and/or end in stead of typing print(ββ)
I would also use .format() in stead of %, but I guess is my personal choice
Thanks again for the post! π
LikeLiked by 1 person
[…] so my last post dealt with searching with Twython and this lead to me to thinking; what about replying to tweets […]
LikeLike