kacpi2442 / am_bot

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

Foodsi - uwierzytelnianie #29

Open Wiedmolol opened 1 year ago

Wiedmolol commented 1 year ago

Wygląda na to, że Foodsi wprowadziło dzisiaj autentykację do requestów po API. W tym momencie API zwraca:

{
    "errors": [
        "Aby kontynuować zaloguj lub zarejestruj się."
    ]
}
Robertnoob12 commented 1 year ago

image

Robertnoob12 commented 1 year ago

should be like this?

antonioli86 commented 1 year ago

should be like this?

Yes, and edit the request after to includes authentication headers: foodsi_api = requests.post('https://api.foodsi.pl/api/v2/restaurants', 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}, data = json.dumps(req_json))

antonioli86 commented 1 year ago

image

Its repeated... I see two "try". Should be only one:

imagem

Robertnoob12 commented 1 year ago

yeah, i noticed that too

Robertnoob12 commented 1 year ago

where do i put foodsi_api = requests.post('https://api.foodsi.pl/api/v2/restaurants', 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}, data = json.dumps(req_json))

antonioli86 commented 1 year ago

where do i put foodsi_api = requests.post('https://api.foodsi.pl/api/v2/restaurants', 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}, data = json.dumps(req_json))

You need to replace the original one: foodsi_api = requests.post('https://api.foodsi.pl/api/v2/restaurants', headers = {'Content-type':'application/json', 'system-version':'android_3.0.0', 'user-agent':'okhttp/3.12.0'}, data = json.dumps(req_json))

Or just add the part " 'Access-Token': access_token, 'Client': client, 'Uid': uid}" after the user-agent (and before data).

Robertnoob12 commented 1 year ago

it doesnt work

Robertnoob12 commented 1 year ago

image

antonioli86 commented 1 year ago

it doesnt work

Attach here your python please.

Robertnoob12 commented 1 year ago

maybe im too stupid to understand

Robertnoob12 commented 1 year ago

it doesnt support the type of file

antonioli86 commented 1 year ago

maybe im too stupid to understand

No... just zip the file and attach here.

Robertnoob12 commented 1 year ago

ok

Robertnoob12 commented 1 year ago

sorry had to edit the zip

Robertnoob12 commented 1 year ago

am.zip

Robertnoob12 commented 1 year ago

everything good? or bad news

antonioli86 commented 1 year ago

Here works: imagem

Do you have in same folder the config.json?

imagem

Robertnoob12 commented 1 year ago

yup, i have in same folder config_example.json and config.json

Robertnoob12 commented 1 year ago

could you send over the watch_script1.py

antonioli86 commented 1 year ago

yup, i have in same folder config_example.json and config.json

You can delete the example...

This is the python file I used: watch_script1.zip Just copied the code from the one you provided.

Robertnoob12 commented 1 year ago

thanks ill try now

Robertnoob12 commented 1 year ago

do i have to open it from python3 command or i can open it from the directory itself, because from the directory the file u sent me it doesnt open, it loads then crashes after like 1 milisecond

antonioli86 commented 1 year ago

You run it from the folder (with all files) using python3...

and the structure of the config.json imagem

imagem

Robertnoob12 commented 1 year ago

it works but after typing the email and confirming it crashes

Robertnoob12 commented 1 year ago

now i found why it wasnt working earlier, because something is wrong

Robertnoob12 commented 1 year ago

do you know the solution lol

antonioli86 commented 1 year ago

do you know the solution lol

So what was the issue?

Robertnoob12 commented 1 year ago

do you know the solution lol

So what was the issue?

probably something wrong with TGTG code 70% sure

Robertnoob12 commented 1 year ago

because after logging in , then opening the python code it crashes instantly like after i done the verification

antonioli86 commented 1 year ago

do you know the solution lol

So what was the issue?

probably something wrong with TGTG code 70% sure

I'm not able to help here :( Also some remarks: this script use tgtg python library (https://pypi.org/project/tgtg/) - https://github.com/Der-Henning/tgtg not.

Robertnoob12 commented 1 year ago

i will just use the one that u used

antonioli86 commented 1 year ago

And after create a new account... I have same issue... maybe in free time I can debug - need to extended code: imagem

I login successfully and then when I run... badum tss.

Robertnoob12 commented 1 year ago

yea, same thing. i added the schedule to the tgtg scanner u told me works good

Robertnoob12 commented 1 year ago

hey i have last question @antonioli86 with the TGTG scanner it only scans your favorites ? right u can have as many ? or theres a limit

antonioli86 commented 1 year ago

I found the issue in the code... for some reason me or you deleted the refresh part after the foodsi function. watch_script1.zip

Missing code: imagem

This works. Some characters are messed up but you can fix.

About TGTG scanner - it only scans favorites. No limits.

Robertnoob12 commented 1 year ago

good one, i think ill stay with the TGTG scanner, but people can check this issue forum and use ur watch script, because ntfy.sh is so good, if u click it brings you to the shop instantly

antonioli86 commented 1 year ago

good one, i think ill stay with the TGTG scanner, but people can check this issue forum and use ur watch script, because ntfy.sh is so good, if u click it brings you to the shop instantly

Check my update... I tested and works. ;) Was missing the code to start the watch and refresh. I dont know at which stage this piece of code disappeared lol

Robertnoob12 commented 1 year ago

good one, i think ill stay with the TGTG scanner, but people can check this issue forum and use ur watch script, because ntfy.sh is so good, if u click it brings you to the shop instantly

Check my update... I tested and works. ;) Was missing the code to start the watch and refresh. I dont know at which stage this piece of code disappeared lol

sure sir will do 1s

Robertnoob12 commented 1 year ago

works 100%

antonioli86 commented 1 year ago

works 100%

All because that "bloody" piece of code that disappeared somehow. :P Enjoy!

Robertnoob12 commented 1 year ago

the last test will be tomorrow, all surprise bags got sold. so the only way to test 100% is to wait till tomorrow and check then

Robertnoob12 commented 1 year ago

theres none TGTG checkers less than 1 minute right? @antonioli86

antonioli86 commented 1 year ago

theres none TGTG checkers less than 1 minute right? @antonioli86

Far as I know - no.

Robertnoob12 commented 1 year ago

thank you for talking to me, and helping.

antonioli86 commented 1 year ago

the last test will be tomorrow, all surprise bags got sold. so the only way to test 100% is to wait till tomorrow and check then

Tested? About schedule every minute... TGTG scanner uses crontab and crontab does not go down to sub-minute resolution. Here am_bot uses schedule and sleep... you can try change the code - in the refresh function - to run at level of seconds: https://www.alixaprodev.com/how-to-execute-a-function-every-x-seconds-in-python/

antonioli86 commented 11 months ago

@Kirri777 @grutkowski-doz can help here - https://github.com/kacpi2442/am_bot/issues/31 ?

Robertnoob12 commented 11 months ago

yes please !!!