Package: nb-search
nb_search.pyHave you ever needed to find a old Jupyter Notebook file but forgot where you put it :grimacing: ?  Do you remember the packages you used :thinking: or maybe some of the terms you may have put in the markdown?  If so then this package will be a useful tool for you!  After learning the uses of this package you can even save valuable notebooks for later use by adding TODO tags.  This is all explained in detail below.High Level DescriptionThis is a package that can be used to search through jupyter notebooks at or below a specified directory.  There are many different ways to use the package to refine the search or visualize the notebooks.  I will go through most of them below.Installingnb_search$pipinstallnb_searchUsesAll of the uses below (except for fsearch) can be used in IPython console and in a Jupyter Notebook itself.  Using it in a Jupyter Notebook is straight forward.  To use it in a IPython console start by entering%run nb_search.pyinto the IPython console along with the optional arguments and directory (or list of files) you would like to search through.allThis is the most basic argument and does not allow any further arguments with it.  It simply searches the desired directory for all of the notebook files and displays them as clickable HTML links to the notebooks.  The syntax for using this is shown below:IPython Console%runnb_search.py--allJupyter Notebookfromnb_searchimportsearch_filesfiles=search_files('PATH_TO_DIRECTORY')^^ You may simply run the function without any arguments.  This will recursively search through the current directory.codeThis argument will allow you to search all of the code cells of the notebooks in your specified directory for a string given and will return the notebooks that have the string in one or more of their cells.  An example of using this to search for the variable "x" is shown below:IPython Console%runnb_search.py--code'.'xJupyter Notebookfromnb_searchimportsearch_notebookfiles=search_notebook('x','code','PATH_TO_DIRECTORY')markdownThis is the same concept as the code argument but in the markdown cells.An example of using this to search the markdown cells for the word "title" is shown below:IPython Console%runnb_search.py--markdown'.'titleJupyter Notebookfromnb_searchimportsearch_notebookfiles=search_notebook('title','markdown','PATH_TO_DIRECTORY')headingThis is close to the markdown argument but instead of searching the entire markdown cell it only looks in the headings.  An example of using this to find the word "title" is shown below:IPython Console%runnb_search.py--heading'.'titleJupyter Notebookfromnb_searchimportsearch_headingfiles=search_heading('title','PATH_TO_DIRECTORY')heading_ppOnce you have found a jupyter notebook you want to know more about but don't want to open yet you can useheading_pp_ to get a pretty printed display of the headings in the file.  An example of how to do that is shown below:IPython Console%runnb_search.py--heading_pp'./notebook.ipynb'Jupyter Notebookfromnb_searchimportheading_pprintfiles=heading_pprint('PATH_TO_DIRECTORY')propertyFor my research groups HER project this is the most refined search.  You are able to search based on one to three things which must be seperated by an "and".Metal A - You can specify a metal to search the notebooks for.Metal B - You can specify a second metal you would like the search for.Max_H - You may specify the max Hydrogen to be below or above a certain value with the logical operators "<" and ">"The order in which you enter the metals or even the Max_H does not matter as long as each specification is seperated by an "and".Below are 2 examples of using the property argument.  The first is just to find any notebook with the metal Mo in it.  The second is to find any notebook with Mo and a Max_H of below 8.0 micromoles.IPython Console%runnb_search.py--property'.'Mo%runnb_search.py--property'.'MoandMax_H<8.0Jupyter Notebookfromnb_searchimportsearch_datafiles=search_data('Mo and Max_H < 8.0','PATH_TO_DIRECTORY')todoIf you have a specific notebook you would like to tag as TODO then you can search for it with this.  You can also put an optional description and due date (in brackets) that will be displayed above the notebook link.  The syntax for this is shown below and can be put in any code cell in a notebook:%TODO[YEAR-MONTH-DAY]OptionalDescriptionThe todo option is simple and only requires the user input the directory they would like to search through or '.' for the current one as shown below:IPython Console%runnb_search.py--todo'.'Jupyter Notebookfromnb_searchimportsearch_todofiles=search_todo('PATH_TO_DIRECTORY')fsearchThis is the exact same concept as the property option but can allow for more complicated queries of the three properties.  The user must input a function that returns True for the files he would like to view.  An example of the syntax of this function is shown below:deff(NB):p1=NB.property['Metal_A']=='Pt'p2=NB.property['Metal_B']=='Pt'p3=NB.property['Max_H']>47return(p1orp2)andp3Then the user can search for files in the current directory that have 'Pt' as either metal A or metal B, as well as, a max_H greater that 47 micromoles by using the function as shown below:fromnb_searchimportfsearchfiles=fsearch(f,'.')Demonstration of UseMost of the search functions output a list of the files that can then be used instead of a directory path to refine a search.  That capability along with the TODO search are shown below:Developing nb_searchTo install nb_search, along with the tools you need to develop and run tests, run the following in your virtualenv:$pipinstall-e.[dev]