예제 #1
0
def getTweets():	
	trendsList = getTrends()
	searchQuery = trendsList[0] + " OR " + trendsList[1] + " OR " + trendsList[2]
	c = twint.Config()
	c.Username = userName
	c.Search = searchQuery  # AND ,OR, NOT query to search for trends
	c.Format = "{tweet}"
	c.Since = TODAY  # Specify the tweet time (today)
	c.Output = "tweets.txt"
	fileCleaner()
	twint.Search(c)
예제 #2
0
파일: twint.py 프로젝트: yonilevine/twint
def main():
    args = options()
    check(args)
    c = initialize(args)

    if args.favorites:
        twint.Favorites(c)
    elif args.following:
        twint.Following(c)
    elif args.followers:
        twint.Followers(c)
    else:
        twint.Search(c)
예제 #3
0
def main():
	args = options()
	check(args)

	if args.userlist:
		args.username = loadUserList(args.userlist)
		print(args.username)
	
	c = initialize(args)

	if args.favorites:
		twint.Favorites(c)
	elif args.following:
		twint.Following(c)
	elif args.followers:
		twint.Followers(c)
	else:
		twint.Search(c)
예제 #4
0
def twit_get_username(username, result='result.csv', limit=10, count=10):
    try:
        os.remove(result)
    except Exception as e:
        pass

    c = twint.Config()
    #c.Search = "#maling"
    c.Username = username
    c.Format = ""
    c.Debug = False
    c.Store_csv = True
    # CSV Fieldnames
    #following should be used as fieldnames in a list:
    #id,date,time,timezone,user_id,username,tweet,replies,retweets,likes,hashtags,link
    #c.Custom_csv = ["id", "user_id", "username", "tweet"]
    c.Output = result
    c.Limit = limit
    c.Count = count
    # Run
    twint.Search(c)

    df = pd.read_csv(result)
    return df
예제 #5
0
def main():
    ap = argparse.ArgumentParser(
        prog="tw.py",
        usage="python3 %(prog)s [options]",
        description="tw.py - An Advanced Twitter Scraping Tool")
    ap.add_argument("-u",
                    "--username",
                    help="User's Tweets you want to scrape.")
    ap.add_argument("-s",
                    "--search",
                    help="Search for Tweets containing this word or phrase.")
    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("-o", "--output", help="Save output to a file.")
    ap.add_argument("-es", "--elasticsearch", help="Index to Elasticsearch")
    ap.add_argument("-t",
                    "--timedelta",
                    help="Time intervall for every request")
    ap.add_argument("--year", help="Filter Tweets before specified year.")
    ap.add_argument(
        "--since", help="Filter Tweets sent since date (Example: 2017-12-27).")
    ap.add_argument(
        "--until", help="Filter Tweets sent until date (Example: 2017-12-27).")
    ap.add_argument("--fruit",
                    help="Display 'low-hanging-fruit' Tweets.",
                    action="store_true")
    ap.add_argument("--tweets",
                    help="Display Tweets only.",
                    action="store_true")
    ap.add_argument(
        "--verified",
        help="Display Tweets only from verified users (Use with -s).",
        action="store_true")
    ap.add_argument("--users",
                    help="Display users only (Use with -s).",
                    action="store_true")
    ap.add_argument("--csv", help="Write as .csv file.", action="store_true")
    ap.add_argument("--json", help="Write as .json file.", action="store_true")
    ap.add_argument("--hashtags",
                    help="Output hashtags in seperate column.",
                    action="store_true")
    ap.add_argument("--userid", help="Twitter user id")
    ap.add_argument("--limit",
                    help="Number of Tweets to pull (Increments of 20).")
    ap.add_argument(
        "--count",
        help="Display number Tweets scraped at the end of session.",
        action="store_true")
    ap.add_argument("--stats",
                    help="Show number of replies, retweets, and likes",
                    action="store_true")
    ap.add_argument("--database", help="Store tweets in the database")
    ap.add_argument("--to", help="Search Tweets to a user")
    ap.add_argument("--all", help="Search all Tweets associated with a user")
    ap.add_argument("--followers",
                    help="Scrape a person's followers",
                    action="store_true")
    ap.add_argument("--following",
                    help="Scrape who a person follows.",
                    action="store_true")
    ap.add_argument("--favorites",
                    help="Scrape Tweets a user has liked.",
                    action="store_true")
    ap.add_argument("--debug", help="Debug mode", action="store_true")
    args = ap.parse_args()

    if args.username is not None:
        if args.users:
            error("Contradicting Args",
                  "Please use --users in combination with -s.")
        if args.verified:
            error("Contradicting Args",
                  "Please use --verified in combination with -s.")
        if args.userid:
            error("Contradicting Args",
                  "--userid and -u cannot be used together.")
    if args.tweets and args.users:
        error("Contradicting Args",
              "--users and --tweets cannot be used together.")
    if args.csv and args.output is None:
        error("Error", "Please specify an output file (Example: -o file.csv).")

    c = twint.Config()
    c.Username = args.username
    c.User_id = args.userid
    c.Search = args.search
    c.Geo = args.geo
    c.Lang = args.lang
    c.Output = args.output
    c.Elasticsearch = args.elasticsearch
    c.Timedelta = args.timedelta
    c.Year = args.year
    c.Since = args.since
    c.Until = args.until
    c.Fruit = args.fruit
    c.Verified = args.verified
    c.Store_csv = args.csv
    c.Store_json = args.json
    c.Show_hashtags = args.hashtags
    c.Tweets_only = args.tweets
    c.Users_only = args.users
    c.Limit = args.limit
    c.Count = args.count
    c.Stats = args.stats
    c.Database = args.database
    c.To = args.to
    c.All = args.all
    c.Debug = args.debug

    if args.favorites:
        twint.Favorites(c)
    elif args.following:
        twint.Following(c)
    elif args.followers:
        twint.Followers(c)
    else:
        twint.Search(c)
예제 #6
0
            print(Fore.GREEN +
                  "\n\nTweets will be saved to the file in plain text\n\n" +
                  Fore.BLUE)
            sys.stdout = open(twint_tweets_savefile, "w")
            twint.run.Search(twintvariable)

            sys.stdout.close()

            sys.stdout = stdout_fileno

        elif (twint_search_option == "4"):

            twintvariable = twint.Config()
            twint_username_option4 = input("Keyword: ")
            twintvariable.Username = twint_username_option4
            twintsearchvar = twint.Search(twint_username_option4)
            twintvariable.Limit = 10

            twint.run.Search(twintvariable)

            sys.stdout.close()

            sys.stdout = stdout_fileno

        print()

        print(Fore.RED)

    ####################################
    #########youtube downloader#########
    ####################################
예제 #7
0
#Print a clean list of all trends
print(allTrends)

# get all tweets for a specific user (also using a specific hashtags)
c = twint.Config()
c.Username = "******"
c.Search = "#hahaha"  #Seach for specific hashtag name. In this case it used the trending list to fetsh for that specific hashtag. you can also search for multiple hashtags using advance query
'''
Options:
	id = ""
	date = ""
	datestamp = ""
	time = ""
	timestamp = ""
	timezone = ""
	user_id = ""
	username = ""
	tweet = "" # Text
	replies = "0"
	likes = "0"
	retweets = "0"
	hashtags = ""
	location = ""
'''

c.Format = "{tweet}"

# Run
twint.Search(c)