瀏覽代碼

페이지카운트 방식 변경, sitemap.xml도 되도록

Surplus_Up (2DU) 6 年之前
父節點
當前提交
df7eb7a9c4
共有 6 個文件被更改,包括 33 次插入24 次删除
  1. 2 20
      app.py
  2. 12 1
      emergency_tool.py
  3. 3 0
      route/edit.py
  4. 3 0
      route/edit_delete.py
  5. 3 0
      route/edit_many_delete.py
  6. 10 3
      route/main_file.py

+ 2 - 20
app.py

@@ -313,28 +313,10 @@ if set_data['db_type'] == 'mysql':
 
     mysql_dont_off()
 
-def count_all_title():
-    curs.execute(db_change("select count(title) from data"))
-    count_data = curs.fetchall()
-    if count_data:
-        count_data = count_data[0][0]
-    else:
-        count_data = 0
-
-    curs.execute(db_change('delete from other where name = "count_all_title"'))
-    curs.execute(db_change('insert into other (name, data) values ("count_all_title", ?)'), [str(count_data)])
-
-    conn.commit()
-
-    threading.Timer(60 * 60 * 24, count_all_title).start()
-
 curs.execute(db_change('select data from other where name = "count_all_title"'))
-all_title = curs.fetchall()
-if not all_title:
+if not curs.fetchall():
     curs.execute(db_change('insert into other (name, data) values ("count_all_title", "0")'))
 
-count_all_title()  
-
 conn.commit()
 
 # Func
@@ -681,7 +663,7 @@ def main_views(name = None):
 
 @app.route('/<data>')
 def main_file(data = None):
-    return main_file_2(conn, data) if re.search('\.txt$', data) else main_error_404_2(conn)
+    return main_file_2(conn, data)
 
 # End
 @app.errorhandler(404)

+ 12 - 1
emergency_tool.py

@@ -113,6 +113,7 @@ print('8. Reset version')
 print('9. Delete set.json')
 print('10. Change name')
 print('11. Delete mysql.json')
+print('12. All title count reset')
 
 print('----')
 print('Select : ', end = '')
@@ -221,11 +222,21 @@ elif what_i_do == '10':
     new_name = input()
 
     curs.execute(db_change("update user set id = ? where id = ?"), [new_name, user_name])
-else:
+elif what_i_do == '11':
     try:
         os.remove('data/mysql.json')
     except:
         pass
+else:
+    curs.execute(db_change("select count(title) from data"))
+    count_data = curs.fetchall()
+    if count_data:
+        count_data = count_data[0][0]
+    else:
+        count_data = 0
+
+    curs.execute(db_change('delete from other where name = "count_all_title"'))
+    curs.execute(db_change('insert into other (name, data) values ("count_all_title", ?)'), [str(count_data)])
 
 conn.commit()
 

+ 3 - 0
route/edit.py

@@ -36,6 +36,9 @@ def edit_2(conn, name):
             
             curs.execute(db_change("insert into data (title, data) values (?, ?)"), [name, content])
 
+            curs.execute(db_change('select data from other where name = "count_all_title"'))
+            curs.execute(db_change("update other set data = ? where name = 'count_all_title'"), [str(int(curs.fetchall()[0][0]) + 1)])
+
         curs.execute(db_change("select user from scan where title = ?"), [name])
         for _ in curs.fetchall():
             curs.execute(db_change("insert into alarm (name, data, date) values (?, ?, ?)"), [ip, ip + ' - <a href="/w/' + url_pas(name) + '">' + name + '</a> (Edit)', today])

+ 3 - 0
route/edit_delete.py

@@ -44,6 +44,9 @@ def edit_delete_2(conn, name, app_var):
                 app_var['path_data_image'],
                 hashlib.sha224(bytes(file_check[0], 'utf-8')).hexdigest() + '.' + file_check[1]
             ))
+
+        curs.execute(db_change('select data from other where name = "count_all_title"'))
+        curs.execute(db_change("update other set data = ? where name = 'count_all_title'"), [str(int(curs.fetchall()[0][0]) - 1)])
             
         return redirect('/w/' + url_pas(name))
     else:

+ 3 - 0
route/edit_many_delete.py

@@ -41,6 +41,9 @@ def edit_many_delete_2(conn, app_var):
                     app_var['path_data_image'],
                     hashlib.sha224(bytes(file_check[0], 'utf-8')).hexdigest() + '.' + file_check[1]
                 ))
+
+            curs.execute(db_change('select data from other where name = "count_all_title"'))
+            curs.execute(db_change("update other set data = ? where name = 'count_all_title'"), [str(int(curs.fetchall()[0][0]) - 1)])
                 
         return redirect('/recent_changes')
     else:

+ 10 - 3
route/main_file.py

@@ -1,9 +1,16 @@
 from .tool.func import *
+from . import main_error_404
 
 def main_file_2(conn, data):
     curs = conn.cursor()
 
-    if data == 'robots.txt' and not os.path.exists('robots.txt'):
-        return flask.Response('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/', mimetype='text/plain')
+    print(data)
+    if re.search('\.txt$', data) or data == 'sitemap.xml':
+        if data == 'robots.txt' and not os.path.exists('robots.txt'):
+            return flask.Response('User-agent: *\nDisallow: /\nAllow: /$\nAllow: /w/', mimetype='text/plain')
+        elif os.path.exists(data):
+            return flask.send_from_directory('./', data)
+        else:
+            return main_error_404.main_error_404_2(conn)
     else:
-        return flask.send_from_directory('./', data)
+        return main_error_404.main_error_404_2(conn)