diff --git a/FTS/__pycache__/initializer.cpython-312.pyc b/FTS/__pycache__/initializer.cpython-312.pyc new file mode 100644 index 0000000..c47b5d0 Binary files /dev/null and b/FTS/__pycache__/initializer.cpython-312.pyc differ diff --git a/FTS/__pycache__/update.cpython-312.pyc b/FTS/__pycache__/update.cpython-312.pyc new file mode 100644 index 0000000..c3ef76e Binary files /dev/null and b/FTS/__pycache__/update.cpython-312.pyc differ diff --git a/FTS/initializer.py b/FTS/initializer.py new file mode 100644 index 0000000..938c661 --- /dev/null +++ b/FTS/initializer.py @@ -0,0 +1,9 @@ +import sqlite3 + +def Initializer_Virtual_Table(): + conn = sqlite3.connect('./database/search-index.db') + + conn.execute('''CREATE VIRTUAL TABLE IF NOT EXISTS information_fts + USING FTS5(site_id, link, title, text, description, keywords, shorttext, added)''') + + conn.close() diff --git a/FTS/update.py b/FTS/update.py new file mode 100644 index 0000000..8774bbd --- /dev/null +++ b/FTS/update.py @@ -0,0 +1,12 @@ +import sqlite3 + +def Update_Virtual_Table(): + conn = sqlite3.connect('./database/search-index.db') + + conn.execute('DELETE FROM information_fts') + conn.execute('''INSERT INTO information_fts(site_id, link, title, text, description, keywords, shorttext, added) + SELECT site_id, link, title, text, description, keywords, shorttext, added FROM information''') + + conn.commit() + + conn.close() diff --git a/acc.sh b/acc.sh deleted file mode 100644 index 7716383..0000000 --- a/acc.sh +++ /dev/null @@ -1 +0,0 @@ -python -m streamlit run account/manager.py \ No newline at end of file diff --git a/adpn.py b/adpn.py index 73dc88b..76ee47e 100644 --- a/adpn.py +++ b/adpn.py @@ -1,8 +1,13 @@ +from datetime import datetime import os import shutil import sqlite3 +import subprocess +from FTS.initializer import Initializer_Virtual_Table +from FTS.update import Update_Virtual_Table from account.userid import get_user_id from account.username import get_username +from initializer.database import Initializer_Database from log.write import log, sys_log from account.loader import account_database_loader from account.reliability import get_user_reliability @@ -99,6 +104,7 @@ def change_reliability_by_user_id(user_id, new_reliability): if reliability is None: print("Account does not exist.") + exit() elif reliability >= 4: print('Logged in successfully.') else: @@ -110,10 +116,22 @@ def change_reliability_by_user_id(user_id, new_reliability): if command == "exit": exit() + elif command == "start": + yn = input('Do you want to start the server including: Search, Account [y/n]: ') + if (yn != 'n'): + Initializer_Database() + Initializer_Virtual_Table() + Update_Virtual_Table() + subprocess.call("start server1", shell=True) + subprocess.call("start server2", shell=True) + print('The server has been started successfully.') + sys_log('Start Server', str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) elif command == "check": compare_databases() elif command == "sync": synchronization_databases() + elif command == "sync-fts": + Update_Virtual_Table() elif command == "log": with open('log.txt', 'r') as file: for line in file: diff --git a/adpn.sh b/adpn.sh deleted file mode 100644 index 747882a..0000000 --- a/adpn.sh +++ /dev/null @@ -1 +0,0 @@ -python adpn.py \ No newline at end of file diff --git a/all.bat b/all.bat deleted file mode 100644 index cc6d9f1..0000000 --- a/all.bat +++ /dev/null @@ -1,3 +0,0 @@ -start "Start Main Server" run -start "Account System" acc -start "Start Adpn Command Line" adpn \ No newline at end of file diff --git a/database/users-account.db b/database/users-account.db new file mode 100644 index 0000000..03cf2ff Binary files /dev/null and b/database/users-account.db differ diff --git a/initializer/__pycache__/loader.cpython-312.pyc b/initializer/__pycache__/loader.cpython-312.pyc index 5fd5b11..a767eac 100644 Binary files a/initializer/__pycache__/loader.cpython-312.pyc and b/initializer/__pycache__/loader.cpython-312.pyc differ diff --git a/log.txt b/log.txt index e69de29..6db2745 100644 --- a/log.txt +++ b/log.txt @@ -0,0 +1,7 @@ +SYS: Loaded: users-account.db +SYS: Initializer Database: search-index.db +SYS: Initializer Censorship Database: censorship.db +SYS: Create Users Account Database: users-account.db +SYS: Start Server: 2024-02-08 18:24:56 +SYS: Loaded: users-account.db +SYS: Loaded: search-index.db diff --git a/main.py b/main.py index 2c22db3..623b0a6 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,8 @@ import streamlit as st import time - from initializer.loader import database_loader from manager.manager import * from search.index import Search_Data -from initializer.database import Initializer_Database - -Initializer_Database() conn = database_loader() diff --git a/run.sh b/run.sh deleted file mode 100644 index 086a355..0000000 --- a/run.sh +++ /dev/null @@ -1 +0,0 @@ -python -m streamlit run main.py \ No newline at end of file diff --git a/search/__pycache__/index.cpython-312.pyc b/search/__pycache__/index.cpython-312.pyc index a179288..b7f8b68 100644 Binary files a/search/__pycache__/index.cpython-312.pyc and b/search/__pycache__/index.cpython-312.pyc differ diff --git a/search/index.py b/search/index.py index f0b76e8..5f8d305 100644 --- a/search/index.py +++ b/search/index.py @@ -4,9 +4,8 @@ def Search_Data(conn, keyword): cursor = conn.cursor() - cursor.execute('''SELECT * FROM information - WHERE title LIKE ? OR text LIKE ? OR description LIKE ? OR keywords LIKE ? OR shorttext LIKE ?''', - ('%' + keyword + '%', '%' + keyword + '%', '%' + keyword + '%', '%' + keyword + '%', '%' + keyword + '%')) + cursor.execute('''SELECT * FROM information_fts + WHERE information_fts MATCH ?''', (keyword,)) rows = cursor.fetchall() conn.close() diff --git a/run.bat b/server1.bat similarity index 100% rename from run.bat rename to server1.bat diff --git a/acc.bat b/server2.bat similarity index 100% rename from acc.bat rename to server2.bat