kacpi2442 / am_bot

Using the toogoodtogo and foodsi APIs to notify me via a Telegram bot for open offers
41 stars 18 forks source link

Foodsi - new error #31

Open antonioli86 opened 1 year ago

antonioli86 commented 1 year ago

Hi,

Seems with latest update they changed something:

Error occured: 
 (most recent call last):
  File "/home/cmjr86/.local/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/cmjr86/Downloads/am_bot-main1/watch_script.py", line 247, in refresh
    foodsi()
  File "/home/cmjr86/Downloads/am_bot-main1/watch_script.py", line 166, in foodsi
    items += parse_foodsi_api(foodsi_api.json())
  File "/home/cmjr86/.local/lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Someone already debug it?

antonioli86 commented 1 year ago

How will it check if a specific product jumps to 1 qty. Instead of 0. In that code u sent i saw theres 0 qty

Brace yourself. :P In the request from app I see (after decoding URL): https:\/\/api.foodsi.pl\/api\/v3\/user\/offers?filter[package_category_ids][not_eq]=[13]&filter[pickup_to][gt]=2023-09-20T23:18:44+02:00&filter[package_category_ids][eq]=[9, 1]&filter[active][eq]=true&filter[current_quantity][gt]=0&sort=distance,pickup_from

Robertnoob12 commented 1 year ago

How will i be able to set the bot up then, would need to add 9 shops if theres that much? @antonioli86

antonioli86 commented 1 year ago

How will i be able to set the bot up then, would need to add 9 shops if theres that much? @antonioli86

Current quantity bigger than 0 - as filter in URL: https://api.foodsi.pl/api/v3/user/offers?filter[active][eq]=true&filter[current_quantity][gt]=0

Robertnoob12 commented 1 year ago

Do you have any ideas how to implement the code into foodsi notify bot though

antonioli86 commented 1 year ago

Do you have any ideas how to implement the code into foodsi notify bot though

First would like to filter by region - find out the proper request - and then work on the parse. Bot already manages it based on monitoring the quantity.

        # Check, if the stock has changed. Send a message if so.
        if new_stock != old_stock:

Is just a matter to change to the proper variable names based on the new structure.

Robertnoob12 commented 1 year ago

what do you need help with that i can help you implementing the code. because i dont know the way how to implement it i can help u finding apis for specific things etc @antonioli86

antonioli86 commented 1 year ago

what do you need help with that i can help you implementing the code. because i dont know the way how to implement it i can help u finding apis for specific things etc @antonioli86

First would be perfect to find out the correct request body to filter by area based on the coordinate and range. Old request json format does not work.

Robertnoob12 commented 1 year ago

what do you need help with that i can help you implementing the code. because i dont know the way how to implement it i can help u finding apis for specific things etc @antonioli86

First would be perfect to find out the correct request body to filter by area based on the coordinate and range. Old request json format does not work.

could u tell me where should i find this

Robertnoob12 commented 1 year ago

and ill try then

Robertnoob12 commented 1 year ago

because i have no idea where should i find these @antonioli86

antonioli86 commented 1 year ago

what do you need help with that i can help you implementing the code. because i dont know the way how to implement it i can help u finding apis for specific things etc @antonioli86

First would be perfect to find out the correct request body to filter by area based on the coordinate and range. Old request json format does not work.

could u tell me where should i find this

