kacpi2442 / am_bot

Using the toogoodtogo and foodsi APIs to notify me via a Telegram bot for open offers
40 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?

Robertnoob12 commented 1 year ago

@antonioli86 (most recent call last): File "C:\Users\rober\OneDrive\Pulpit\am_bot-main\watch_script.py", line 239, in refresh foodsi() File "C:\Users\rober\OneDrive\Pulpit\am_bot-main\watch_script.py", line 159, in foodsi items = parse_foodsi_api(foodsi_api.json()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\rober\OneDrive\Pulpit\am_bot-main\watch_script.py", line 121, in parse_foodsi_api for restaurant in api_result['data']:


KeyError: 'data'
Robertnoob12 commented 1 year ago

Can u get it working to me so it can check only favorites items if anything is available bc the code u told me doesnt work @antonioli86

antonioli86 commented 1 year ago

I had some spare time... check only favorites items is more complex since is not possible to filter out in the GET request. I tried to use some filters and do not work. Also in app is not possible to filter the favorites based on availability. Request to see the favorites and see the related offers: https://api.foodsi.pl/api/v3/user/favourites?include=package.current_offer Only filter possible to use is the one related with deliveries not.

To do a bot only for the favorites is necessary to go offer by offer from the response and check current_quantity and so on. @Robertnoob12, please ignore what I wrote before. That URL before just returns the favorites ids. Sorry for that.

I updated the general script: watch_script2.zip

Maybe you will note some repeated offers... it is coming directly from the Foodsi API, is not generated by this code.

Robertnoob12 commented 1 year ago

@antonioli86 it can to check offers its not necessary to check favorites. I favorited all avilable products when u load in the app.

Robertnoob12 commented 1 year ago

Could u make it work so it checks offers @antonioli86 like main page ones if u cant favorites like to give me the foodsi_api request get whole code

antonioli86 commented 1 year ago

Updated code is above - few minutes ago. For now working: image

Robertnoob12 commented 1 year ago

Updated code is above - few minutes ago. For now working: image

Works for all offers available for app or only favorites bc as i told earlier i have 10 shops in my app that use foodsi so if any of these will drop any available it will send notifitation?

Robertnoob12 commented 1 year ago

Or i will have to use this code @antonioli86 related offers: https://api.foodsi.pl/api/v3/user/favourites?include=package.current_offer Only filter possible to use is the one

antonioli86 commented 1 year ago

Updated code is above - few minutes ago. For now working: image

Works for all offers available for app or only favorites bc as i told earlier i have 10 shops in my app that use foodsi so if any of these will drop any available it will send notifitation?

Works to all offers in the range you defined in the app (with your user account) - first tab in the app. For favorites only is necessary to update the code. image

Robertnoob12 commented 1 year ago

Ill test it at home

Robertnoob12 commented 1 year ago

Updated code is above - few minutes ago. For now working: image

Works for all offers available for app or only favorites bc as i told earlier i have 10 shops in my app that use foodsi so if any of these will drop any available it will send notifitation?

Works to all offers in the range you defined in the app (with your user account) - first tab in the app. For favorites only is necessary to update the code. image

Ok thats good so i can just run the python code u sent and ill be fine?

Robertnoob12 commented 1 year ago

Hopefully no updates soon. It took a long time to get it working ugh

Robertnoob12 commented 1 year ago

theres a problem @antonioli86 back home and ugh... it grabs info from not my location.

Robertnoob12 commented 1 year ago

and it crashes after

antonioli86 commented 1 year ago

Are you using same user in the script config as in the app? In my side is still running and no issues.

Robertnoob12 commented 1 year ago

image

Robertnoob12 commented 1 year ago

image im not from there either

Robertnoob12 commented 1 year ago

oh wait

Robertnoob12 commented 1 year ago

image now this i changed the details the acc was outdated i think

Robertnoob12 commented 1 year ago

it was working earlier now its completely broken

Robertnoob12 commented 1 year ago

image its a good config i guess?

Robertnoob12 commented 1 year ago

below email is password

Robertnoob12 commented 1 year ago

Are you using same user in the script config as in the app? In my side is still running and no issues.

and yeah

antonioli86 commented 1 year ago

Did you changed anything in the code I sent. like the request? Confirm if the details of you user are fine - in the code do a request to https://api.foodsi.pl/api/v3/user/users/current and print the result. It should be something like: image

Then you confirm if the coordinates and range are fine.

Robertnoob12 commented 1 year ago

https://api.foodsi.pl/api/v3/user/users/current

i cant do anything image

Robertnoob12 commented 1 year ago

everytime i open that happens

antonioli86 commented 1 year ago

You need to debug... add a print in the code after the request (like print(foodsi_api.json()) ). this will fail - is normal - is just to test. You dont need to put the result here... just check if the coordinate and the range are fine

Robertnoob12 commented 1 year ago

You need to debug... add a print in the code after the request (like print(foodsi_api.json()) ). this will fail - is normal - is just to test. You dont need to put the result here... just check if the coordinate and the range are fine

it must be ok image

Robertnoob12 commented 1 year ago

it was ok earlier and it broke somehow when i switched to the acc i was using on foodsi...

Robertnoob12 commented 1 year ago

when i added print(foodsi_api.json()) it crashed insta

antonioli86 commented 1 year ago

App will crash... check in the window the output. "when i switched to the acc " - I dont understand.

Robertnoob12 commented 1 year ago

i made a new account , deleted the old one edited the config same issue

Robertnoob12 commented 1 year ago

App will crash... check in the window the output. "when i switched to the acc " - I dont understand.

i logged out and logged in the account that i used on the Foodsi config, then it broke

antonioli86 commented 1 year ago

So its normal that app crashed. Please update in the app all parameters - location and range. Then in config put this new user and password and start application.

Robertnoob12 commented 1 year ago

do i have to change this foodsi_api = requests.get('https://api.foodsi.pl/api/v3/user/offers?filter[package_category_ids][not_eq]=[13]&filter[package_category_ids][eq]=[9,1]&filter[active][eq]=true&filter[current_quantity][gt]=0&filter[pickup_to][gt]='+waw_dt.strftime('%Y-%m-%dT%H:%M:%S%z')+'&page[size]=15&sort=distance,pickup_from', 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})

