104 lines
3.5 KiB
Python
Executable file
104 lines
3.5 KiB
Python
Executable file
#!/bin/python3
|
|
import sys,os,re
|
|
from func import *
|
|
from config import *
|
|
|
|
def add():
|
|
args=[]
|
|
for i in ["Filepath","Category","Title","Source","Tags","Content"]:
|
|
eingabe = input("Enter {}: ".format(i))
|
|
if i in ["Filepath"] and not eingabe:
|
|
print("{} has to not be empty!".format(i))
|
|
return 1
|
|
if i in ["Category"] and not eingabe:
|
|
print("{} set to 'default'".format(i))
|
|
eingabe="default"
|
|
args.append(eingabe)
|
|
print(args)
|
|
tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5])
|
|
|
|
def delete(args):
|
|
selection=search(args)
|
|
if selection[0] != ".":
|
|
try:
|
|
category=selection[4]
|
|
filename=selection[0]
|
|
os.remove("{}/{}".format(category,filename))
|
|
except Exception:
|
|
print("Couldn't delete file!")
|
|
return 1
|
|
tb.delete_index(selection)
|
|
|
|
def help():
|
|
print("SYNTAX:\n\t'image-index' displays this text")
|
|
print("\t'image-index <option> [args]' executes the command")
|
|
print("\nOPTIONS:\n\thelp:\tdisplays this prompt")
|
|
print("\tadd:\tadds a new entry;\n\t\tInstant: image-index add <filepath> <category> <title> <source> <tags> <content>")
|
|
print("\t\tPrompt: image-index add")
|
|
print("\tsearch:\tsearches through the index (enter prompt for options);\n\t\tInstant: image-index search <words/filter>")
|
|
print("\t\tPrompt: image-index search")
|
|
print("\tdelete:\tdeletes an entry based on a search query;\n\t\tInstant: image-index delete <words>")
|
|
print("\t\tPrompt: image-index delete")
|
|
|
|
input("Press return...")
|
|
|
|
def search(args):
|
|
if len(args) == 0:
|
|
print("Separate the items with spaces ( )")
|
|
print("FILTERS: -a: All types")
|
|
print("\t -c: Category")
|
|
print("\t -f: Filename")
|
|
print("\t -g: Tags")
|
|
print("\t -h: Hash")
|
|
print("\t -i: Content")
|
|
print("\t -s: Source")
|
|
print("\t -t: Title")
|
|
args=input("Query: ")
|
|
if len(args) > 0:
|
|
return tb.search_index(args.split(' '))
|
|
print("\nQuery empty!")
|
|
return tb.search_index(args)
|
|
|
|
def main():
|
|
if len(sys.argv) <= 1:
|
|
help()
|
|
exit()
|
|
else:
|
|
command=sys.argv[1]
|
|
args=[]
|
|
for i in sys.argv[2:]:
|
|
args.append(i)
|
|
if re.match('[aA].*',command):
|
|
if len(sys.argv) == 2:
|
|
add()
|
|
exit()
|
|
elif len(sys.argv) >= 8:
|
|
tb.add_index(args[0],args[1],args[2],args[3],args[4],args[5])
|
|
elif re.match('[dD].*',command):
|
|
delete(args)
|
|
exit()
|
|
elif re.match('[sS].*',command):
|
|
search(args)
|
|
exit()
|
|
else:
|
|
print("No such option!")
|
|
exit()
|
|
#for i in sys.argv:
|
|
# print("Arg:" + i)
|
|
exit()
|
|
#tb.add_index("/home/marcel/Downloads/froggy.jpg","Tiere","Fifel","https://youtu.be","Tier,Meme_template","Ein sitzender Frosch. Ist er nicht süß?")
|
|
#tb.add_index("/home/marcel/Downloads/people.jpg","Leute","Rote Leute","https://www.pexels.com","Menschen,Uniform","Leute in roten Uniformen. Warum stehen sie so? Wer weiß.")
|
|
#sys.argv+=("-t","Fifel")
|
|
sys.argv+=("-g","Meme")
|
|
#sys.argv+=("-f","ea892d6e-a20a-4784-930e-cabceb7b98ab")
|
|
print(tb.search_index(sys.argv[1:]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
filepath=CONFIG_DIR + '/index.db'
|
|
tb = filestable(filepath)
|
|
mtb = metatable(filepath)
|
|
main()
|
|
print("Stopping")
|
|
tb.connection.close()
|