No idea at this moment. :(

Robertnoob12 commented 1 year ago

@antonioli86 how did yall make it compatible with the old version then

antonioli86 commented 1 year ago

Maybe someone is working is parallel and will help us here... 🥇

Robertnoob12 commented 1 year ago

Maybe someone is working is parallel and will help us here... 🥇

i dont think so we are the only ones talking there we might work on ourselves for now

Robertnoob12 commented 1 year ago

@antonioli86 i feel like nobody will help

paweleck commented 1 year ago

If you want you can filter by given name

...&filter[venue_name][eq]=Kuchnia Vikinga Kawaleryjska

Robertnoob12 commented 1 year ago

If you want you can filter by given name

...&filter[venue_name][eq]=Kuchnia Vikinga Kawaleryjska

i have 9 shops in my app. i would need to filter 9 shops all by 1

Robertnoob12 commented 1 year ago

i hope there will be a solution soon i dont wanna miss any packages lol they get sold quick still probably even when there are no notify bots

Robertnoob12 commented 1 year ago

@antonioli86 have u tried chatgpt?? to maybe help

patrykskrzyniarz commented 1 year ago

If you want you can filter by given name ...&filter[venue_name][eq]=Kuchnia Vikinga Kawaleryjska

i have 9 shops in my app. i would need to filter 9 shops all by 1

you can ask for specific names in one endpoint

e.g.

https://api.foodsi.pl/api/v3/user/offers?filter[venue_name][]=Piekarnia Szwajcarska Światowida&filter[venue_name][]=Kuchnia Vikinga Kawaleryjska
antonioli86 commented 1 year ago

Updated version - not fully tested but seems fine: watch_script2.zip

I was "sleeping" when I was writing about request body... now is a GET request, not a POST as before, so no body is passed. All goes in the filter. Coordinates and distance are taken from user profile (from the authentication) - information is visible on https://api.foodsi.pl/api/v3/user/users/current

In filter I'm passing several things: [package_category_ids][not_eq]=[13] - this is to exclude Dostawa [package_category_ids][eq]=[9,1] - I want only meals and Bread & Pastries [active][eq]=true - only active [current_quantity][gt]=0 - meals available bigger than 0 [pickup_to][gt]='+waw_dt.strftime('%Y-%m-%dT%H:%M:%S%z') - offer that are available to pick in the future. Without this filter from API comes packages that were not picked up - current_quantity is bigger than 0 but time to pickup already passed.

Other thing I did - removed the loop to go page by page and increased the page size to 50. I don't expect more than 50 offers active... if someone has more can increase it or can always try do the loop the check page by page.

Robertnoob12 commented 1 year ago

I will test on poznań, because everything is available there

Robertnoob12 commented 1 year ago

@antonioli86 doesnt seem to work, after i open it closes after few seconds i noticed its flashing some code

antonioli86 commented 1 year ago

It was working but now I have timeout in the telegram part - also I changed a bit from original code. :( Later I will check.

Robertnoob12 commented 1 year ago

It was working but now I have timeout in the telegram part - also I changed a bit from original code. :( Later I will check.

could u send me the new code, it seems to work for me it now prints "total foodsi items 50" do i have to change anything in the code? or if the lang and long / distance is in my city its fine in the config ? @antonioli86

Robertnoob12 commented 1 year ago

image

Robertnoob12 commented 1 year ago

pls send me the new code lol... telegram i think is rate limiting

antonioli86 commented 1 year ago

Seems is the same issue I have... only later or tomorrow will check.

Robertnoob12 commented 1 year ago

@antonioli86 its not about the foodsi its working fine.. the telegram bot is rate limiting

antonioli86 commented 1 year ago

@antonioli86 its not about the foodsi its working fine.. the telegram bot is rate limiting

I know. I should not use big page size - need to limit (or keep 20) and do a loop as before.

Robertnoob12 commented 1 year ago

how can i change to my favorite item it keeps sending cofix instead of my product @antonioli86

Robertnoob12 commented 1 year ago

and the sofix is not even in my city. something bugged

antonioli86 commented 1 year ago

how can i change to my favorite item it keeps sending cofix instead of my product @antonioli86

Change in line of request to this foodsi_api = requests.get('https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13]', headers = {'Content-type':'application/json', 'system-version':'android_3.0.0', 'user-agent':'okhttp/3.12.0', 'Access-Token': access_token, 'Client': client, 'Uid': uid})

antonioli86 commented 1 year ago

and the sofix is not even in my city. something bugged

Please be patient. :) For favorites seems fine... imagem

Robertnoob12 commented 1 year ago

if ill add 9 favorites all with other filters like coffee, cakes, then pizza and other will be fine?

antonioli86 commented 1 year ago

if ill add 9 favorites all with other filters like coffee, cakes, then pizza and other will be fine?

Check above. Remove all filters except the one for deliveries (Dostawa) - https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13]

Robertnoob12 commented 1 year ago

omg.. it works

Robertnoob12 commented 1 year ago

if ill add 9 favorites all with other filters like coffee, cakes, then pizza and other will be fine?

Check above. Remove all filters except the one for deliveries (Dostawa) - https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13]

