How to use the twitterapi.download_user_tweets function in TwitterAPI

To help you get started, we’ve selected a few TwitterAPI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github afshinrahimi / pigeo / pigeo.py View on Github external
def geo_twitter(twitter_screen_name, return_lbl_dist=False):
	"""
	given a twitter id or screen_name, retrieves the top 100 tweets of the user, extracts the text, vectorizes it, classifies it into one of the regions using 
	clf (a pre-trained classifier) and returns a json which has info about the predicted location(s).
	Note that internet connection is required and authentication information should be set in twitterapi.py.
	
	Args:
		twitter_screen_name (str): Twitter user id or screen_name
	Returns:
		a dictionary including information about the predicted location of the user given the content of their tweets.
	"""
	from twitterapi import download_user_tweets
	timeline = []
	timeline = download_user_tweets(twitter_screen_name, count=100)
	if timeline:
		text = ' '.join([t.text for t in timeline])
	else:
		text = ' '
	return geo(text, return_lbl_dist)
github afshinrahimi / pigeo / pigeo.py View on Github external
the @-mentions are extracted and an ego graph for the user is built.
	The neighbors (@-mentions) of the user are matched with geolocated
	users of the WORLD dataset (Han et. al, 2012) and their locations
	are set if any matches are found.
	The user is then geolocated using the locations of its neighbours.
	The geolocation algorithm is based on real-valued label propagation (Rahimi et. al, 2015).
	
	Args:
		twitter_user (str): a Twitter screen/id.
		return_address : if True the predicted coordinates are mapped to an address using geopy. Default (False).
	Returns:
		a dictionary with location information
	"""
	load_lpmodel(lpmodel_file)
	from twitterapi import download_user_tweets
	timeline = download_user_tweets(twitter_user, count=200)
	text = ' '.join([t.text for t in timeline])
	#pattern for @mentions
	token_pattern = '(?<=^|(?<=[^a-zA-Z0-9-_\\.]))@([A-Za-z]+[A-Za-z0-9_]+)'
	token_pattern = re.compile(token_pattern)
	mentions = [m.lower() for m in token_pattern.findall(text)]
	mention_hashes = [hashlib.md5(m).hexdigest() for m in mentions]
	neighbour_coordinates = []
	for mention_hash in mention_hashes:
		if mention_hash in params.userhash_coordinate:
			coordinate = params.userhash_coordinate[mention_hash]
			neighbour_coordinates.append(coordinate)
	
	#no match found, unable to geolocate
	if len(neighbour_coordinates) == 0:
		return