Fix aiosqlite

This commit is contained in:
Nexus 2024-01-09 09:37:19 +00:00
parent 02e3038baa
commit 548c039494
2 changed files with 18 additions and 11 deletions

View file

@ -4,11 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="aa6d62a8-d64d-4a60-a85f-8d9fa52b6b49" name="Changes" comment="Fix the last few words not being added"> <list default="true" id="aa6d62a8-d64d-4a60-a85f-8d9fa52b6b49" name="Changes" comment="Allow re-use of previous downloads">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/docker-compose.yml" beforeDir="false" afterPath="$PROJECT_DIR$/docker-compose.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cogs/ollama.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cogs/ollama.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/cogs/ytdl.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cogs/ytdl.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/cogs/ytdl.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/cogs/ytdl.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -84,7 +80,7 @@
<workItem from="1704572901106" duration="125000" /> <workItem from="1704572901106" duration="125000" />
<workItem from="1704573038888" duration="7749000" /> <workItem from="1704573038888" duration="7749000" />
<workItem from="1704760229948" duration="946000" /> <workItem from="1704760229948" duration="946000" />
<workItem from="1704790508193" duration="2117000" /> <workItem from="1704790508193" duration="2280000" />
</task> </task>
<task id="LOCAL-00001" summary="Update gitignore"> <task id="LOCAL-00001" summary="Update gitignore">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -254,7 +250,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1704790607299</updated> <updated>1704790607299</updated>
</task> </task>
<option name="localTasksCounter" value="22" /> <task id="LOCAL-00022" summary="Allow re-use of previous downloads">
<option name="closed" value="true" />
<created>1704792896546</created>
<option name="number" value="00022" />
<option name="presentableId" value="LOCAL-00022" />
<option name="project" value="LOCAL" />
<updated>1704792896546</updated>
</task>
<option name="localTasksCounter" value="23" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -283,6 +287,7 @@
<MESSAGE value="Set output to TTY because why not" /> <MESSAGE value="Set output to TTY because why not" />
<MESSAGE value="Fix the space strip and JSON output" /> <MESSAGE value="Fix the space strip and JSON output" />
<MESSAGE value="Fix the last few words not being added" /> <MESSAGE value="Fix the last few words not being added" />
<option name="LAST_COMMIT_MESSAGE" value="Fix the last few words not being added" /> <MESSAGE value="Allow re-use of previous downloads" />
<option name="LAST_COMMIT_MESSAGE" value="Allow re-use of previous downloads" />
</component> </component>
</project> </project>

View file

@ -79,7 +79,7 @@ class YTDLCog(commands.Cog):
""" """
) )
await db.commit() await db.commit()
return aiosqlite.connect("./data/ytdl.db") return
async def save_link(self, message: discord.Message, webpage_url: str, format_id: str, attachment_index: int = 0): async def save_link(self, message: discord.Message, webpage_url: str, format_id: str, attachment_index: int = 0):
""" """
@ -90,7 +90,8 @@ class YTDLCog(commands.Cog):
:param attachment_index: The index of the attachment. Defaults to 0 :param attachment_index: The index of the attachment. Defaults to 0
:return: The created hash key :return: The created hash key
""" """
async with self._init_db() as db: await self._init_db()
async with aiosqlite.connect("./data/ytdl.db") as db:
_hash = hashlib.md5(f"{webpage_url}:{format_id}".encode()) _hash = hashlib.md5(f"{webpage_url}:{format_id}".encode())
await db.execute( await db.execute(
""" """
@ -109,7 +110,8 @@ class YTDLCog(commands.Cog):
:param format_id: The format ID :param format_id: The format ID
:return: the URL, if found and valid. :return: the URL, if found and valid.
""" """
async with self._init_db() as db: await self._init_db()
async with aiosqlite.connect("./data/ytdl.db") as db:
_hash = hashlib.md5(f"{webpage_url}:{format_id}".encode()) _hash = hashlib.md5(f"{webpage_url}:{format_id}".encode())
cursor = await db.execute( cursor = await db.execute(
"SELECT (message_id, channel_id, attachment_index) FROM downloads WHERE key=?", "SELECT (message_id, channel_id, attachment_index) FROM downloads WHERE key=?",