r/pythonhelp • • May 27 '23

Script not skipping scanning for volumes that have already been scanned less than one week ago

In order to reduce the amount of api calls my script does I wanted to setup a number of things like only scan for ongoing series or new series added to the comicvine website. then i created other checks like if a series has not had a new issue in 13 months mark as complete and finally if a series has already been scanned in the last seven days skip it. Issue is like my title says its still scanning for them and updating data that does not need to be updated. I know there are other issues with my script such as fields setup in the database which are not called for and lack of logging when I see under last modified for the db files it keeps updating but i dont have logs as to what its doing. I am sure there are other issues others but I am pretty new to python and need to focus on one issue at a time. here is my current script:

https://pastebin.com/ra6VrPQ8

3 Upvotes

7 comments sorted by

1

u/CraigAT May 27 '23 edited May 27 '23
  • When you look at the database, how many last scan dates are within a week? (Is the saved data correct?) - Just seen you are not using individual dates, instead using the entry in last_update_table.

  • If you run the query that gets the last scan dates, do you get what you expect? (Test the query)

  • If you run the api call with the parameters you are specifying do you get the result you expect (the API may not give the results you expect)

1

u/Xx255q May 27 '23

The script for example had a volume of a last scan date of 5-23 but still scanned for the volume two days later and updated the last scan date to 5-25. It seems to get the information but can't figure out to skip the volumes it should

1

u/CraigAT May 27 '23

Second look, as far as I can see you never call save_last_updated to update the last scan date.

1

u/Xx255q May 27 '23

How do I change the script to make the change and can you explain more?

1

u/CraigAT May 27 '23

Check out if your last_update table has an entry each time you run the program?

As far as I could see, you have created a function called save_last_update but you never use it or call it. You need to find an appropriate spot in your code (probably after you have done the updates) to call that function and add a new entry to the table, for the update you have just done.

2

u/Xx255q May 27 '23

That gives me an idea to put in somewhere in my main function before all the scanning start so that it knows not to call the API/site for them?

1

u/CraigAT May 27 '23 edited May 27 '23

As I see it, the purpose of the function would be to add an entry to say you have just done an update, so I would have thought it should go at the end. But there are many ways to do what you want.

If possible, my approach would be as you suggested, to use the API to grab a big list of volumes/series (high level, not detailed), then compare that to what is in your database, to update the database and create a separate list of what you want to query in more detail from the API.