Robertnoob12 commented 1 year ago

So its normal that app crashed. Please update in the app all parameters - location and range. Then in config put this new user and password and start application.

i dont mean the app, the whole python script before i ran it showed information that some products were available but now it shows me KeyError: 'links'

the products were not in my city by the way

antonioli86 commented 1 year ago

do i have to change this foodsi_api = requests.get('https://api.foodsi.pl/api/v3/user/offers?filter[package_category_ids][not_eq]=[13]&filter[package_category_ids][eq]=[9,1]&filter[active][eq]=true&filter[current_quantity][gt]=0&filter[pickup_to][gt]='+waw_dt.strftime('%Y-%m-%dT%H:%M:%S%z')+'&page[size]=15&sort=distance,pickup_from', 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})

If you want to debug, change that to foodsi_api = requests.get('https://api.foodsi.pl/api/v3/user/users/current', 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})

and add below

print(foodsi_api.json())

App will crash. Check is if your account details are fine.

Robertnoob12 commented 1 year ago

it doesnt work ill try to record

Robertnoob12 commented 1 year ago

zip.zip

antonioli86 commented 1 year ago

it doesnt work ill try to record

Should be something like that in the code. image

Then when you run will crash but will appear the results in the window: image

Robertnoob12 commented 1 year ago

and as u can see the update date of the json file it is same as before, nothing changed @antonioli86

Robertnoob12 commented 1 year ago

ill try like u do

antonioli86 commented 1 year ago

zip.zip

You need to run from command line to debug. CMD Then go to the folder where you have the script python3 "script name"

image

Robertnoob12 commented 1 year ago

ugh... image

Robertnoob12 commented 1 year ago

image

Robertnoob12 commented 1 year ago

i got it working @antonioli86

antonioli86 commented 1 year ago

App crashes - is normal. coordinates and range are fine? If yes - put the original code and should be fine.

Robertnoob12 commented 1 year ago

it didnt crash @antonioli86

Robertnoob12 commented 1 year ago

i updated coordinates

Robertnoob12 commented 1 year ago

OFCOURSE!!! image