philipcraigt
Joined: 12/08/2024 06:41:42
Messages: 1
Offline
|
python
Sao chép mã
import requests
def fetch_children(geoname_id, username, max_rows=10):
url = "http://api.geonames.org/childrenJSON"
results = []
start = 0
while True:
response = requests.get(url, params={
'geonameId': geoname_id,
'username': username,
'start': start,
'maxRows': max_rows
})
data = response.json()
children = data.get('geonames', [])
results.extend(children)
if len(children) < max_rows:
break
start += max_rows
return results
# Example usage
username = 'YOUR_USERNAME'
geoname_id = '123456'
children = fetch_children(geoname_id, username)
print(children)
|