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