nicho92 / MtgDesktopCompanion

Cards manager for magic the gathering
Apache License 2.0
155 stars 34 forks source link

Card Kingdom pricer timeout #222

Closed bewarellamas closed 1 year ago

bewarellamas commented 2 years ago

The CardKingdomPricer will only do about 15-20 cards at a time before it seems to lock out the web requests for the JSON data. The program already downloads the json data to a file (mtgkingdom.json in the data directory) and updates it the file is more than a day old. Is there a way to have the pricing data be pulled form the local file to avoid timeouts.

There are a number of check and special cases in the getUrlFor method that would need to be applied to the local file as well. Not sure if a new method would be needed for that.

bewarellamas commented 2 years ago

I am putting this in as an issue since I am not sure how to implement this. I can work on getting it going if there are too many other things in the pipe.

nicho92 commented 2 years ago

can you explain your manipulations ? i'm checking json file's date to download 1 time per day. if(!jsonFile.exists()|| FileTools.daysBetween(jsonFile)>1) { FileTools.saveFile(jsonFile, URLTools.extractAsJson(API_URI).toString()); }

bewarellamas commented 2 years ago

So it looks like I was wrong. It is referencing the file (did a test with a blank file), but the pricer will stop getting prices if you try processing too large of a request (over 20ish cards). Is there a reason it would stop pulling price data after a certain number of cards? It will usually start working again after waiting a couple minutes and trying again.

bewarellamas commented 2 years ago

Here are some logs. For clarification this is when using the price suggester button in the Stock screen.

Stopped working when I did a large batch of cards 2022-04-19 08:18:55 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 100 - Reading file C:\Users\bewar\.magicDeskCompanion\data\mtgkingdom.json with [?(@['name'] == 'Lost Hours' && @['sku'] CONTAINS 'FUT' && @['is_foil'] == 'false')] 2022-04-19 08:18:55 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 103 - Ending reading with 0 sec 2022-04-19 08:18:55 INFO org.magic.api.pricers.impl.CardKingdomPricer 158 - Card Kingdom looking for prices Lost Hours foil=false 2022-04-19 08:18:55 DEBUG org.magic.services.network.MTGHttpClient 107 - execute GET https://www.cardkingdom.com/mtg/future-sight/lost-hours HTTP/1.1 2022-04-19 08:18:55 INFO org.magic.api.pricers.impl.CardKingdomPricer 188 - Card Kingdom found 0 offers 2022-04-19 08:18:55 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 100 - Reading file C:\Users\bewar\.magicDeskCompanion\data\mtgkingdom.json with [?(@['name'] == 'Lost Hours' && @['sku'] CONTAINS 'FUT' && @['is_foil'] == 'true')] 2022-04-19 08:18:55 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 103 - Ending reading with 0 sec 2022-04-19 08:18:55 INFO org.magic.api.pricers.impl.CardKingdomPricer 158 - Card Kingdom looking for prices Lost Hours foil=true 2022-04-19 08:18:55 DEBUG org.magic.services.network.MTGHttpClient 107 - execute GET https://www.cardkingdom.com/mtg/future-sight/lost-hours-foil HTTP/1.1 2022-04-19 08:18:55 INFO org.magic.api.pricers.impl.CardKingdomPricer 188 - Card Kingdom found 0 offers

Worked a couple minutes later 2022-04-19 08:22:20 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 100 - Reading file C:\Users\bewar\.magicDeskCompanion\data\mtgkingdom.json with [?(@['name'] == 'Lost Hours' && @['sku'] CONTAINS 'FUT' && @['is_foil'] == 'false')] 2022-04-19 08:22:20 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 103 - Ending reading with 0 sec 2022-04-19 08:22:20 INFO org.magic.api.pricers.impl.CardKingdomPricer 158 - Card Kingdom looking for prices Lost Hours foil=false 2022-04-19 08:22:20 DEBUG org.magic.services.network.MTGHttpClient 107 - execute GET https://www.cardkingdom.com/mtg/future-sight/lost-hours HTTP/1.1 2022-04-19 08:22:21 INFO org.magic.api.pricers.impl.CardKingdomPricer 188 - Card Kingdom found 3 offers 2022-04-19 08:22:21 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 100 - Reading file C:\Users\bewar\.magicDeskCompanion\data\mtgkingdom.json with [?(@['name'] == 'Lost Hours' && @['sku'] CONTAINS 'FUT' && @['is_foil'] == 'true')] 2022-04-19 08:22:21 DEBUG org.magic.api.pricers.impl.CardKingdomPricer 103 - Ending reading with 0 sec 2022-04-19 08:22:21 INFO org.magic.api.pricers.impl.CardKingdomPricer 158 - Card Kingdom looking for prices Lost Hours foil=true 2022-04-19 08:22:21 DEBUG org.magic.services.network.MTGHttpClient 107 - execute GET https://www.cardkingdom.com/mtg/future-sight/lost-hours-foil HTTP/1.1 2022-04-19 08:22:22 INFO org.magic.api.pricers.impl.CardKingdomPricer 188 - Card Kingdom found 2 offers