Added all files

This commit is contained in:
L3gacy B3ta 2020-08-19 17:41:19 -04:00
parent 7df955704e
commit 879455bc29
6 changed files with 124 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tiny_BETA.db

56
indexer.py Normal file
View File

@ -0,0 +1,56 @@
#imports
import sqlite3
import os
#Init
#DB FORMAT: {fd: (File 'f' or directory 'd'), filename: (Filename duh), path: (path)}
#ex: {"fd":"f","filename":""
#may add more later
conn = sqlite3.connect('tiny_BETA.db')
files = []
counter = 0
#creates cursor
c = conn.cursor()
#create table
c.execute('''CREATE TABLE files
(fd text, filename text, path text)''')
#Indexes disks:
for (dirpath, dirnames, filenames) in os.walk('C:'):
#progress "bar"
counter = counter + 1
if counter == 500:
counter = 0
print(".", end='')
for f in filenames:
files.append(("f", f, os.path.join(dirpath, f)))
for d in dirnames:
files.append(("d", d, os.path.join(dirpath, d)))
print("C drive indexed!")
for (dirpath, dirnames, filenames) in os.walk('D:'):
#progress "bar"
counter = counter + 1
if counter == 500:
counter = 0
print(".", end='')
for f in filenames:
files.append(("f", f, os.path.join(dirpath, f)))
for d in dirnames:
files.append(("d", d, os.path.join(dirpath, d)))
print("D drive indexed!")
c.executemany('INSERT INTO files VALUES (?,?,?)', files)
conn.commit()
print("DB saved! Press enter to see files!")
#print(files)
c.close()

33
search_engine.py Normal file
View File

@ -0,0 +1,33 @@
from flask import Flask, request, render_template, send_from_directory
import sqlite3, os
app = Flask(__name__)
conn = sqlite3.connect('tiny_BETA.db')
c = conn.cursor()
@app.route('/', methods=['GET','POST'])
def hello_world():
return render_template("index.html")
@app.route('/data', methods=['GET', 'POST'])
def index():
conn = sqlite3.connect('tiny_BETA.db')
c = conn.cursor()
data = request.form['query']
c.execute("SELECT * FROM files WHERE FILENAME LIKE '%"+data+"%'")
data = c.fetchall()
conn.close()
return render_template("data.html", len = len(data), data = data)
@app.route('/img/<path:path>', methods=['GET', 'POST'])
def send_js(path):
return send_from_directory('templates', path)
@app.route('/open/<path:path>', methods=['GET', 'POST'])
def open(path):
os.system("start "+path)
return "Opened!"

15
templates/data.html Normal file
View File

@ -0,0 +1,15 @@
<html>
<title>Datalist</title>
<body>
<a href = "/">Home</a>
<img src="/img/logo.png" style="align: center;" height="10%" width="15%">
<ul>
{%for i in range(0, len)%}
<li>
<a href="/open/{{data[i][2]}}" style="text-color:green"> {{data[i][1]}} </a>
<br>
</li>
{%endfor%}
</ul>
</body>
</html>

19
templates/index.html Normal file
View File

@ -0,0 +1,19 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
.cbuttons { display: flex; justify-content: center; margin: auto; width: 50%;}
#textbox {height:200px;font-size:14pt;}
#body {vertical-align: middle;}
</style>
</head>
<body>
<div style="text-align:center; margin-top:auto; margin-bottom:auto;">
<img src="/img/logo.png" style="align: center;">
<form class="cbuttons" action="/data" method="post">
<input type="text" id="textbox" name="query" style="width: 90%; height: 10%;"><br>
<input type="submit" value="Search">
</form>
</div>
</body>
</html>

BIN
templates/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB