Spaces:
Running
Running
Upload database.py
Browse files- akn/utils/database.py +31 -2
akn/utils/database.py
CHANGED
@@ -1,12 +1,41 @@
|
|
1 |
import datetime
|
2 |
import time
|
3 |
-
|
|
|
4 |
from motor import motor_asyncio
|
5 |
from motor.core import AgnosticClient
|
|
|
|
|
|
|
|
|
6 |
|
|
|
7 |
from akn.utils.logger import LOGS
|
8 |
-
from config import MONGO_URL
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
class Database:
|
12 |
def __init__(self, uri: str) -> None:
|
|
|
1 |
import datetime
|
2 |
import time
|
3 |
+
import markdown
|
4 |
+
import smtplib
|
5 |
from motor import motor_asyncio
|
6 |
from motor.core import AgnosticClient
|
7 |
+
from motor.motor_asyncio import AsyncIOMotorClient
|
8 |
+
|
9 |
+
from email.mime.multipart import MIMEMultipart
|
10 |
+
from email.mime.text import MIMEText
|
11 |
|
12 |
+
from config import *
|
13 |
from akn.utils.logger import LOGS
|
|
|
14 |
|
15 |
+
client_tiktok = AsyncIOMotorClient(MONGO_URL)
|
16 |
+
db_tiktok = client_tiktok["tiktokbot"]
|
17 |
+
otp_collection = db_tiktok["otps"]
|
18 |
+
|
19 |
+
async def send_check_otp_email(receiver_email, text):
|
20 |
+
try:
|
21 |
+
smtp_server = "smtp.gmail.com"
|
22 |
+
port = 587
|
23 |
+
sender_email = ME_GMAIL
|
24 |
+
password = ME_GMAIL_PASSWORD
|
25 |
+
msg = MIMEMultipart()
|
26 |
+
msg['From'] = 'Akeno AI <[email protected]>'
|
27 |
+
msg['To'] = receiver_email
|
28 |
+
msg['Subject'] = "Verified OTP- Akeno AI API"
|
29 |
+
html = markdown.markdown(text)
|
30 |
+
msg.attach(MIMEText(html, 'html'))
|
31 |
+
server = smtplib.SMTP(smtp_server, port)
|
32 |
+
server.starttls()
|
33 |
+
server.login(sender_email, password)
|
34 |
+
server.sendmail(sender_email, receiver_email, msg.as_string())
|
35 |
+
server.quit()
|
36 |
+
logger.info("Email sent successfully!")
|
37 |
+
except Exception:
|
38 |
+
pass
|
39 |
|
40 |
class Database:
|
41 |
def __init__(self, uri: str) -> None:
|