← back to Kravet Fabric Fix 2026 04 23

__pycache__/fix_dwkk_misclassified.cpython-314.pyc

66 lines

+
x
YjX��t�Rt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt	Rt
]PPRR4tR]
R2tRR.tR	tR
tRRR
RRR/t]P(!R]P*4t]P(!R]P*4tRRltRtRtRtRtRRltRt]R8Xd
]!4R#R#)a�
Fix DWKK products whose Shopify productType says wallcovering but the Kravet
master sheet classifies the item as MULTIPURPOSE / UPHOLSTERY / DRAPERY.

Per-row action (idempotent):
  1. Pull live product from Shopify (productType, tags, title, status)
  2. Target productType = 'Fabric'
  3. Target tags = existing - {Wallcovering} + {Fabric, <TitleUse>}
  4. Target title = strip stray "Wallpaper" / "Wallcovering" tokens
  5. Skip the write if nothing differs
  6. Mirror product_type='Fabric' back to kravet_catalog

Run:
  python3 fix_dwkk_misclassified.py --limit 5          # pilot
  python3 fix_dwkk_misclassified.py --limit 0          # full batch
  python3 fix_dwkk_misclassified.py --dry              # no writes
Nz)designer-laboratory-sandbox.myshopify.com�SHOPIFY_ADMIN_TOKEN�zhttps://z/admin/api/2024-10/graphql.json�sshzroot@45.61.58.125zY/Users/macstudio3/Projects/kravet-fabric-fix-2026-04-23/dwkk_misclassified_2026-04-23.csvzI/Users/macstudio3/Projects/kravet-fabric-fix-2026-04-23/fix_results.jsonl�MULTIPURPOSE�Multipurpose�
UPHOLSTERY�
Upholstery�DRAPERY�Draperyz$\s*\|\s*(wallpaper|wallcovering)s?\bz \b(wallpaper|wallcovering)s?\s*$c	��\P!RTRT;'g//4P4p\PP\VRRRR\/R7p\PPV^R7p\P!VP44pRV9d\VR,4hVR	,#)
�query�	variables�POSTzContent-Typezapplication/jsonzX-Shopify-Access-Token)�data�method�headers)�timeout�errorsr)�json�dumps�encode�urllib�request�Request�GQL�TOKEN�urlopen�loads�read�RuntimeError)rr
�body�req�resprs&&    �6kravet-fabric-fix-2026-04-23/fix_dwkk_misclassified.py�gqlr$!s����:�:�w��{�I�O�O��D�E�L�L�N�D�
�.�.�
 �
 ��4���*� �%�I�
 ��C��>�>�!�!�#�r�!�2�D��:�:�d�i�i�k�"�D��4���4��>�*�*���<��c�X�\P!\RVR2.,RRR7R#)zCPGPASSWORD=DW2024! psql -h 127.0.0.1 -U dw_admin -d dw_unified -c "�"T)�check�capture_outputN)�
subprocess�run�SSH)�sqls&r#�pg_execr..s,���N�N�3�
N�s�e�SU�V���
�$�(r%c�.�VR,p\VR,4pVR,pRp\V4pVPR4VPR4VPR4VP\V,4\V4p\PRV4p\PRV4P4PR4P4p/p	W%8wdW%3V	R&\V4V8wdW73V	R&WH8wdWH3V	R&WWW�3#)�productType�tags�title�Fabric�Wallcovering�wallcoveringr�|)�list�set�discard�add�	TITLE_USE�sorted�STRIP_TITLE�sub�STRIP_TITLE_TAIL�strip�rstrip)
�product�	sheet_use�cur_type�cur_tags�	cur_title�new_type�tag_set�new_tags�	new_title�changess
&&        r#�compute_targetrL4s����}�%�H��G�F�O�$�H��� �I��H��(�m�G��O�O�N�#��O�O�N�#��K�K����K�K�	�)�$�%��g��H�����I�.�I� �$�$�R��3�9�9�;�B�B�3�G�M�M�O�I��G���"*�!5��
��
�h��8�#�#�.������%�1�����y�1�1r%zYquery($id: ID!) {
  product(id: $id) { id title productType status tags vendor handle }
}z�mutation($input: ProductInput!) {
  productUpdate(input: $input) {
    product { id productType tags title }
    userErrors { field message }
  }
}c��VR,pVR,pVR,p\\RV/4pTR	,pTf	RTRTRR
/#\	Yt4wr�r�T'gRTRTRRRTR,/#T'dRTRTRR
RT/#RRTRTRT	RT
//p\\
T4p
T
R,R,pT'd
RTRTRRRTRT/#RTR2p\
T4RTRTRRRT/# \dpRTRTRRR\T4/uRp?#Rp?ii;i \d pRTRTRRR\T4RT/uRp?#Rp?ii;i \d pRTRTRRR\T4RT/uRp?#Rp?ii;i)�shopify_product_id�dw_skurC�id�pid�status�fetch_error�errorNrB�	not_found�noopr2�would_changerK�inputr0r1�update_error�
productUpdate�
userErrors�user_errorsrzPUPDATE kravet_catalog SET product_type='Fabric', updated_at=now() WHERE dw_sku='�'�shopify_ok_pg_fail�ok)r$�	PRODUCT_Q�	Exception�strrL�PRODUCT_UPDATEr.)�row�dryrQrOrCr�e�prGrIrJrKr
�upd�errsr-s&&              r#�fix_onerjZs���

