Skip to content

Commit

Permalink
Added & Patch for update
Browse files Browse the repository at this point in the history
Add search options: text, image, video
Disable ATMT Strt in Search/Index.py because it does not work with new databases
Patch:
Add databases for new search options
  • Loading branch information
EndermanPC committed Feb 12, 2024
1 parent 81be3de commit ad70fac
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 85 deletions.
22 changes: 20 additions & 2 deletions FTS/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@
from log.write import sys_log

def Initializer_Virtual_Table():
conn = sqlite3.connect('./database/search-index.db')
conn = sqlite3.connect('./database/search-index0.db')

conn.execute('''CREATE VIRTUAL TABLE IF NOT EXISTS information_fts
USING FTS5(site_id, link, title, text, description, keywords, shorttext, added)''')

conn.close()

sys_log("Initializer Virtual Table", "search-index.db")
sys_log("Initializer Virtual Table", "search-index0.db")

conn = sqlite3.connect('./database/search-index1.db')

conn.execute('''CREATE VIRTUAL TABLE IF NOT EXISTS information_fts
USING FTS5(site_id, link, title, text, description, keywords, shorttext, added)''')

conn.close()

sys_log("Initializer Virtual Table", "search-index1.db")

conn = sqlite3.connect('./database/search-index2.db')

conn.execute('''CREATE VIRTUAL TABLE IF NOT EXISTS information_fts
USING FTS5(site_id, link, title, text, description, keywords, shorttext, added)''')

conn.close()

sys_log("Initializer Virtual Table", "search-index2.db")
2 changes: 1 addition & 1 deletion FTS/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def Update_Virtual_Table(conn):

conn.commit()

sys_log("Update Virtual Table", "search-index.db")
sys_log("Update Virtual Table", "search-index012.db")
166 changes: 133 additions & 33 deletions adpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,138 @@

print('Welcome to Neutron Administrator Panel')

def compare_databases():
try:
conn1 = sqlite3.connect("./database/search-index.db")
conn2 = sqlite3.connect("./database/censorship.db")
def compare_databases(num):
if num == 0:
try:
conn1 = sqlite3.connect("./database/search-index0.db")
conn2 = sqlite3.connect("./database/censorship0.db")

cur1 = conn1.cursor()
cur2 = conn2.cursor()
cur1 = conn1.cursor()
cur2 = conn2.cursor()

table_name = "information"
table_name = "information"

cur1.execute(f"SELECT * FROM {table_name}")
cur2.execute(f"SELECT * FROM {table_name}")
cur1.execute(f"SELECT * FROM {table_name}")
cur2.execute(f"SELECT * FROM {table_name}")

data1 = cur1.fetchall()
data2 = cur2.fetchall()
data1 = cur1.fetchall()
data2 = cur2.fetchall()

set1 = set(data1)
set2 = set(data2)
set1 = set(data1)
set2 = set(data2)

different_list = list(set2 - set1)
different_list = list(set2 - set1)

result = {
"Censorship:": different_list,
"Search Index:": list(set1-set2)
}
result = {
"Censorship:": different_list,
"Search Index:": list(set1-set2)
}

print(result)
print(result)

conn1.close()
conn2.close()
conn1.close()
conn2.close()

if different_list:
if different_list:
return False
else:
return True
except Exception as e:
print("Error comparing databases:", str(e))
return False
elif num == 1:
try:
conn1 = sqlite3.connect("./database/search-index1.db")
conn2 = sqlite3.connect("./database/censorship1.db")

cur1 = conn1.cursor()
cur2 = conn2.cursor()

table_name = "information"

cur1.execute(f"SELECT * FROM {table_name}")
cur2.execute(f"SELECT * FROM {table_name}")

data1 = cur1.fetchall()
data2 = cur2.fetchall()

set1 = set(data1)
set2 = set(data2)

different_list = list(set2 - set1)

result = {
"Censorship:": different_list,
"Search Index:": list(set1-set2)
}

print(result)

conn1.close()
conn2.close()

if different_list:
return False
else:
return True
except Exception as e:
print("Error comparing databases:", str(e))
return False
elif num == 2:
try:
conn1 = sqlite3.connect("./database/search-index2.db")
conn2 = sqlite3.connect("./database/censorship2.db")

cur1 = conn1.cursor()
cur2 = conn2.cursor()

table_name = "information"

cur1.execute(f"SELECT * FROM {table_name}")
cur2.execute(f"SELECT * FROM {table_name}")

data1 = cur1.fetchall()
data2 = cur2.fetchall()

set1 = set(data1)
set2 = set(data2)

different_list = list(set2 - set1)

result = {
"Censorship:": different_list,
"Search Index:": list(set1-set2)
}

print(result)

conn1.close()
conn2.close()

if different_list:
return False
else:
return True
except Exception as e:
print("Error comparing databases:", str(e))
return False
else:
return True
except Exception as e:
print("Error comparing databases:", str(e))
return False

def synchronization_databases():
try:
if not compare_databases():
if not compare_databases(0) and not compare_databases(1) and not compare_databases(2):
print("Databases cannot be synchronized when there are differences between them.")
return
else:
os.remove("./database/censorship.db")
shutil.copy("./database/search-index.db", "./database/censorship.db")
os.remove("./database/censorship0.db")
shutil.copy("./database/search-index0.db", "./database/censorship0.db")
print("Synchronization successful.")

os.remove("./database/censorship1.db")
shutil.copy("./database/search-index1.db", "./database/censorship1.db")
print("Synchronization successful.")

