注意!
記事を読んだ後、BDSMなどが好きな印象を受けるかもしれませんが、それはあなただけのようです。
ストアの問題
私はワルシャワの中心部にある通常の自転車店で働いています。私たちは固定とインターネットの両方で取引しています。1日あたりの平均購入自転車数〜年間で2台。同時に、売り上げのピークは夏になり、1日あたり最大17のオンライン注文と同じ数の店舗での注文が可能になり、冬には何も販売できなくなります。
2020年。COVIDのパンデミックに関連して、自転車の需要は驚異的な速度にまで成長し、まともなオフィスとして、私たちは拡大し始めました。
これにより、昨シーズンの終わりに、存在しない自転車のみの注文が、最も生産性の高い4か月間に平均して週に4回まで増加したという事実につながりました。そして、これは1か月あたりサイトで約16の不整合です(ストアでの障害はカウントされません)。
今年は別の大型倉庫の登場で状況が悪化し、存在しない自転車に加えて、存在しない自転車が追加され、時間通りに顧客に届けることができなくなった。
, - EXEL, , . , . 2 2-3 .
. , , , – , . .
, , - . . , . :
, .
:
Python API PrestaShop;
, -, . ;
Chrome . , Chrome.
middle-, . .
API PrestaShop
API PrestaShop Python , , PS 5% ( 1.6 ). — prestapyt, . , , .
, , API, PS. , , .
, , ! , .
- , .
, , .
:
reference ;
— ;
, , stock_availables. ;
associations .
, , > 0 — . – , .
XML stock_availables, .
.
, - , .
API
https://domain.com/api. , . id – , «products» . , .
API XML, :
<prestashop>
<api shopName="myshop">
<addresses xlink:href="https://domain.com/api/addresses" get="true" put="false" post="false" delete="false" head="false"></addresses>
</api>
</prestashop>
- . https://domain.com/api/products:
<prestashop>
<products>
<product id="22" xlink:href="https://domain.com/api/products/22"/>
<product id="24" xlink:href="https://domain.com/api/products/24"/>
<product id="265" xlink:href="https://domain.com/api/products/265"/>
<product id="294" xlink:href="https://domain.com/api/products/294"/>
<products />
<prestashop />
.
requests. , Requests — , .
API PS Basic ( ). . requests:
request_url = «https://domain.com/api»
get_combination_xml = requests.get(request_url, auth=(self.api_secret_key, ''))
200, , XML. .
XML
– xml.etree. , , ( ), , Python.
:
# 2
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import ElementTree
# xml.etree
def xml_data_extractor(data, tag):
# data – XML
# tag = products–
try:
xml_content = ET.fromstring(data.content) # ElementTree. . .
general_tag = xml_content[0] # –
tag = general_tag.find(tag) #
tag_inner_link = tag.get('{http://www.w3.org/1999/xlink}href') #
# href
#
product_meta = {'product_link': tag_inner_link}
return product_meta
except:
return None
: https://domain.com/api/products. , .
None except Try. , , , , .
PS
PS . , – SQL . XML , — , .
:
https://domain.com/api/combinations/?filter[reference]=reference
, reference — .
- -, : KRHE1Z26X14M200034.
, . ! Git:
«»
( , ). base64 , , , :
def __init__(self, api_secret_key, request_url=None, **kwargs):
try:
self.api_secret_key = str(api_secret_key) #!API key is necessary!
self.api_secret_key_64 = base64.b64encode((self.api_secret_key + ':').encode())
except:
raise TypeError('The secret_key must be a string!')
# Main path to working directory
self.base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
self.request_url = request_url
self.kwargs = kwargs.items()
#product meta to return
self.name = None
self.total_quantity = None
self.w_from = None
self.w_to = None
self.date = str(datetime.datetime.now().strftime("%d-%m-%Y, %H:%M"))
: _xml_data_extractor(), _wd() _logging(), . -.
— . 11. . , , .
middle-
c Python. , - . WSGI- , !
, , .
, . , Django, — middle-, .
, , - .
! https://palachintosh.com/xxx/xxx/
? ( ) , , . .
/?code=1122334455&token=IUFJ44KPQE342M3M109DNWI
( ):
success – , , , , - . .
, , , , . Django Django REST. Java Retrofit, .
– – . – - :
token = None
with open(‘token.txt’) as file_t:
token = file_t[0]
if token == str(request.GET.get(‘token’)):
//
return JsonResponse({‘Error’: ‘Invalid token’})
, , .
Chrome
, , ..
, . . XMLHttpRequest.
CORS. , Access-Control-Allow-Origin. , OPTIONS.
views.py def options(self, request). GET .
100 , .
- , . . :
, . «Kod roweru» , .
– PrestaRequest . , .
«sku» , ajax . , ajax . .
var interval;
function main_interval() {
clearInterval(interval);
interval = setInterval(function () {
href = window.location.href
if (href.indexOf('https://24.kross.pl/warranty/new') >= 0 ||
href.indexOf('id_product=') >= 0) {
if (href.indexOf('id_product=') >= 0) {
prestaCheck();
clearInterval(interval);
}
if (href.indexOf('https://24.kross.pl/warranty/new') >= 0) {
location.reload();
get_buttons();
}
}
if (href.indexOf('https://24.kross.pl/bike-overview/new') >= 0) {
clearInterval(interval);
check_all();
}
}, 1000);
}
:
// onclick or enter events
function getFormData() {
var getForm = document.forms[0];
if (getForm != null) {
if (getForm.hasChildNodes("sku") && getForm.sku != null){
var code = String(getForm.sku.value);
}
if (getForm.hasChildNodes("bike_model") && getForm.bike_model != null) {
edit_msg = document.querySelector(".message-container > span > h1");
edit_msg.innerText = "Rower " + String(getForm.bike_model.value) + " zostanie usunięty ze stanów!";
}
if (code != null && getForm.serial_number != null) {
sendRequest(code);
}
}
}
bike_model , , . :
var getBodyBlock = document.querySelector('body');
var alert_div = document.createElement('div');
alert_div.innerHTML = '<div class="alert-message"><div class="message-container">\
<span><h1></h1></span>\
<div class="inner-buttons">\
<button id="btnYes" class="ant-btn ant-btn-danger">Potwierdzam!</button>\
<button id="btnReserve" class="ant-btn ant-btn-danger">Zdjąć rezerwację</button>\
<button id="btnNo" class="ant-btn ant-btn-success">Nie teraz</button>\
</div></div></div>';
loader = document.createElement('div');
getBodyBlock.appendChild(alert_div);
: https://github.com/palachintosh/shop_extension
– Android-
, , . . , , , 50 ., .
. , . , .
( )
3 . , :
, .
, , , - , .
, . - . , - . Java .
Retrofit 2. , Python. , , , , , .
Main Activity 3 – onCreate, scanCode, enterCode , :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner fromSpinner = (Spinner) findViewById(R.id.fromSpinner);
Spinner toSpinner = (Spinner) findViewById(R.id.toSpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (
this, android.R.layout.simple_spinner_item, warehouses);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
fromSpinner.setAdapter(adapter);
toSpinner.setAdapter(adapter);
}
public void scanCode(View view) {
Intent intent = new Intent(MainActivity.this, Scan.class);
Spinner get_w_from = (Spinner) findViewById(R.id.fromSpinner);
Spinner get_w_to = (Spinner) findViewById(R.id.toSpinner);
EditText editText = (EditText) findViewById(R.id.prodctQuantity);
String quantity_tt = editText.getText().toString();
RequestData requestData = new RequestData(
get_w_from.getSelectedItem().toString(),
get_w_to.getSelectedItem().toString(),
quantity_tt);
intent.putExtra(RequestData.class.getSimpleName(), requestData);
startActivity(intent);
}
“Enter Code” . , . – .
Scan Code Activity co , Barcode Scanner Google.
Send Code – . , . Retrofit . , , – Java Android , .
github: https://github.com/palachintosh/product_control.git
:
– ;
– , , ;
- , .
:
– - , ;
– ;
– .
, 2- -.
, , 5:
.
( , PrestaShop).
"Enter code" .
"Scan code".
– "Send Code".
, , , .
, , , . - - .
: , , , .
, , , .
リポジトリを見たり、一般的にこれを読んだりした人は、建設的なコメントや批判に感謝するでしょう。