Skip to content
Snippets Groups Projects
Commit 5622cf94 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

get sounds urls

parent 20b5b9a8
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ class En_en_straktor(Wikstraktor): ...@@ -17,7 +17,7 @@ class En_en_straktor(Wikstraktor):
self.wiki_language = "en" self.wiki_language = "en"
self.entry_language = "en" self.entry_language = "en"
self.constants = string_values self.constants = string_values
self.site = self.pwb.Site(f'wiktionary:{self.wiki_language}') self.site = self.pwb.Site(f'wiktionary:en')
def process_pronunciation(self, proContent): def process_pronunciation(self, proContent):
l = proContent.get_lists()[0] l = proContent.get_lists()[0]
...@@ -36,7 +36,7 @@ class En_en_straktor(Wikstraktor): ...@@ -36,7 +36,7 @@ class En_en_straktor(Wikstraktor):
p.set_transcription(t.arguments[1].value) p.set_transcription(t.arguments[1].value)
print(t, t.arguments, t.arguments[0].value) print(t, t.arguments, t.arguments[0].value)
elif t.normal_name() == self.constants['t_snd']: elif t.normal_name() == self.constants['t_snd']:
p.add_sound(t.arguments[1].value) p.add_sound(self.get_file_url(t.arguments[1].value))
print(t, t.arguments, t.arguments[1].value) print(t, t.arguments, t.arguments[1].value)
pronunciations.append(p) pronunciations.append(p)
i += 1 i += 1
......
#!/usr/bin/env python3 #!/usr/bin/env python3
class Sound:
def __init__(self, url, accent):
self.url = url
self.accent = accent
def serializable(self):
if self.accent == None:
res = {"url":self.url}
else:
res = {"accent":self.accent, "url":self.url}
return res
class Pronunciation: class Pronunciation:
def __init__(self): def __init__(self):
self.ipa = None self.ipa = None
self.sounds = [] self.sounds = []
self.accent = None
def set_transcription(self, tscpt): def set_transcription(self, tscpt):
self.ipa = tscpt self.ipa = tscpt
def add_sound(self, url): def set_accent(self, accent):
self.sounds.append(url) self.accent = accent
def add_sound(self, url, accent=None):
self.sounds.append(Sound(url,accent))
def serializable(self): def serializable(self):
return {"transcript":self.ipa, "sounds":self.sounds} snds = []
for s in self.sounds:
snds.append(s.serializable())
return {"transcript":self.ipa, "sounds":snds}
def __str__(self): def __str__(self):
return f"{self.serializable()}" return f"{self.serializable()}"
...@@ -21,6 +21,15 @@ class Wikstraktor: ...@@ -21,6 +21,15 @@ class Wikstraktor:
instance = None instance = None
return instance return instance
def get_file_url(self, file_page_name):
res = None
try:
f = self.pwb.FilePage(self.site, file_page_name)
res = f.get_file_url()
except pywikibot.exceptions.NoPageError:
print(f"{file_page_name} does not exist in {self.site}.")
return res
def __init__(self): def __init__(self):
self.entries = [] self.entries = []
self.pwb = pywikibot self.pwb = pywikibot
...@@ -58,6 +67,15 @@ class Wikstraktor: ...@@ -58,6 +67,15 @@ class Wikstraktor:
if __name__ == "__main__": if __name__ == "__main__":
e = Wikstraktor.get_instance('en', "en") e = Wikstraktor.get_instance('en', "en")
print(e.get_file_url("File:LL-Q1860 (eng)-Nattes à chat----parent.wav"))
print(e.get_file_url("File:LL-Q1860 (eng)-Nattes à chat-parent.wav"))
print(e.fetch("test"), "entries added") print(e.fetch("test"), "entries added")
# site = pywikibot.Site(f'wiktionary:en')
# p = pywikibot.FilePage(site, "File:LL-Q1860 (eng)-Nattes à chat----parent.wav")
# print(p)
# if not p.exists():
# site = pywikibot.Site('commons')
# p = pywikibot.FilePage(site, "File:LL-Q1860 (eng)-Nattes à chat-parent.wav")
# print(p.get_file_url())
#print(e) #print(e)
#Entry("test", wtp.parse(page.text))) #Entry("test", wtp.parse(page.text)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment