瀏覽代碼

https://github.com/openNAMU/openNAMU/issues/1396

잉여개발기 (SPDV) 2 年之前
父節點
當前提交
b4f99444a9
共有 3 個文件被更改,包括 24 次插入2 次删除
  1. 21 0
      route/tool/func.py
  2. 1 0
      route/vote_close.py
  3. 2 2
      route/vote_select.py

+ 21 - 0
route/tool/func.py

@@ -412,14 +412,35 @@ def do_ban_end():
         curs = conn.cursor()
 
         curs.execute(db_change("update rb set ongoing = '' where end < ? and end != '' and ongoing = '1'"), [get_time()])
+        conn.commit()
 
         threading.Timer(60, do_ban_end).start()
 
+def do_vote_end():
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+    
+        curs.execute(db_change('select id, type from vote where type = "open" or type = "n_open"'))
+        for for_a in curs.fetchall():
+            curs.execute(db_change('select data from vote where id = ? and name = "end_date" and type = "option"'), [for_a[0]])
+            db_data = curs.fetchall()
+            if db_data:
+                time_db = db_data[0][0].split()[0]
+                time_today = get_time().split()[0]
+
+                if time_today > time_db:
+                    curs.execute(db_change("update vote set type = ? where user = '' and id = ? and type = ?"), ['close' if for_a[1] == 'open' else 'n_close', for_a[0], for_a[1]])
+
+        conn.commit()
+
+        threading.Timer(60 * 60 * 24, do_ban_end).start()
+
 def auto_do_something(data_db_set):
     if data_db_set['type'] == 'sqlite':
         back_up(data_db_set)
 
     do_ban_end()
+    do_vote_end()
 
 def update(ver_num, set_data):
     with get_db_connect() as conn:

+ 1 - 0
route/vote_close.py

@@ -24,6 +24,7 @@ def vote_close(num = 1):
             type_set = 'n_close'
 
         curs.execute(db_change("update vote set type = ? where user = '' and id = ? and type = ?"), [type_set, num, data_list[0][0]])
+        curs.execute(db_change('delete from vote where name = "end_date" and type = "option" and id = ?'), [num])
         conn.commit()
 
         if data_list[0][0] == 'close' or data_list[0][0] == 'n_close':

+ 2 - 2
route/vote_select.py

@@ -27,8 +27,8 @@ def vote_select(num = 1):
         if db_data:
             time_limit = db_data[0][0]
             
-            time_db = int(db_data[0][0].split()[0].replace('-', ''))
-            time_today = int(get_time().split()[0].replace('-', ''))
+            time_db = db_data[0][0].split()[0]
+            time_today = get_time().split()[0]
             
             if time_today > time_db:
                 return redirect('/vote/end/' + num)