Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
ATMT (Program)
ATMT_SRTR (Start ATMT)
Automatically use ATMT if the keyword is not found
add ATMT command to adpn
  • Loading branch information
EndermanPC committed Feb 9, 2024
1 parent aef8545 commit 081ba3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
4 changes: 4 additions & 0 deletions adpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from FTS.update import Update_Virtual_Table
from account.userid import get_user_id
from account.username import get_username
from atmt import ATMT_STRT
from initializer.database import Initializer_Database
from log.write import log, sys_log
from account.loader import account_database_loader
Expand Down Expand Up @@ -126,6 +127,9 @@ def change_reliability_by_user_id(user_id, new_reliability):
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 == "atmt":
keyword = input('Keyword: ')
ATMT_STRT(keyword)
elif command == "check":
compare_databases()
elif command == "sync":
Expand Down
52 changes: 24 additions & 28 deletions atmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from initializer.loader import database_loader
from manager.insert import insert_data

conn = database_loader()

def summarize_text(text, max_length=100):
if len(text) <= max_length:
return text
Expand Down Expand Up @@ -43,29 +41,27 @@ def get_website_info(url):
print("Error:", e)
return None

user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107 Safari/537.36'
headers = {'User-Agent': user_agent}

random_keyword = ' '.join(['Google', 'English'])
search_url = f"https://www.google.com/search?q={random_keyword}&hl=en"

response = requests.get(search_url, headers=headers)

if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')

search_results = soup.find_all('a')

random_urls = [link.get('href') for link in search_results if link.get('href') and link.get('href').startswith('http')]

for url in random_urls:
print("url: ", url)
website_info = get_website_info(url)
if website_info is None:
pass
else:
print("title: ", website_info["title"])
insert_data(conn, url, website_info["title"], website_info["text_content"], website_info["description"], website_info["keywords"], summarize_text(website_info["text_content"]))
print("---PASS---")
else:
print("ERR.")
def ATMT_STRT(random_keyword):
conn = database_loader()
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107 Safari/537.36'
headers = {'User-Agent': user_agent}
search_url = f"https://www.google.com/search?q={random_keyword}&hl=en"

response = requests.get(search_url, headers=headers)

if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
search_results = soup.find_all('a')
random_urls = [link.get('href') for link in search_results if link.get('href') and link.get('href').startswith('http')]

for url in random_urls:
print("url: ", url)
website_info = get_website_info(url)
if website_info is None:
pass
else:
print("title: ", website_info["title"])
insert_data(conn, url, website_info["title"], website_info["text_content"], website_info["description"], website_info["keywords"], summarize_text(website_info["text_content"]))
print("---PASS---")
else:
print("ERR.")
3 changes: 3 additions & 0 deletions search/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pandas as pd
import streamlit as st

from atmt import ATMT_STRT

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

Expand All @@ -11,5 +13,6 @@ def Search_Data(conn, keyword):

if len(rows) == 0:
st.write("No results found")
ATMT_STRT(keyword)
else:
return rows

0 comments on commit 081ba3b

Please sign in to comment.