-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_function.py
More file actions
37 lines (32 loc) · 905 Bytes
/
db_function.py
File metadata and controls
37 lines (32 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pymysql
from config import DB_CONFIG
def get_connection():
return pymysql.connect(**DB_CONFIG)
def get_next_frames(anime, limit=2):
conn = get_connection()
try:
with conn.cursor() as cursor:
sql = f"""
SELECT *
FROM {DB_CONFIG['database']}.{anime}
WHERE post_time IS NULL
ORDER BY id ASC
LIMIT {limit}
"""
cursor.execute(sql,)
return cursor.fetchall()
finally:
pass
def mark_posted(anime, frame_id):
conn = get_connection()
try:
with conn.cursor() as cursor:
sql = f"""
UPDATE {DB_CONFIG['database']}.{anime}
SET post_time = NOW()
WHERE id = {frame_id}
"""
cursor.execute(sql,)
conn.commit()
finally:
conn.close()