import urllib.parse import urllib.request import json f2=open("nimekohad.txt", "w") for nimetus in open("nimetused.txt").read().split("\n"): print(nimetus) aadress="https://api.opencagedata.com/geocode/v1/json?q="+urllib.parse.quote(nimetus)+"&key=0aac443c07914e3ca194a63f185bfda0&language=en&pretty=1" tekst=urllib.request.urlopen(aadress).read().decode("utf-8") obj=json.loads(tekst) asukoht=obj["results"][0]["geometry"] f2.write(nimetus+","+str(asukoht["lat"])+","+str(asukoht["lng"])+"\n") f2.close()