Code
2 years ago in Python
#The main() func initially runs an inquirer menu with the menu() func, which selects what option I would like. The main() func then runs the pick() func which checks if "a" (a global variable) matches the output of picking the file sorter from the menu() func. At this point, the pick() func outputs nothing. I am expecting it to run the sort func if the output matches.
#Pardon my coding illiteracy I am new to this.
#This is the code in question:
from pprint import pprint
import inquirer
import os
import shutil
#CookieCLI™ 2022 Version 0.1 Alpha
def pick():
if a == "{'option': 'Sort Files'}":
def sort():
os.chdir('/home/qz/Downloads')
current = os.getcwd()
files = os.listdir(current)
class col:
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
print(col.OKGREEN,"[Filey] Filey File Organiser V3")
images = [".jpeg",".png",".jpg",".gif"]
text = [".doc",".txt",".pdf",".xlsx",".docx",".xls",".rtf"]
videos = [".mp4",".mkv"]
sounds = [".mp3",".wav",".m4a"]
for file in files:
d = ""
for ex in images:
if file.endswith(ex):
d = '/home/qz/Pictures'
shutil.move(file,d)
print(" [Filey]",file,">>",d)
break
for ex in text:
if file.endswith(ex):
d = '/home/qz/Documents/Text Files'
shutil.move(file,d)
print(" [Filey]",file,">>",d)
break
for ex in sounds:
if file.endswith(ex):
d = '/home/qz/Music'
shutil.move(file,d)
print(" [Filey]",file,">>",d)
break
for ex in videos:
if file.endswith(ex):
d = '/home/qz/Videos'
shutil.move(file,d)
print(" [Filey]",file,">>",d)
break
print(col.OKGREEN,"[Filey] Completed Successfully")
def menu():
questions = [
inquirer.List(
"option",
message="Choose an option",
choices=["Sort Files", "Other"],
),
]
global a
a = inquirer.prompt(questions)
def welcome():
print("this is a welcome message")
def main():
welcome()
menu()
pick()
if __name__ == '__main__':
main()