|
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} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
csv = "file_name,gender,region,text" |
|
for reg, regid in regids.items(): |
|
data = dict(countryId=172, |
|
regionId=regid, |
|
|
|
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(): |
|
|
|
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) |
|
|