�"�
#�C�
��]�F��K� �I�X��9�t�S�k�*��	
�Y��A��y��&�%��h��D�D�-;�A�-I�*�H�	���&�%��h����7��T�T�
��&�%��h��	�SZ�[�[���c��x�����	��I�m��.�)�,������-�D���&�%��h�
�x�QU�W`�bi�j�j�\�]c�\d�de�
f�C�s����
�f�e�S�(�D�)�W�M�M��C�X��&�%��h�
�w�PS�TU�PV�W�W��X��*�m��&�%��h���QT�UV�QW�Yb�dk�l�l��m���s��&�%��h�8L�g�WZ�[\�W]�_h�jq�r�r��s�sY�C�
D�D2�D�%C=�7D�=D�D/�D*�$D/�*D/�2E�=E�E�Ec��\P!4pVPR\^R7VPRRR7VPR\^R7VP	4p\\4;_uu_4p\\P!V44pRRR4VP'dXVPRpVP'dXRVPp\R\X4RVP'dR	MR
24/p\\R4;_uu_4p\!V^4F�wrg\#WqPR7pVP%VR
,^4^,WHR
,&VP'\(P*!V4R,4VP-4V^,^8XgV^
8:d/\RVR\V4RVR,RVR
,24\.P0!R4K�	RRR4\RV4R# +'giEL�;i +'giL2;i)z--limit)�type�defaultz--dry�
store_true)�actionz--offsetNzProcessing z	 productsz (DRY)r�a)rerR�
z  [�/z] rOz: g333333�?zDone:)�argparse�ArgumentParser�add_argument�int�
parse_args�open�CSV_PATHr7�csv�
DictReader�offset�limit�print�lenre�RESULTS�	enumeraterj�get�writerr�flush�time�sleep)	�ap�args�f�rows�counters�out�ird�results	         r#�mainr��s���	�	 �	 �	"�B��O�O�I�C��O�3��O�O�G�L�O�1��O�O�J�S�!�O�4�
�=�=�?�D�	
�h���1��C�N�N�1�%�&��
��{�{�{��D�K�K�L�!���z�z�z��K�T�Z�Z� ��	�K��D�	�{�)�����H�b�+I�
J�K��H�	
�g�s�	�	�s���a�(�F�A��S�h�h�/�F�)1���f�X�6F��)J�Q�)N�H�H�%�&��I�I�d�j�j��(�4�/�0��I�I�K��2�v��{�a�2�g���A�3�a��D�	�{�"�S��]�O�2�f�X�>N�=O�P�Q��J�J�t��)�
�
�'�8��%
����
�	�s� H2�2C*I�2I	�I	�__main__)N)F) �__doc__rsrzr�rer*�sysr��urllib.requestr�SHOP�os�environr�rrr,ryr�r;�compile�Ir=r?r$r.rLr`rcrjr��__name__�r%r#�<module>r�s����"F�E�E�E�3��
�
�
���,�R�0��
�4�&�7�8��	�#�$��f��V��
�^�\�<��T]�^�	��j�j�@�"�$�$�G���:�:�A�2�4�4�H��
�(�2�4
�	���(N�V�8�z���F�r%