skadogg / personal-tv-guide

Python-based JustWatch scraper
GNU General Public License v3.0
6 stars 7 forks source link

🐛 Error when saved_data.bin does not yet exist #94

Closed skadogg closed 6 months ago

skadogg commented 7 months ago

We need to test for the existance of saved_data.bin before trying to read from it. If it's not there, show_db should be initialized as an empty list.


PS C:\Users\gunner\Documents\git\personal-tv-guide> & c:/Users/gunner/Documents/git/personal-tv-guide/.venv/Scripts/python.exe c:/Users/gunner/Documents/git/personal-tv-guide/run.py

DevTools listening on ws://127.0.0.1:55958/devtools/browser/c7325439-6987-4945-82c9-57fb77f619e0
Signed in successfully
Traceback (most recent call last):
  File "c:\Users\gunner\Documents\git\personal-tv-guide\run.py", line 31, in <module>
    modules.justwatch.scrape_justwatch('TV')
  File "c:\Users\gunner\Documents\git\personal-tv-guide\modules\justwatch.py", line 157, in scrape_justwatch 
    show_db = modules.data_bin_convert.bin_to_data('./my_data/saved_data.bin')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\gunner\Documents\git\personal-tv-guide\modules\data_bin_convert.py", line 18, in bin_to_data
    fh = open(filename, 'rb')
         ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './my_data/saved_data.bin'

```PS C:\Users\gunner\Documents\git\personal-tv-guide> 
r3dp0int commented 7 months ago

you should just be able to do this with try except blocks

skadogg commented 7 months ago

I bet you're right, @r3dp0int. Sounds like a good first issue 😉 for someone who wants an easy way to begin contributing. Thanks for the suggestion!

r3dp0int commented 7 months ago

Which Python version are you using for this project?

skadogg commented 7 months ago

I'm pretty new to Python, so I'm using 3.12, though I don't know that there's anything too special going on that it wouldn't work with one or two earlier versions. I haven't tested with anything else yet.

r3dp0int commented 7 months ago

I've created a check for my data directory which will create it if it doesn't exist, and have implemented a check for the .bin file. Will finish implementing creation of the blank .bin file then issue a pull request for you 😄

skadogg commented 6 months ago

98 does fix this for me.

image