os.remove("./database/censorship2.db")
shutil.copy("./database/search-index2.db", "./database/censorship2.db")
print("Synchronization successful.")
except Exception as e:
print("Error synchronizing databases:", str(e))
Expand Down Expand Up @@ -122,9 +207,17 @@ def change_reliability_by_user_id(user_id, new_reliability):
if (yn != 'n'):
Initializer_Database()
Initializer_Virtual_Table()
vt_conn = database_loader()

vt_conn = database_loader(0)
Update_Virtual_Table(vt_conn)
vt_conn.close()
vt_conn = database_loader(1)
Update_Virtual_Table(vt_conn)
vt_conn.close()
vt_conn = database_loader(2)
Update_Virtual_Table(vt_conn)
vt_conn.close()

subprocess.call("start server1", shell=True)
subprocess.call("start server2", shell=True)
print('The server has been started successfully.')
Expand All @@ -133,12 +226,19 @@ def change_reliability_by_user_id(user_id, new_reliability):
keyword = input('Keyword: ')
ATMT_STRT(keyword)
elif command == "check":
compare_databases()
compare_databases_num = input('Text(0), Image(1), Video(3): ')
compare_databases(compare_databases_num)
elif command == "sync":
synchronization_databases()
print("Successful data synchronization.")
elif command == "sync-fts":
vt_conn = database_loader()
vt_conn = database_loader(0)
Update_Virtual_Table(vt_conn)
vt_conn.close()
vt_conn = database_loader(1)
Update_Virtual_Table(vt_conn)
vt_conn.close()
vt_conn = database_loader(2)
Update_Virtual_Table(vt_conn)
vt_conn.close()
print("Successful data synchronization.")
Expand Down
Binary file removed database/censorship.db
Binary file not shown.
Binary file removed database/search-index.db
Binary file not shown.
43 changes: 35 additions & 8 deletions initializer/database.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import sqlite3
from log.write import sys_log
from datetime import datetime

from account.database import create_users_database

def Initializer_Censorship_Database():
source_conn = sqlite3.connect('./database/search-index.db')
source_conn1 = sqlite3.connect('./database/search-index0.db')

destination_conn = sqlite3.connect('./database/censorship.db')
destination_conn1 = sqlite3.connect('./database/censorship0.db')

source_conn.backup(destination_conn)
source_conn1.backup(destination_conn1)

source_conn.close()
destination_conn.close()
source_conn1.close()
destination_conn1.close()

source_conn2 = sqlite3.connect('./database/search-index1.db')

destination_conn2 = sqlite3.connect('./database/censorship1.db')

source_conn2.backup(destination_conn2)

source_conn2.close()
destination_conn2.close()

source_conn3 = sqlite3.connect('./database/search-index2.db')

destination_conn3 = sqlite3.connect('./database/censorship2.db')

source_conn3.backup(destination_conn3)

source_conn3.close()
destination_conn3.close()

def Initializer_Database():
conn = sqlite3.connect('./database/search-index.db')
conn = sqlite3.connect('./database/search-index0.db')
cursor = conn.cursor()

cursor.execute('''CREATE TABLE IF NOT EXISTS information
Expand All @@ -36,11 +52,22 @@ def Initializer_Database():
cursor.execute('''CREATE INDEX IF NOT EXISTS idx_shorttext ON information (shorttext)''')

conn.commit()

conn1 = sqlite3.connect('./database/search-index1.db')
conn2 = sqlite3.connect('./database/search-index2.db')

conn.backup(conn1)
conn.backup(conn2)

conn.close()
conn1.close()
conn2.close()

Initializer_Censorship_Database()
create_users_database()

sys_log("Initializer Database", "search-index.db")
sys_log("Initializer Database", "search-index0.db")
sys_log("Initializer Database", "search-index1.db")
sys_log("Initializer Database", "search-index2.db")
sys_log("Initializer Censorship Database", "censorship.db")
sys_log("Create Users Account Database", "users-account.db")
34 changes: 26 additions & 8 deletions initializer/loader.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import sqlite3
from log.write import sys_log

def database_loader():
conn = sqlite3.connect('./database/search-index.db', check_same_thread=False)
sys_log("Loaded", "search-index.db")
return conn
def database_loader(num):
if num == 0:
conn = sqlite3.connect('./database/search-index0.db', check_same_thread=False)
sys_log("Loaded", "search-index0.db")
return conn
elif num == 1:
conn = sqlite3.connect('./database/search-index1.db', check_same_thread=False)
sys_log("Loaded", "search-index1.db")
return conn
elif num == 2:
conn = sqlite3.connect('./database/search-index2.db', check_same_thread=False)
sys_log("Loaded", "search-index2.db")
return conn

def censorship_database_loader():
conn = sqlite3.connect('./database/censorship.db')
sys_log("Loaded", "censorship.db")
return conn
def censorship_database_loader(num):
if num == 0:
conn = sqlite3.connect('./database/censorship0.db')
sys_log("Loaded", "censorship0.db")
return conn
if num == 1:
conn = sqlite3.connect('./database/censorship1.db')
sys_log("Loaded", "censorship1.db")
return conn
if num == 2:
conn = sqlite3.connect('./database/censorship2.db')
sys_log("Loaded", "censorship2.db")
return conn
17 changes: 0 additions & 17 deletions log.txt
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
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: Initializer Virtual Table: search-index.db
SYS: Loaded: search-index.db
SYS: Update Virtual Table: search-index.db
SYS: Start Server: 2024-02-12 07:20:55
SYS: Loaded: search-index.db
SYS: Loaded: users-account.db
SYS: Loaded: search-index.db
SYS: Loaded: search-index.db
SYS: Loaded: search-index.db
SYS: Update Virtual Table: search-index.db
SYS: Loaded: search-index.db
SYS: Loaded: search-index.db
SYS: Loaded: search-index.db
Loading

0 comments on commit ad70fac

Please sign in to comment.