Migrate to async_pymongo
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Module that provides all database columns"""
|
||||
|
||||
from pymongo import MongoClient
|
||||
from async_pymongo import AsyncClient
|
||||
from ujson import loads
|
||||
|
||||
with open("config.json", "r", encoding="utf-8") as f:
|
||||
@@ -20,15 +20,9 @@ else:
|
||||
db_config["host"], db_config["port"], db_config["name"]
|
||||
)
|
||||
|
||||
db_client = MongoClient(con_string)
|
||||
db_client = AsyncClient(con_string)
|
||||
db = db_client.get_database(name=db_config["name"])
|
||||
|
||||
collections = db.list_collection_names()
|
||||
|
||||
for collection in ["sent", "users", "submitted"]:
|
||||
if collection not in collections:
|
||||
db.create_collection(collection)
|
||||
|
||||
col_sent = db.get_collection("sent")
|
||||
col_users = db.get_collection("users")
|
||||
col_submitted = db.get_collection("submitted")
|
||||
|
@@ -179,7 +179,7 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
||||
|
||||
del response
|
||||
|
||||
submitted = col_submitted.find_one({"temp.file": media.filename})
|
||||
submitted = await col_submitted.find_one({"temp.file": media.filename})
|
||||
|
||||
if submitted is not None and submitted["caption"] is not None:
|
||||
caption = submitted["caption"].strip()
|
||||
@@ -229,7 +229,7 @@ async def send_content(app: PyroClient, http_session: ClientSession) -> None:
|
||||
# rmtree(path.join(app.config['locations']['tmp'], tmp_dir), ignore_errors=True)
|
||||
return
|
||||
|
||||
col_sent.insert_one(
|
||||
await col_sent.insert_one(
|
||||
{
|
||||
"date": datetime.now(),
|
||||
"image": media.id,
|
||||
|
Reference in New Issue
Block a user