aezzaoui
Messages postés5Date d'inscriptionvendredi 11 février 2022StatutMembreDernière intervention14 janvier 2024
-
12 avril 2022 à 19:45
Utilisateur anonyme -
12 avril 2022 à 22:24
Bonjour,
Je j'ai eu une autre erreur dans mon code,
si quelqu'un pouvait m'aider.
async def dailyword():
while True:
h = int(time.strftime(f"%H",time.localtime()))
m = int(time.strftime(f"%M",time.localtime()))
s = int(time.strftime(f"%S",time.localtime()))
if h == 00 and m == 00 and s == 00:
trans = Translator()
wikipedia.set_lang("fr")
lang = ["fr", "en", "de", "es", ]
dir_date = time.strftime("%d.%m.%Y",time.localtime())
os.makedirs(time.strftime(f"src/daily_word/rec/{dir_date}"))
f = open("./src/daily_word/list_words.txt", "r")
text = f.read()
f.close
f = open("./src/daily_word/total.txt", "r")
total = f.read()
total = int(total)
f.close
f = open("./src/daily_word/total.txt", "w")
f.write(str(total + 1))
f.close
text1 = text.split()
tp_text = text1
word = tp_text[total - 1]
file = open("./src/daily_word/words_trad.txt", "a")
file.write(f"\n[fr] - {word} :")
def_word = wikipedia.summary(word, sentences=1)
file.write(f"[fr] - {def_word}")
x = lang[0]
obj = gTTS(text=word, lang=x, slow=False)
obj.save(time.strftime(f"./src/daily_word/rec/{dir_date}/[{x}] - {word}.mp3"))
x = lang[1]
tr = trans.translate(word,src="fr",dest=x)
file.write(f"\n [{x}] - {tr.text}")
obj = gTTS(text=tr.text, lang=x, slow=False)
obj.save(time.strftime(f"./src/daily_word/rec/{dir_date}/[{x}] - {tr.text}.mp3"))
en = tr.text
x = lang[2]
tr = trans.translate(word,src="fr",dest=x)
file.write(f"\n [{x}] - {tr.text}")
obj = gTTS(text=tr.text, lang=x, slow=False)
obj.save(time.strftime(f"./src/daily_word/rec/{dir_date}/[{x}] - {tr.text}.mp3"))
de = tr.text
x = lang[3]
tr = trans.translate(word,src="fr",dest=x)
file.write(f"\n [{x}] - {tr.text}")
obj = gTTS(text=tr.text, lang=x, slow=False)
obj.save(f"./src/daily_word/rec/{dir_date}/[{x}] - {tr.text}.mp3")
es = tr.text
file.close()
dir_date = time.strftime("%d.%m.%Y",time.localtime())
f = open("./src/daily_word/re_send.txt", "w")
f.write(f"{word}\n{en}\n{de}\n{es}\n{def_word}")
f.close()
dailyword = client.get_channel(f_dailyword)
await dailyword.send(f'@everyone Le mot du jour est "{word}",\nDéfinition : {def_word}\nEn Anglais : {en},\nEn Allemand : {de},\nEn Espagnole : {es}.')
await dailyword.send(file=discord.File(f"./src/daily_word/rec/{dir_date}/[fr] - {word}.mp3"))
await dailyword.send(file=discord.File(f"./src/daily_word/rec/{dir_date}/[en] - {en}.mp3"))
await dailyword.send(file=discord.File(f"./src/daily_word/rec/{dir_date}/[de] - {de}.mp3"))
await dailyword.send(file=discord.File(f"./src/daily_word/rec/{dir_date}/[es] - {es}.mp3"))
f = open(f"./src/daily_word/rec/{dir_date}/text.txt", "a")
f.write(f'Le mot du jour était "{word}",\nDéfinition : {def_word}\nEn Anglais : {en},\nEn Allemand : {de},\nEn Espagnole : {es}.')
f.close
time.sleep(1)
def run_dailyword():
asyncio.run(dailyword())
def bot():
client.run(token)
t1 = threading.Thread(target=bot,)
t2 = threading.Thread(target=run_dailyword,)
t1.start()
t2.start()
t1.join()
t2.join()
erreur :
Exception in thread Thread-2 (run_dailyword):
Traceback (most recent call last):
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "F:\Python\Bots\Zaoui\zaoui.py", line 267, in run_dailyword
asyncio.run(dailyword())
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "F:\Python\Bots\Zaoui\zaoui.py", line 256, in dailyword
await dailyword.send(f'@everyone Le mot du jour est "{word}",\nDéfinition : {def_word}\nEn Anglais : {en},\nEn Allemand : {de},\nEn Espagnole : {es}.')
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\abc.py", line 1065, in send
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\client.py", line 1117, in __aenter__
self._resp = await self._coro
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\client.py", line 448, in _request
with timer:
File "C:\Users\utilisateur\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\helpers.py", line 635, in __enter__
raise RuntimeError(
RuntimeError: Timeout context manager should be used inside a task