Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pip install wikidata
- >>> from wikidata.client import Client
- >>> client = Client()
- >>> entity = client.get('Q40780', load=True)
- >>> entity
- <wikidata.entity.Entity Q40780 'Acre'>
- >>> entity.description
- m'federated state of Brazil'
- >>> image_prop = client.get('P18')
- >>> image = entity[image_prop]
- >>> image
- <wikidata.commonsmedia.File 'File:Trevo BR-364.2.jpg'>
- >>> image.image_url
- 'https://upload.wikimedia.org/wikipedia/commons/4/41/Trevo_BR-364.2.jpg'
- >>> str(entity).upper()
- ACRE
- >>> shortname_prop = client.get('P1813')
- >>> shortname = entity[shortname_prop]
- >>> str(shortname)
- 'AC'
- >>> demonym_prop = client.get('P1549')
- >>> demonym = entity[demonym_prop]
- >>> str(demonym)
- 'acriano'
- >>> country_prop = client.get('P17')
- >>> country = entity[country_prop]
- >>> str(country.label)
- 'Brazil'
- >>> country.id
- 'Q155'
- >>> capital_prop = client.get('P36')
- >>> capital = entity[capital_prop]
- >>> str(capital.label)
- 'Rio Branco'
- >>> country.id
- 'Q171612'
- >>> flag_prop = client.get('P41')
- >>> flag = entity[flag_prop]
- >>> flag.image_url
- 'https://upload.wikimedia.org/wikipedia/commons/4/4c/Bandeira_do_Acre.svg'
- >>> iso3166_2_prop = client.get('P300')
- >>> iso3166_2 = entity[iso3166_2_prop]
- >>> str(iso3166_2)
- 'BR-AC'
- >>> timezone_prop = client.get('P421')
- >>> timezone = entity[timezone_prop]
- >>> str(timezone.label)
- 'UTC−03:00'
Add Comment
Please, Sign In to add comment