Saturday, November 16, 2024
Google search engine
HomeLanguagesPython – Place object in Tweepy

Python – Place object in Tweepy

Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.

Place

The Place object in Tweepy module contains the information about a place.

Here are the list of attributes in the Place object :

  • id : The ID of the place.
  • url : The URL representing the location of the place.
  • place_type : The type of location represented by the place.
  • name : The name of the place.
  • full_name : The full name of the place.
  • country_code : The code of the country of the place.
  • country : The name of the country of the place.
  • contained_within : A Place object containing the place.
  • geometry : The geometry of the place.
  • polylines : The polylines of the place.
  • centroid : The centroid of the place.
  • bounding_box : The coordinates which encloses the place.

Example : Use geo_id() method to fetch the place. Consider the city of London.




# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# Twitter ID of London 
id = "457b4814b4240d87"
    
# fetching the location 
place = api.geo_id(id
    
# printing the information 
print("The id is : " + place.id)
print("The url is : " + place.url)
print("The place_type is : " + place.place_type)
print("The name is : " + place.name)
print("The full_name is : " + place.full_name)
print("The country_code is : " + place.country_code)
print("The country is : " + place.country)
print("The contained_within is : " + str(place.contained_within))
print("The geometry is : " + str(place.geometry))
print("The polylines are : " + str(place.polylines))
print("The centroid is : " + str(place.centroid))
print("The bounding_box is : " + str(place.bounding_box))


Output :

The id is : 457b4814b4240d87
The url is : https://api.twitter.com/1.1/geo/id/457b4814b4240d87.json
The place_type is : city
The name is : London
The full_name is : London, England
The country_code is : GB
The country is : United Kingdom
The contained_within is : [Place(_api=, id=’1090d3ced4b75d04′, url=’https://api.twitter.com/1.1/geo/id/1090d3ced4b75d04.json’, place_type=’admin’, name=’London’, full_name=’London’, country_code=’GB’, country=’United Kingdom’, centroid=[0.07110233274688144, 51.5989395], bounding_box=BoundingBox(_api=, type=’Polygon’, coordinates=[[[-0.853907, 51.105205], [-0.853907, 52.092674], [0.958128, 52.092674], [0.958128, 51.105205], [-0.853907, 51.105205]]]), attributes={})]
The geometry is : None
The polylines are : []
The centroid is : [-0.14032122753075282, 51.50009175]
The bounding_box is : BoundingBox(_api=, type=’Polygon’, coordinates=[[[-0.187894, 51.483718], [-0.187894, 51.5164655], [-0.109978, 51.5164655], [-0.109978, 51.483718], [-0.187894, 51.483718]]])

Last Updated :
03 Jul, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments