Site du proximo, utilisé pour gérer le stock.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zapette.py 927B

12345678910111213141516171819202122232425262728293031323334353637
  1. # run pip3 install requests
  2. import requests
  3. import json
  4. API_ENDPOINT = "https://srv-falcon.etud.insa-toulouse.fr/~proximo/ajax/scan_article.php"
  5. def get_password():
  6. with open('pass') as f:
  7. password = f.readline()
  8. return password.strip()
  9. def search_product(code):
  10. # data to be sent to api
  11. data = {
  12. 'password': get_password(),
  13. 'code': str(code)
  14. }
  15. # sending post request and saving response as response object
  16. r = requests.post(url=API_ENDPOINT, data=json.dumps(data))
  17. return r.text
  18. def main():
  19. code_input = input('Scannez le code\n')
  20. try:
  21. code = int(code_input)
  22. result = search_product(code)
  23. print(result)
  24. except requests.exceptions.MissingSchema:
  25. print("Format URL invalide !")
  26. except requests.exceptions.ConnectionError:
  27. print("URL invalide !")
  28. except ValueError:
  29. print("Code invalide !")
  30. main()