archivesunleashed / auk-notebooks

Jupyter notebooks to assist in creating additional analysis and visualizations of Archives Unleashed Cloud derivatives.
https://cloud.archivesunleashed.org
Other
11 stars 5 forks source link

Add class call to write_output(). #54 #55

Closed greebie closed 5 years ago

greebie commented 5 years ago

This change adds the class call (nb.) to write_output() and adds the new version of au-notebook to requirements.txt.

To test:

spin the notebook remove comment from this line in cell 6. # nb.write_output(filename, year_results)

Run the notebook.

(Again, if you already have the notebook running, you will need to restart and run all).

ianmilligan1 commented 5 years ago

I can't get this to work.

Am now on the right version of au-notebook

Requirement already satisfied: au-notebook==0.0.3 in /Users/ianmilligan1/anaconda/lib/python3.5/site-packages (from -r requirements.txt (line 1)) (0.0.3)

But

nb.write_output(filename, year_results)

still leading to

Error writing the file.

This is out of the box on MacOS, running pip install -r requirements.txt and then jupyter notebook.

ianmilligan1 commented 5 years ago

Did a bit more testing.

If I set up the function locally i.e.

def write_output2(self, stdout, results):
        """ Writes results to file.
        :param stdout: Filepath for file.
        :param results: A list of results.
        :return: None.
        """
        try:
            with open(stdout, "w") as output:
                for value in results:
                    output.write(str(value))
        except Exception as exp:
            print("Error writing the file.")

then running

write_output2(filename, year_results)

gives me this error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-f3735c684425> in <module>()
     13 ## or nb.output_filename (set in the User Configuration section).
     14 
---> 15 write_output2(filename, year_results)

TypeError: write_output2() missing 1 required positional argument: 'results'

Is it working on your end, @greebie ?

ianmilligan1 commented 5 years ago

I should note that it works with Binder.. so something a bit funky with running it locally here. I may also be missing something obvious. 😄

ruebot commented 5 years ago

Weird. Can you try pip install --upgrade aut-notebook before you fire up the notebook, and see if that works?

It's working for me locally, and I just fired it up with the Docker build too, and it ran fine.

Screenshot from 2019-04-24 23-45-07

Screenshot from 2019-04-24 23-42-15

Screenshot from 2019-04-24 23-42-25

greebie commented 5 years ago

Not sure why it should not work. I think the problem with write_output2 is that you do not need 'self' in a simple function that is not part of a class.

Can you do a 'restart and run all' and try again? That always messes me up. But yeah I had the same result as Nick.