is it setup only for dostawa?

Robertnoob12 commented 1 year ago

@antonioli86 but my all products have "Odbiór Osobisty" not "Dostawa" is that fine?

Robertnoob12 commented 1 year ago

Screenshot_20230922_080806_foodsi.jpg

Robertnoob12 commented 1 year ago

Will it really work @antonioli86 ? I set it up with my city favourites and ran the script. However i didnt add the current_quantity qt option and when i changed lang and long to poznań and added to favourites some available items it didnt work

Robertnoob12 commented 1 year ago

Tell me please

antonioli86 commented 1 year ago

if ill add 9 favorites all with other filters like coffee, cakes, then pizza and other will be fine?

Check above. Remove all filters except the one for deliveries (Dostawa) - https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13]

is it setup only for dostawa?

This is only to pickup (odbior) - not equal to 13. If you want all, remove the filter.

Robertnoob12 commented 1 year ago

https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13] But after i add no filter will it still notify me if any product gets on stock ? @antonioli86 And it should look like this after i remove the filter? https://api.foodsi.pl/api/v3/user/favourites Or should i replace it with https://api.foodsi.pl/api/v3/user/favourites?filter[current_quantity][gt]=0

Because [current_quantity][gt]=0 - meals available bigger than 0 Could u send me the code so it will check my all favourites if they are more than 1 on stock? Then send me notify

Robertnoob12 commented 1 year ago

if ill add 9 favorites all with other filters like coffee, cakes, then pizza and other will be fine?

Check above. Remove all filters except the one for deliveries (Dostawa) - https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13]

is it setup only for dostawa?

This is only to pickup (odbior) - not equal to 13. If you want all, remove the filter.

And its not equal to 13 what? Currency i dont understand

Robertnoob12 commented 1 year ago

https://api.foodsi.pl/api/v3/user/favourites?filter[package_category_ids][not_eq]=[13] But after i add no filter will it still notify me if any product gets on stock ? @antonioli86 And it should look like this after i remove the filter? https://api.foodsi.pl/api/v3/user/favourites Or should i replace it with https://api.foodsi.pl/api/v3/user/favourites?filter[current_quantity][gt]=0

Because [current_quantity][gt]=0 - meals available bigger than 0 Could u send me the code so it will check my all favourites if they are more than 1 on stock? Then send me notify

Would help me alot if u could give me the ready code to check all my 9 favorites some are 25 pln some are less.

antonioli86 commented 1 year ago

@Robertnoob12 - I only can back to this later...

Robertnoob12 commented 1 year ago

@Robertnoob12 - I only can back to this later...

But u know how to do it? I think u just need to change the api right? To make it work on all my favorites i have 10 right now and to make the bot notify me when 1 will get to any stock when it checks like from sold out to last one available @antonioli86

antonioli86 commented 1 year ago

@Robertnoob12 - I only can back to this later...

But u know how to do it? I think u just need to change the api right? To make it work on all my favorites i have 10 and to make the bot notify me when 1 will get to any stock when it checks like from sold out to last one available or any @antonioli86

So the request should be as you wrote - https://api.foodsi.pl/api/v3/user/favourites?filter[current_quantity][gt]=0

Robertnoob12 commented 1 year ago

@Robertnoob12 - I only can back to this later...

But u know how to do it? I think u just need to change the api right? To make it work on all my favorites i have 10 and to make the bot notify me when 1 will get to any stock when it checks like from sold out to last one available or any @antonioli86

So the request should be as you wrote - https://api.foodsi.pl/api/v3/user/favourites?filter[current_quantity][gt]=0

@antonioli86 so it will check my favourites. If any goes on available it sends me to telegram bot that the specific shop got a item available right? The price wont matter?