site-proximo/zapette.py

38 lines
902 B
Python
Raw Normal View History

2019-08-02 09:34:15 +02:00
# run pip3 install requests
import requests
import json
API_ENDPOINT = "http://localhost/proximo/ajax/scan_article.php"
def get_password():
with open('pass') as f:
password = f.readline()
return password.strip()
def search_product(code):
# data to be sent to api
data = {
'password': get_password(),
'code': str(code)
}
# sending post request and saving response as response object
r = requests.post(url=API_ENDPOINT, data=json.dumps(data))
return r.text
def main():
code_input = input('Scannez le code\n')
try:
code = int(code_input)
result = search_product(code)
print(result)
except requests.exceptions.MissingSchema:
print("Format URL invalide !")
except requests.exceptions.ConnectionError:
print("URL invalide !")
except ValueError:
print("Code invalide !")
main()