2022-11-12 21:35:50 +01:00
#!/bin/python3
2022-11-16 09:12:37 +01:00
import sys , os , re
2022-11-12 21:35:50 +01:00
from func import *
2022-11-16 10:36:34 +01:00
from config import *
2022-11-16 09:12:37 +01:00
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 ] )
2022-11-12 21:35:50 +01:00
2022-11-16 10:36:34 +01:00
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 )
2022-11-12 21:35:50 +01:00
2022-11-16 09:12:37 +01:00
def help ( ) :
print ( " SYNTAX: \n \t ' image-index ' displays this text " )
print ( " \t ' image-index <option> [args] ' executes the command " )
print ( " \n OPTIONS: \n \t help: \t displays this prompt " )
print ( " \t add: \t adds a new entry; \n \t \t Instant: image-index add <filepath> <category> <title> <source> <tags> <content> " )
print ( " \t \t Prompt: image-index add " )
print ( " \t search: \t searches through the index (enter prompt for options); \n \t \t Instant: image-index search <words/filter> " )
print ( " \t \t Prompt: image-index search " )
print ( " \t delete: \t deletes an entry based on a search query; \n \t \t Instant: image-index delete <words> " )
print ( " \t \t Prompt: image-index delete " )
input ( " Press return... " )
2022-11-16 10:36:34 +01:00
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 ( " \n Query empty! " )
return tb . search_index ( args )
2022-11-16 09:12:37 +01:00
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 ) :
2022-11-16 10:36:34 +01:00
delete ( args )
exit ( )
2022-11-16 09:12:37 +01:00
elif re . match ( ' [sS].* ' , command ) :
2022-11-16 10:36:34 +01:00
search ( args )
exit ( )
2022-11-16 09:12:37 +01:00
else :
print ( " No such option! " )
exit ( )
#for i in sys.argv:
# print("Arg:" + i)
exit ( )
2022-11-12 21:35:50 +01:00
#tb.add_index("/home/marcel/Downloads/froggy.jpg","Tiere","Fifel","https://youtu.be","Tier,Meme_template","Ein sitzender Frosch. Ist er nicht süß?")
2022-11-16 09:12:37 +01:00
#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 : ] ) )
2022-11-12 21:35:50 +01:00
if __name__ == " __main__ " :
filepath = CONFIG_DIR + ' /index.db '
tb = filestable ( filepath )
mtb = metatable ( filepath )
main ( )
print ( " Stopping " )
tb . connection . close ( )