Package: yodas
__                     
                  /\ \                    
 __  __    ___    \_\ \     __      ____  
/\ \/\ \  / __`\  /'_` \  /'__`\   /',__\ 
\ \ \_\ \/\ \L\ \/\ \L\ \/\ \L\.\_/\__, `\
 \/`____ \ \____/\ \___,_\ \__/.\_\/\____/
  `/___/> \/___/  \/__,_ /\/__/\/_/\/___/ 
     /\___/                               
     \/__/A group of tools I programmed that I use regularly. Public because why not, exists because I was tired of scrolling through repos to copy/paste the same code again and again.
To see examples, check outexamples.pyProjects that use yodasIOSBackupExtractortelegramChatBotdeepLJSONTranslatorphoneToolsInstallFrom PIPSince I didn't want to copy git repos into other projects, I made a pip package$pipinstallyodasor to upgrade$pipinstall--upgradeyodasFrom Git RepositoryThe script I use isbuild.sh. For this I assume you already have a virtual python environment or that python3 is aliased as python.$python-mpipinstall--upgradebuild
$python-mbuild
$pipinstalldist/*.tar.gz# for the latest version of yodas.From Releases (latest)$wgethttps://github.com/veryheavypickle/yodas/releases/download/v1.4.0/yodas-1.4.0.tar.gz
$pipinstallyodas-1.4.0.tar.gzFunctionscamelCaseSplit>>>fromyodasimportcamelCaseSplit>>>camelCaseSplit(string)This function takes a string in camel case form and returns it in "normal" form
For examplehelloWorldresults inHello Worldstring:strreturns:strsnakeCaseSplit>>>fromyodasimportsnakeCaseSplit>>>snakeCaseSplit(string)This function takes a string in snake case form and returns it in "normal" form
For examplehello_worldresults inHello Worldstring:strreturns:strcaseSplit>>>fromyodasimportcaseSplit>>>caseSplit(string)This function takes a string in camel case or snake case form and returns it in "normal" form
For examplehelloWorldandhello_worldboth results inHello Worldstring:strreturns:strunixToDatetime>>>fromyodasimportunixToDatetime>>>unixToDatetime(float)This function takes a unix time float/int and returns a datetime object.
For example605703600results in1989-03-12 12:00:00unixTimestamp:floatreturns:datetime.datetimeClassesMenuThis creates a CLI menu based on the inputs.InputsfromyodasimportMenuMenu(items,title=None,subtitle=None,execute=True,layout=None)items:list(required)title:strsubtitle:strexecute:boollayout:strreturns:MenuitemsWhen inputting a[dictionary], it will assume that the key is the title of the object as a string, the value can be any data type, even functionstitleIf not none, will display everytimemenu.select()is called.subtitleIf not none, will display everytimemenu.select()is called.executeBy default it isTrue, if a function is inputted in items, it will automatically execute it when selectedlayoutThis is a string that customises the appearance of the menu.Usage>>>fromyodasimportMenu>>>menu=Menu(["hello"])To run the CLI>>>menu.select()====================0:helloChooseanoption:Inputting0, the functionmenu.select()will return'hello'>>>menu.append(exit)appending pythons built-inexitto the menu. Runningmenu.select()again.>>>menu.select()====================0:hello1:QuitChooseanoption:Selecting1results in executingexit()automatically. To stop automatically running functions>>>menu.setExecute(False)This can also be setup upon menu creation>>>menu=Menu([exit,"hello"],execute=False)To append a custom label, just use a dictionary>>>menu.append({"Exit Python":exit})Functionsselect>>>Menu.select()Will open a CLI interface where the user can select an option
It will return any data type given to upon creating theMenuinstancereturns:anyappend>>>Menu.append(item)Seeitemsvariable in creating a Menu instance. Appends a new item to the menu. Returns bool on whether operation was successfulitem:anyreturns:boolpop>>>Menu.pop()Pops the last item from the list of menu items. Returns the item removedreturns:anyremove>>>Menu.remove(item)Removes a specific item from the menu list. Will return True if operation was successful, returns False if item doesn't existitem:anyreturns:boolsetExecute>>>Menu.setExecute(execute)Sets the auto execute on the menu which dictates whether functions should be automatically executed when it is selected. Returns bool on whether operation was successfulexecute:boolreturns:boolsetLayoutThis customises the appearance of the menu. By default, it is"=" * 50 + "\n%T\n%S".>>>menu.setLayout(layout)Whensubtitle is None,title = "Menu"andlayout = "=" * 5 " %T " + "=" * 5results in the appearance of.===== Menu =====
0 : First menu Item
1 : 2nd ItemWhensubtitle is None,title = "Menu"andlayout = "%T"results in the appearance of.Menu
0 : First menu Item
1 : 2nd Itemlayout:string%T istitle%S issubtitleYodaThis manages JSON files in a safe manner. When creating an object, the path does not have to exist. If the json file does not exist, Yoda will automatically create one using thekeysas reference.For eachkeygiven upon creation, Yoda will ask the user in a user-friendly manner, what the data is.InputsfromyodasimportYodaYoda(path,keys=[])path:str(required)keys:listreturns:YodapathThis is the path to the JSON filekeysThis is a list of keys that will be in the JSON file. If the JSON file does not exist, Yoda will ask the user to fill out the JSON file based on the provided keys.
This is used by me personally to write scripts that require authentication.
For example in telegram, I don't want to have my first commits to have the telegram token.UsageTo implement a Yoda object>>>fromyodasimportYoda>>>yoda=Yoda("file.json",["ping!"])Executing this will result inFor each key, give its required value
ping!:Enteringpong!will save it to the JSON file. To check this, run>>>yoda.contents(){'ping!':'pong!'}To doublecheck this$catfile.json{"ping!":"pong!"}%Functionscontents>>>Yoda.contents()Will return the contents of the JSON file, reading from the disk everytime.returns:dictwrite>>>Yoda.write(contents)This will overwrite the existing JSON file with the variablecontents. Returnsboolif the operation was successful.contents:dictreturns:booldelete>>>Yoda.delete()Will delete the JSON file associated with the Yoda instance. Returns True if it was successful, False if nothing was deleted.returns:boolgetCreationTime>>>Yoda.getCreationTime()This will get the date the file was created in datetime format. If the file doesn't exist, it will return null.returns:datetime.datetimegetCreationTime>>>Yoda.getModificationTime()This will get the date the file was modified in datetime format. If the file doesn't exist, it will return null.returns:datetime.datetimegetPath>>>Yoda.getPath()Is used to get the path where the JSON file is stored.returns:strsetPath>>>Yoda.setPath(path)This used to set the pathpath:strTODOIn Yoda class, add option to have other variables like akey: list, orkey: dictrather than juststr: strIn Yoda class, add option to have custom questions rather than just reading keysIn Menu class, add argument managementFixcamelCaseSplit()wherethisIsATestresults inThis Is ATestChangelog1.4.1Added datetime utilities.AddedYoda.getCreationTime()which gets the creation/modifcation time of the filesAddedYoda.getModificationTime()AddedunixToDatetime()to convert unix timestamp to python datetimeReworked utilities1.4.0Adding more insight into the inner workings ofMenuAddedMenu.setLayout(layout)which customises the appearance of the MenuChangedMenu.add(item)toMenu.append(item)Added new functionMenu.pop()Added new functionMenu.remove(item)Fixed format issue inREADME1.3.1Adding return variables to all functions.Majorly reformatted README.mdYoda.delete()now returnsbooldepending on whether the operation was successful or not.Yoda.__setPath()now returnsboolif successfulYoda.write()returnsboolMenu.setExecute()returnsboolMenu.add()returnsbool1.3.0Major update to README.mdIn Yoda() changed name of functionopen()to__open()In Yoda() changed name of functionsetPath()to__setPath()In Menu() added new functionsetExecute()1.2.0Added full support to store items other than functionsIn Menu() added support to add new items after menu creation using Menu.add()In Menu() moved code to add items to Menu.add()1.1.1Added support to create empty YodaYoda("empty.json")will create a JSON with{}Fixed issue where even in empty Yoda files, it will ask for the details1.1.0Added support for string only menusChanged Menu.show() to Menu.select()Fixed issue where camelCaseSplit() wouldn't detect words with a length of 2Fixed issue whereupon creating Yoda, it won't ask for details until contents() is calledFixed issue in Yoda where if the path doesn't exist, Yoda will crash