Skip to content

Commit

Permalink
Patch
Browse files Browse the repository at this point in the history
Now special characters can work with keywords
  • Loading branch information
EndermanPC committed Feb 12, 2024
1 parent 85a4dc2 commit 80d5ded
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 5 deletions.
1 change: 0 additions & 1 deletion adpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from log.write import sys_log
from account.loader import account_database_loader
from account.reliability import get_user_reliability
from main import MainForm

print('Welcome to Neutron Administrator Panel')

Expand Down
Binary file modified database/censorship.db
Binary file not shown.
Binary file modified database/search-index.db
Binary file not shown.
17 changes: 17 additions & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from initializer.loader import database_loader
from manager.manager import *
from search.index import Search_Data
from search.safe import return_special_characters

if 'conn' not in st.session_state:
st.session_state.conn = database_loader()
Expand All @@ -14,9 +15,9 @@
with st.form('Input_Form'):
col1, col2, col3, col4, col5 = st.columns([3, 0.8, 0.6, 0.6, 0.8])
AForm = st.session_state.form_state

with col1:
keyword = st.text_input('Try to search something!', placeholder='Try to search something!', label_visibility='collapsed')

with col2:
submitted1 = st.form_submit_button('Search')
with col3:
Expand All @@ -25,6 +26,7 @@
submitted3 = st.form_submit_button('Edit')
with col5:
submitted4 = st.form_submit_button('Remove')

if keyword and submitted1:
Search_Result = Search_Data(conn, keyword)
if submitted2 and AForm == True:
Expand Down Expand Up @@ -73,11 +75,13 @@
elif submitted4 and not AForm:
st.session_state.add_state = True
for row in Search_Result:
row2 = return_special_characters(row[2])
row6 = return_special_characters(row[6])
st.markdown('```' + str(row[0]) + '``` ```' + row[1] + '```')
row_title = row[2].replace('\n', ' ')
row_title = row2.replace('\n', ' ')
row_title = row_title.replace(':', ' ')
st.markdown("### [" + row_title + ']' + '(' + row[1] + ')')
row_shorttext = row[6].replace('\n', ' ')
row_shorttext = row6.replace('\n', ' ')
row_shorttext = row_shorttext.replace('```', ' ')
st.markdown("```" + row_shorttext + "```")
st.markdown("   ")
8 changes: 8 additions & 0 deletions manager/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import json
from datetime import datetime

from search.safe import escape_special_characters

GOOGLE_SAFE_BROWSING_API_KEY = 'API_KEY'

allowed_extensions = {"http", "https"}
Expand Down Expand Up @@ -42,6 +44,12 @@ def is_content_safe(link):
return True

def edit_data(conn, site_id, link, title, text, description, keywords, shorttext):
title = escape_special_characters(title)
text = escape_special_characters(text)
description = escape_special_characters(description)
keywords = escape_special_characters(keywords)
shorttext = escape_special_characters(shorttext)

added = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

normalize_link = link
Expand Down
8 changes: 8 additions & 0 deletions manager/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import json
from datetime import datetime

from search.safe import escape_special_characters

GOOGLE_SAFE_BROWSING_API_KEY = 'API_KEY'

allowed_extensions = {"http", "https"}
Expand Down Expand Up @@ -42,6 +44,12 @@ def is_content_safe(link):
return True

def insert_data(conn, link, title, text, description, keywords, shorttext):
title = escape_special_characters(title)
text = escape_special_characters(text)
description = escape_special_characters(description)
keywords = escape_special_characters(keywords)
shorttext = escape_special_characters(shorttext)

added = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

cursor = conn.cursor()
Expand Down
5 changes: 4 additions & 1 deletion search/index.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import streamlit as st

from atmt import ATMT_STRT
from search.safe import escape_special_characters

def Search_Data(conn, keyword):
cursor = conn.cursor()

safe_keyword = escape_special_characters(keyword)

cursor.execute('''SELECT * FROM information_fts
WHERE information_fts MATCH ?''', (keyword,))
WHERE information_fts MATCH ?''', (safe_keyword,))

rows = cursor.fetchall()

Expand Down
43 changes: 43 additions & 0 deletions search/safe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def escape_special_characters(text):
special_characters_dict = {
'+': '"plus"',
'-': '"minus"',
'*': '"asterisk"',
':': '"colon"',
'(': '"leftparen"',
')': '"rightparen"',
'[': '"leftbracket"',
']': '"rightbracket"',
'{': '"leftbrace"',
'}': '"rightbrace"',
'~': '"tilde"',
'?': '"questionmark"',
'\\': '"backslash"'
}

for char, replacement in special_characters_dict.items():
text = text.replace(char, replacement)

return text

def return_special_characters(text):
special_characters_dict = {
'"plus"': '+',
'"minus"': '-',
'"asterisk"': '*',
'"colon"': ':',
'"leftparen"': '(',
'"rightparen"': ')',
'"leftbracket"': '[',
'"rightbracket"': ']',
'"leftbrace"': '{',
'"rightbrace"': '}',
'"tilde"': '~',
'"questionmark"': '?',
'"backslash"': '\\'
}

for char, replacement in special_characters_dict.items():
text = text.replace(char, replacement)

return text

0 comments on commit 80d5ded

Please sign in to comment.