Commit 1cb40f0c authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

Add retweets option

parent a7274069
#!/usr/bin/python3 #!/usr/bin/python3
''' '''
Twint.py - Twitter Intelligence (formerly known as Tweep). Twint.py - Twitter Intelligence Tool (formerly known as Tweep).
Written by Cody Zacharias (@now)
Special thanks to @hpiedcoq & @pielco11 for contributing
several search and storing options.
See wiki on Github for in-depth details. See wiki on Github for in-depth details.
https://github.com/haccer/twint/wiki https://github.com/haccer/twint/wiki
...@@ -18,148 +14,154 @@ import sys ...@@ -18,148 +14,154 @@ import sys
import os import os
def error(error, message): def error(error, message):
print("[-] {}: {}".format(error, message)) print("[-] {}: {}".format(error, message))
sys.exit(0) sys.exit(0)
def check(args): def check(args):
if args.username is not None: # Error checking
if args.users: if args.username is not None:
error("Contradicting Args", "Please use --users in combination with -s.") if args.users:
if args.verified: error("Contradicting Args",
error("Contradicting Args", "Please use --verified in combination with -s.") "Please use --users in combination with -s.")
if args.userid: if args.verified:
error("Contradicting Args", "--userid and -u cannot be used together.") error("Contradicting Args",
if args.tweets and args.users: "Please use --verified in combination with -s.")
error("Contradicting Args", "--users and --tweets cannot be used together.") if args.userid:
if args.csv and args.output is None: error("Contradicting Args",
error("Error", "Please specify an output file (Example: -o file.csv).") "--userid and -u cannot be used together.")
if args.proxy_host is not None: if args.tweets and args.users:
if args.proxy_host.lower() == "tor": error("Contradicting Args", "--users and --tweets cannot be used together.")
import socks, socket if args.csv and args.output is None:
socks.set_default_proxy(socks.SOCKS5, "localhost", 9050) error("Error", "Please specify an output file (Example: -o file.csv).")
socket.socket = socks.socksocket if args.proxy_host is not None:
elif args.proxy_port and args.proxy_type: if args.proxy_host.lower() == "tor":
if args.proxy_type.lower() == "socks5": import socks, socket
_type = socks.SOCKS5 socks.set_default_proxy(socks.SOCKS5, "localhost", 9050)
elif args.proxy_type.lower() == "socks4": socket.socket = socks.socksocket
_type = socks.SOCKS4 elif args.proxy_port and args.proxy_type:
elif args.proxy_type.lower() == "http": if args.proxy_type.lower() == "socks5":
_type = socks.HTTP _type = socks.SOCKS5
else: elif args.proxy_type.lower() == "socks4":
error("Error", "Proxy type allowed are: socks5, socks4 and http.") _type = socks.SOCKS4
import socks, socket elif args.proxy_type.lower() == "http":
socks.set_default_proxy(_type, args.proxy_host, int(args.proxy_port)) _type = socks.HTTP
socket.socket = socks.socksocket else:
else: error("Error", "Proxy types allowed are: socks5, socks4, and http.")
error("Error", "Please specify --proxy-host, --proxy-port and --proxy-type") import socks, socket
else: socks.set_default_proxy(_type, args.proxy_host, int(args.proxy_port))
if args.proxy_port or args.proxy_type: socket.socket = socks.socksocket
error("Error", "Please specify --proxy-host, --proxy-port and --proxy-type") else:
error("Error", "Please specify --proxy-host, --proxy-port, and --proxy-type")
else:
if args.proxy_port or args.proxy_type:
error("Error", "Please specify --proxy-host, --proxy-port, and --proxy-type")
def loadUserList(ul): def loadUserList(ul):
if os.path.exists(os.path.abspath(ul)): if os.path.exists(os.path.abspath(ul)):
userlist = open(os.path.abspath(ul), "r").read().splitlines() userlist = open(os.path.abspath(ul), "r".read().splitlines())
else: else:
userlist = ul.split(",") userlist = ul.split(",")
un = "" un = ""
for user in userlist: for user in userlist:
un += "%20OR%20from%3A" + user un += "%20OR%20from%3A" + user
return un[15:] return un[15:]
def initialize(args): def initialize(args):
c = twint.Config() c = twint.Config()
c.Username = args.username c.Username = args.username
c.User_id = args.userid c.User_id = args.userid
c.Search = args.search c.Search = args.search
c.Geo = args.geo c.Geo = args.geo
c.Location = args.location c.Location = args.location
c.Near = args.near c.Near = args.near
c.Lang = args.lang c.Lang = args.lang
c.Output = args.output c.Output = args.output
c.Elasticsearch = args.elasticsearch c.Elasticsearch = args.elasticsearch
c.Timedelta = args.timedelta c.Timedelta = args.timedelta
c.Year = args.year c.Year = args.year
c.Since = args.since c.Since = args.since
c.Until = args.until c.Until = args.until
c.Fruit = args.fruit c.Fruit = args.fruit
c.Verified = args.verified c.Verified = args.verified
c.Store_csv = args.csv c.Store_csv = args.csv
c.Store_json = args.json c.Store_json = args.json
c.Show_hashtags = args.hashtags c.Show_hashtags = args.hashtags
c.Tweets_only = args.tweets c.Tweets_only = args.tweets
c.Users_only = args.users c.Users_only = args.users
c.Limit = args.limit c.Limit = args.limit
c.Count = args.count c.Count = args.count
c.Stats = args.stats c.Stats = args.stats
c.Database = args.database c.Database = args.database
c.To = args.to c.To = args.to
c.All = args.all c.All = args.all
c.Debug = args.debug #c.Debug = args.debug
c.Proxy_type = args.proxy_type c.Essid = args.essid
c.Proxy_host = args.proxy_host return c
c.Proxy_port = args.proxy_port
c.Essid = args.essid
c.Userlist = args.userlist
return c
def options(): def options():
ap = argparse.ArgumentParser(prog="twint.py", usage="python3 %(prog)s [options]", description="TWINT - An Advanced Twitter Scraping Tool") ap = argparse.ArgumentParser(prog="Twint.py",
ap.add_argument("-u", "--username", help="User's Tweets you want to scrape.") usage="python3 %(prog)s [options]",
ap.add_argument("-s", "--search", help="Search for Tweets containing this word or phrase.") description="TWINT - An Advanced Twitter Scraping Tool.")
ap.add_argument("-g", "--geo", help="Search for geocoded tweets.") ap.add_argument("-u", "--username", help="User's Tweets you want to scrape.")
ap.add_argument("--near", help="Near a specified city.") ap.add_argument("-s", "--search", help="Search for Tweets containing this word or phrase.")
ap.add_argument("--location", help="Show user's location (Experimental).", action="store_true") ap.add_argument("-g", "--geo", help="Search for geocoded Tweets.")
ap.add_argument("-l", "--lang", help="Serch for Tweets in a specific language") ap.add_argument("--near", help="Near a specified city.")
ap.add_argument("-o", "--output", help="Save output to a file.") ap.add_argument("--location", help="Show user's location (Experimental).", action="store_true")
ap.add_argument("-es", "--elasticsearch", help="Index to Elasticsearch") ap.add_argument("-l", "--lang", help="Search for Tweets in a specific language.")
ap.add_argument("-t", "--timedelta", help="Time interval for every request") ap.add_argument("-o", "--output", help="Save output to a file.")
ap.add_argument("--year", help="Filter Tweets before specified year.") ap.add_argument("-es", "--elasticsearch", help="Index to Elasticsearch.")
ap.add_argument("--since", help="Filter Tweets sent since date (Example: 2017-12-27).") ap.add_argument("-t", "--timedelta", help="Time interval for every request.")
ap.add_argument("--until", help="Filter Tweets sent until date (Example: 2017-12-27).") ap.add_argument("--year", help="Filter Tweets before specified year.")
ap.add_argument("--fruit", help="Display 'low-hanging-fruit' Tweets.", action="store_true") ap.add_argument("--since", help="Filter Tweets sent since date (Example: 2017-12-27).")
ap.add_argument("--tweets", help="Display Tweets only.", action="store_true") ap.add_argument("--until", help="Filter Tweets sent until date (Example: 2017-12-27).")
ap.add_argument("--verified", help="Display Tweets only from verified users (Use with -s).", action="store_true") ap.add_argument("--fruit", help="Display 'low-hanging-fruit' Tweets.", action="store_true")
ap.add_argument("--users", help="Display users only (Use with -s).", action="store_true") ap.add_argument("--tweets", help="Display Tweets only.", action="store_true")
ap.add_argument("--csv", help="Write as .csv file.", action="store_true") ap.add_argument("--verified", help="Display Tweets only from verified users (Use with -s).",
ap.add_argument("--json", help="Write as .json file.", action="store_true") action="store_true")
ap.add_argument("--hashtags", help="Output hashtags in seperate column.", action="store_true") ap.add_argument("--users", help="Display users only (Use with -s).", action="store_true")
ap.add_argument("--userid", help="Twitter user id") ap.add_argument("--csv", help="Write as .csv file.", action="store_true")
ap.add_argument("--limit", help="Number of Tweets to pull (Increments of 20).") ap.add_argument("--json", help="Write as .json file", action="store_true")
ap.add_argument("--count", help="Display number Tweets scraped at the end of session.", action="store_true") ap.add_argument("--hashtags", help="Output hashtags in seperate column.", action="store_true")
ap.add_argument("--stats", help="Show number of replies, retweets, and likes", action="store_true") ap.add_argument("--userid", help="Twitter user id.")
ap.add_argument("--database", help="Store tweets in the database") ap.add_argument("--limit", help="Number of Tweets to pull (Increments of 20).")
ap.add_argument("--to", help="Search Tweets to a user") ap.add_argument("--count", help="Display number of Tweets scraped at the end of session.",
ap.add_argument("--all", help="Search all Tweets associated with a user") action="store_true")
ap.add_argument("--followers", help="Scrape a person's followers", action="store_true") ap.add_argument("--stats", help="Show number of replies, retweets, and likes.", action="store_true")
ap.add_argument("--following", help="Scrape who a person follows.", action="store_true") ap.add_argument("-db", "--database", help="Store Tweets in a sqlite3 database.")
ap.add_argument("--favorites", help="Scrape Tweets a user has liked.", action="store_true") ap.add_argument("--to", help="Search Tweets to a user.")
ap.add_argument("--debug", help="Debug mode", action="store_true") ap.add_argument("--all", help="Search all Tweets associated with a user.")
ap.add_argument("--proxy-type", help="Socks5, HTTP, etc.") ap.add_argument("--followers", help="Scrape a person's followers.", action="store_true")
ap.add_argument("--proxy-host", help="Proxy hostname or IP.") ap.add_argument("--following", help="Scrape a person's follows", action="store_true")
ap.add_argument("--proxy-port", help="The port of the proxy server.") ap.add_argument("--favorites", help="Scrape Tweets a user has liked.", action="store_true")
ap.add_argument("--essid", help="Elasticsearch Session ID, use this to differentiate scraping sessions.") # ap.add_argument("--debug", help="Debug mode", action="store_true")
ap.add_argument("--userlist", help="Userlist from list or file.") ap.add_argument("--proxy-type", help="Socks5, HTTP, etc.")
args = ap.parse_args() ap.add_argument("--proxy-host", help="Proxy hostname or IP.")
return args ap.add_argument("--proxy-port", help="The port of the proxy server.")
ap.add_argument("--essid", help="Elasticsearch Session ID, use this to differentiate scraping sessions.")
ap.add_argument("--userlist", help="Userlist from list or file.")
ap.add_argument("--retweets", help="Include user's Retweets (Warning: limited).", action="store_true")
args = ap.parse_args()
return args
def main(): def main():
args = options() args = options()
check(args) check(args)
if args.userlist:
args.username = loadUserList(args.userlist)
if args.userlist: c = initialize(args)
args.username = loadUserList(args.userlist)
c = initialize(args)
if args.favorites: if args.favorites:
twint.Favorites(c) twint.Favorites(c)
elif args.following: elif args.following:
twint.Following(c) twint.Following(c)
elif args.followers: elif args.followers:
twint.Followers(c) twint.Followers(c)
else: elif args.retweets:
twint.Search(c) twint.Profile(c)
else:
twint.Search(c)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment