-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
34 lines (25 loc) · 1.18 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import requests
import datetime
from shopwareconnection import ShopwareConnection
myPid = os.getpid()
requestsSession = requests.Session()
def printLog(logtext, noNewline=False):
if noNewline:
print(datetime.datetime.now().astimezone().isoformat() + " (" + str(myPid) + ") => " + logtext, flush=True, end="")
else:
print(datetime.datetime.now().astimezone().isoformat() + " (" + str(myPid) + ") => " + logtext, flush=True)
def getShopwareArticleId(url, shConn: ShopwareConnection, articleNo):
shopwareID = ""
payload = {"filter": [{"type": "equals", "field": "productNumber", "value": articleNo}], "includes": {}}
payload["includes"]["product"] = ["id"]
r = shConn.makeAuthenticatedRequest("/api/search/product", shConn.requestsSession.post, payload)
if 'errors' in r:
raise ValueError(r)
if 'data' in r and len(r['data']) == 1:
shopwareID = r['data'][0]['id']
return shopwareID
def updateArticleStock(url, shConn, productID, stock):
payload = {"stock": int(stock)}
r = shConn.makeAuthenticatedRequest(f"/api/product/{productID}", shConn.requestsSession.patch, payload, returnType="text")
return r.status_code