locallingua_pt / download_locallingua.py
Jarbas's picture
Upload 165 files
a065542 verified
import os
import requests
regids = {'Aveiro': 3404,
'Azores': 3402,
'Beja': 3407,
'Braga': 3413,
'Bragança': 3414,
'Castelo Branco': 3415,
'Coimbra': 3416,
'Faro': 3409,
'Guarda': 3417,
'Leiria': 3405,
'Lisboa': 3410,
'Madeira': 3403,
'Portalegre': 3411,
'Porto': 3418,
'Santarém': 3412,
'Setúbal': 3401,
'Viana do Castelo': 3406,
'Vila Real': 3420,
'Viseu': 3419,
'Évora': 3408}
# u = "https://localingual.com/data/getregionsbycountry"
# regions = requests.post(u, data={"countryCode": "PT"})
# for code, region in regions.json().items():
# if not region.get('HasSounds'):
# continue
# regids[region["Name"]] = region["Id"]
csv = "file_name,gender,region,text"
for reg, regid in regids.items():
data = dict(countryId=172,
regionId=regid,
# placeId,
languageId=359,
amount=12,
skip=0,
sort="top",
fingerprint=2306608879)
d = requests.post("https://localingual.com/data/getphrases", data=data)
for e in d.json():
# pprint(e)
fname = e["URL"]
url = "https://localingualstor.blob.core.windows.net/sounds/" + fname
gender = e["Sex"]
text = e["NativeText"].replace(",", "")
l = e["LanguageExo"]
if l != "Portuguese":
continue
csv += f"\n{fname},{gender},{reg},{text}"
if not os.path.isfile(f"{os.path.dirname(__file__)}/data/{fname}"):
with open(f"{os.path.dirname(__file__)}/data/{fname}", "wb") as f:
f.write(requests.get(url).content)
with open(f"{os.path.dirname(__file__)}/metadata.csv", "w") as f:
f.write(csv)