image-index-py/main.py
2022-11-16 09:12:37 +01:00

93 lines
3.2 KiB
Python
Executable file

#!/bin/python3
import sys,os,re
os.chdir("ii-py")
from func import *
from vars 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():
df="Hi"
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():
print("Separate the items with spaces ( )")
print("FILTER: -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")
query=input("Query: ")
tb.search_index(query.split(' '))
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):
if len(sys.argv) == 2:
delete()
exit()
tb.del_index()
elif re.match('[sS].*',command):
if len(sys.argv) == 2:
search()
exit()
tb.search_index(args)
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()