← back to Kravet Sheet Sync 2026 04 20

__pycache__/test_push_2_items.cpython-314.pyc

226 lines

+
x
Yj�=��N�Rt^RIt^RIt^RIt^RIt^RIt^RIt^RItRt	]PPRR4tRt
R]	R]
R2tR	R
.tR%RRlltR
RltRRltRRltRRltRRltRRltRRltRRltRtRtRtR tR!R"ltR#t]R$8Xd
]!4R#R#)&u�
Test push 2 Kravet wallcoverings to Shopify as drafts.

Follows Designer-Wallcoverings CLAUDE.md rules:
- PG first (already done via kravet_sheet_fields)
- Register in dw_sku_registry
- Draft status (no image yet)
- Sample variant at $4.25 with DW-SKU-Sample
- manufacturer_sku metafields (custom + dwc)
- Never use word "wallpaper" — always "wallcovering"

Run:  python3 test_push_2_items.py
Nz)designer-laboratory-sandbox.myshopify.com�SHOPIFY_ADMIN_TOKEN�z2024-10zhttps://z/admin/api/z
/graphql.jsonzDWKK-141031zDWKK-141042c�J�V^8�dQhR\R\R,R\/#)��query�	variablesN�return)�str�dict)�formats"�1kravet-sheet-sync-2026-04-20/test_push_2_items.py�__annotate__r
 s%����s��t�d�{��d��c	��\P!RTRT;'g//4PR4p\PP\VRRRR\/R7p\PPV^R7;_uu_4p\P!VP44pR	R	R	4R
X9d,\R\P!VR
,^R724hVR
,# +'giLK;i)rrzutf-8�POSTzContent-Typezapplication/jsonzX-Shopify-Access-Token)�data�method�headers)�timeoutN�errorszGraphQL errors: ��indentr)�json�dumps�encode�urllib�request�Request�GQL_URL�TOKEN�urlopen�loads�read�RuntimeError)rr�body�req�rrs&&    r�gqlr' s����:�:�w��{�I�O�O��D�E�L�L�W�U�D�
�.�.�
 �
 ��
���.�$�e�
�	!��C�
���	�	��R�	�	0�	0�A��z�z�!�&�&�(�#��
1��4���-�d�j�j��h��PQ�.R�-S�T�U�U���<��	
1�	0�s�%C4�4D	c�\�V^8�dQhR\R\\\,,/#)rrr)r	�list)rs"rr
r
2s&��
N�
N�c�
N�d�4��9�o�
Nrc���\P!RRRVR2.RRRR7pVPP4P	R4Uu.uFq"'gKVP	R4NK	up#uupi)	zBRun psql on Kamatera, return rows as list of list-of-cell strings.�sshzroot@45.61.58.125zNPGPASSWORD=DW2024! psql -h 127.0.0.1 -U dw_admin -d dw_unified -At -F "|" -c "�"T)�capture_output�text�check�
�|)�
subprocess�run�stdout�strip�split)rr&�lines&  r�pgr82su��������#�W�A�
'�	
��
��
	�A�)*�����(8�(>�(>�t�(D�M�(D���O�D�J�J�s�O�(D�M�M��Ms�
	A3�A3c�0�V^8�dQhR\R\/#�r�sr�r	)rs"rr
r
Bs��
�
�#�
�#�
rc��V'gV#VP4P4pVP4p0Rmp.p\V4FcwrEV^8�dWR9dVP	V4K%TP	V'd&V^,P4VR,,MT4Ke	RP
V4#)z/Simple title case preserving common separators.:�NN� >
�a�an�at�in�of�on�or�to�and�but�for�the�with)r5�lowerr6�	enumerate�append�upper�join)r;�words�small�out�i�ws&     r�
title_caserWBs������	���	����A�
�G�G�I�E�_�E�
�C��%� ����q�5�Q�Z��J�J�q�M��J�J�q�q��t�z�z�|�a��e�+�a�8�	!�
�8�8�C�=�rc�0�V^8�dQhR\R\/#r:r<)rs"rr
r
Rs��
�
�s�
�s�
rc���V'gV#^RIpVPRRWPR7pVPRRWPR7pVPRRWPR7pV#)z6Per CLAUDE.md: banned word, replace with Wallcovering.Nz\bWallpapers\b�
Wallcoverings)�flagsz\bWalls Wallpaper\bz
\bWallpaper\b�Wallcovering)�re�sub�I)r;r]s& r�clean_wallpaperr`Rs]�����
�
��� �/�1�D�D��A�A�
���%������F�A�
������$�$��?�A��Hrc�\�V^8�dQhR\\,R\\,/#)r�dw_skusr)r)r	r
)rs"rr
r
^s&��B.�B.��c��B.�t�D�z�B.rc	�R�RPRV44pRVR2p.RNRNRNRNR	NR
NRNRNR
NRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NR(NR)NR*NR+NR,NR-NR.Np\V4pVUu.uFp\\W544NK	up#uupi)/zWFetch each DWKK candidate with all needed fields joined from sheet_fields + new bucket.�,c3�."�TFpRVR2x�K
	R#5i)�'N�)�.0r;s& r�	<genexpr>�fetch_items.<locals>.<genexpr>`s���2�'�Q�!�A�3�a��'�s�a
    SELECT
      n.new_dw_sku,
      n.mfr_sku,
      COALESCE(NULLIF(n.pattern_name,''), n.mfr_sku)            AS pattern_name,
      n.color_name,
      n.brand,
      n.collection,
      n.country_of_origin,
      n.width,
      n.unit_of_measure,
      n.content,
      n.type1,
      n.type2,
      n.style1,
      n.style2,
      n.display_status,
      n.inventory_available,
      n.wholesale::text,
      n.map::text,
      n.tariff_pct::text,
      n.cost::text,
      s.vert_repeat,
      s.horz_repeat,
      s.repeat_uom,
      s.width_uom,
      s.weight,
      s.weight_uom,
      s.prop_65,
      s.prop_65_chemical,
      s.prop_65_effect,
      s.ca_tb117,
      s.ab_1817,
      s.ufac,
      s.direction,
      s.lead_time_days,
      s.minimum_order_qty,
      s.order_increment_qty,
      s.horizontal_half_drop,
      s.barcode,
      s.memo_sample_available,
      s.ship_from,
      s.clean_code,
      s.durability
    FROM kravet_diff_new_2026_04_20 n
    JOIN kravet_sheet_fields s ON s.mfr_sku_norm = regexp_replace(
                                                     regexp_replace(upper(btrim(n.mfr_sku)),'-','.','g'),
                                                     '\.0\$',''
                                                   )
    WHERE n.new_dw_sku IN (z )
    ORDER BY n.new_dw_sku
    �dw_sku�mfr_sku�pattern_name�
color_name�brand�
collection�country_of_origin�width�unit_of_measure�content�type1�type2�style1�style2�display_status�inventory_available�	wholesale�map�
tariff_pct�cost�vert_repeat�horz_repeat�
repeat_uom�	width_uom�weight�
weight_uom�prop_65�prop_65_chemical�prop_65_effect�ca_tb117�ab_1817�ufac�	direction�lead_time_days�minimum_order_qty�order_increment_qty�horizontal_half_drop�barcode�memo_sample_available�	ship_from�
clean_code�
durability)rQr8r
�zip)rb�skus_csv�q�cols�rowsr&s&     r�fetch_itemsr�^s����x�x�2�'�2�2�H�1
�b%�:�&�c3	�A�h	��	��	�)�	�*6�	�7>�	�?K�	�L_�	��	�!�	�"+�	�,3�	�4;�	�<D�	�EM�	�	�	�/�	�0;�	�<A�	�BN�	�OU�	�	�		�$�		�%1�		�2=�		�>F�		�GS�		�
	�	�
%�	�
&6�	�
7A�	�
BK�	�
LR�	�	�
	�%�
	�&9�
	�:O�
	�	�	� )�	�*A�	�BM�	�	�	�"�	�D��a�5�D�(,�-��1�D��T����-�-��-s�B$c�@�V^8�dQhR\R\R\RR/#)rrkrlrorNr<)rs"rr
r
�s(��	
�	
��	
�s�	
�3�	
�4�	
rc��T;'gRPRR4pVPRR4pRVRVRVR2p\V4R#)	z-INSERT into dw_sku_registry (skip if exists).�KRAVETrf�''zh
    INSERT INTO dw_sku_registry (dw_sku, vendor_prefix, vendor_name, mfr_sku, created_at)
    VALUES ('z', 'DWKK', '�', 'z2', now())
    ON CONFLICT (dw_sku) DO NOTHING
    N)�replacer8)rkrlro�	esc_brand�esc_mfrr�s&&&   r�register_skur��sW���"�"�(�+�+�C��6�I��o�o�c�4�(�G�
��X�\�)��D��	�:�	�A�
�q�Erc�0�V^8�dQhR\R\/#�r�itemr)r
r	)rs"rr
r
�s��"�"�d�"�s�"rc���\VR,;'gR4p\VR,;'gR4p\VR,;'gR4pVRVRV2P4p\V4#)rmrrnro�Kravetr?� | )rWr5r`)r��pattern�colorro�titles&    r�build_titler��sp����n�-�3�3��4�G���l�+�3�3��4�E���g��9�9��:�E��	��5�'��U�G�,�2�2�4�E��5�!�!rc�F�V^8�dQhR\R\\,/#r�)r
r)r	)rs"rr
r
�s��
"�
"�T�
"�d�3�i�
"rc��R\VR,;'gR4RR.pVR,'d"VP\VR,44VR,'d"VP\VR,44VR,'d%VPR\VR,424VUu.uFq"'gKVNK	up#uupi)r�ror\zTest-Import-2026-04-20rurzrqzOrigin: )rWrO)r��tags�ts&  r�
build_tagsr��s�����4��=�,�,�H�-�� �	�D��G�}�}����J�t�G�}�-�.��!�"�"����J�t�$9�:�;�<��� � ����h�z�$�/B�*C�D�E�F�G��!�t�!�q�A�A�t�!�!��!s�8	C�Cc�F�V^8�dQhR\R\\,/#r�)r
r))rs"rr
r
�s��/�/�4�/�D��J�/rc�a�.oR:RV3RlllpV!RRVR,4V!RRVR,4T!RR\VR,;'gR	44T!RR
\VR,;'gR	44T!RR\VR,;'gR	44T!RR\VR,;'gR	44T!RR\VR,;'gR	44T!RR
\VR,;'gR	44T!RR\VR,;'gR	44T!RR\VR,;'gR	44V!RRVR,4V!RRVR,4T!RR\VR,;'gR	44V!RRVR,4T!RR\VR,;'gR	44V!RRVR,4V!RRVR,4V!RRVR,4V!RR VR!,4V!RR"VR#,4V!RR$VR%,4V!RR&VR',4V!RR(VR),4V!RR*VR+,4V!RR,VR-,4V!RR.VR/,4V!RR0VR1,4V!RR2VR3,4V!RR4VR5,4V!RR6VR7,4V!RR8VR9,4S#);z?Build metafield definitions per CLAUDE.md global.* conventions.c�0�V^8�dQhR\R\/#)r�ns�keyr<)rs"rr
�&build_metafields.<locals>.__annotate__�s��M�M��M�#�Mrc
�<�VeVR8XgVR8XdR#\V4P4pV'gR#SPRVRVRVRV/4R#)Nr�NULL�	namespacer��value�type)r	r5rO)r�r��val�mtype�v�mfss&&&& �r�add�build_metafields.<locals>.add�sJ����;�#��)�s�f�}����H�N�N������
�
�K��U�C��!�V�U�K�Lr�custom�manufacturer_skurl�dwcr�rnr�real_color_namermro�real_vendor�global�Brand�
CollectionrprrrszCountry-of-Originrq�Contentrt�Type1ruzVert-RptrzHorz-Rptr��	Directionr�zProp-65r�zCA-TB117r��UFACr�z
Clean-Coder��
Durabilityr��Weightr�zLead-Time-in-Daysr�z	Ship-Fromr�zMemo-Sample-Availabler�zDisplay-StatusryzInventory-Availablerzz
WHLS-Pricer{�Minimumr�)�single_line_text_field)rW)r�r�r�s& @r�build_metafieldsr��s�����C�M�M���$�d�9�o�6���$�d�9�o�6���'�j��l�1C�1I�1I�r�&J�K���#�j��l�1C�1I�1I�r�&J�K���'�j��l�1C�1I�1I�r�&J�K���.�j��n�1E�1K�1K��&L�M���'�j��g��1D�1D�"�&E�F���-�j��g��1D�1D�"�&E�F���'�:�d�7�m�6I�6I�r�+J�K���,�:�d�<�6H�6N�6N�B�+O�P���'�4��=�9���#�4�0A�+B�C���%�:�d�;N�6O�6U�6U�SU�+V�W���)�4�	�?�;���'�:�d�7�m�6I�6I�r�+J�K���*�4�
�+>�?���*�4�
�+>�?���+�4��+<�=���)�4�	�?�;���*�4�
�+;�<���&�4��<�8���,�4��+=�>���,�4��+=�>���(�4��>�:���%�4�0@�+A�B���+�4��+<�=���)�4�0G�+H�I���"�4�0@�+A�B���'�4�0E�+F�G���,�4��+<�=���)�4�0C�+D�E��Jra
mutation productCreate($product: ProductCreateInput!) {
  productCreate(product: $product) {
    product {
      id
      handle
      title
      status
      onlineStoreUrl
      variants(first: 5) { nodes { id title sku price } }
    }
    userErrors { field message }
  }
}
a2
mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
  productVariantsBulkUpdate(productId: $productId, variants: $variants) {
    product { id }
    productVariants { id sku price inventoryItem { id unitCost { amount } } }
    userErrors { field message }
  }
}
a	
mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
  productVariantsBulkCreate(productId: $productId, variants: $variants) {
    product { id }
    productVariants { id sku price }
    userErrors { field message }
  }
}
z�
mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields { id namespace key }
    userErrors { field message }
  }
}
c�0�V^8�dQhR\R\/#r�)r
)rs"rr
r
(s��|�|�4�|�D�|rc�	�VR,p\V4p\V4p\RVRVR,R24\RV24\RV24\YR,VR,;'gR4\R	4R
TR\	VR,;'gR4R
RRRRTRR\	VR,;'gR4R\	VR,;'gR4R\	VR,;'gR4RVR,RVR,;'gRR2/p\\R V/4pVR!,R",pV'd\R#V24hVR!,R ,pVR$,pVR%,R&,^,R$,p	\R'VR(VR),R*24VR+,R^9d\VR+,4MR.p
VR/,R^9d\VR/,4MR,pR$V	R0V
R1
R2R3VR4R5//pVeVR1
VR2,R/&VPR64'd$\VR6,4P4VR6&\\R7VR%V./4p
V
R8,R",pV'd\R9V24h\R:VR;V
R1
R<VR1
R*24R0R=R2R3VR>2R4R?/R@RARBRCRD/./p\\R7VR%V./4pVRE,R",pV'd\RFV24M\RGVRH24\V4pVUu.uF	pRIV/VCNK	pp\\ RJV/4pVRK,R",pV'd\RLV24\RM\#VRK,RJ,4RN\#V424VP%RO4R_,pVR,;'gRP'RPRQ4pVR,;'gRP'RPRQ4pVR,;'gRP'RPRQ4pVR,P'RPRQ4pRRTRSTRSTRSTRTTRSTRUVR+,;'gR-RVVR/,;'gR-RVVRW,;'gR-RX2p\)V4\RY4RVRVR,RZVR[VR)VR),R
VR
,R\R]V2/# \d	R.p
R,pEL�i;iuupi)`rkz
=== r�rlz ===z	  Title: z	  Tags:  ror�z  registry: DWKK-registeredr��vendorr��productTyper\�status�DRAFTr��descriptionHtmlz<p>rmrz in rnz. rtz	. Width: rrr?r��INz.</p>�product�
productCreate�
userErrorszproductCreate errors: �id�variants�nodesz  created: z (�handle�)r|Nr�gr~�pricez.2f�
inventoryItem�sku�trackedTr��	productId�productVariantsBulkUpdatezvariantUpdate errors: z  main variant: z @ $z (cost $z4.25z-SampleF�optionValues�
optionName�Title�name�Sample�productVariantsBulkCreatez  sample variant skipped: z  sample variant: z-Sample @ $4.25�ownerId�
metafields�
metafieldsSetz  metafields userErrors: z  metafields set: z / �/rfr�z�
    INSERT INTO kravet_catalog (
      mfr_sku, pattern_name, color_name, brand, dw_sku, shopify_product_id,
      on_shopify, price_retail, cost_price, tariff_pct, status, imported_at
    ) VALUES (
      'r�z
',
      'z',
      true,
      z, r}z�,
      'draft', now()
    )
    ON CONFLICT (mfr_sku) DO UPDATE SET
      dw_sku = EXCLUDED.dw_sku,
      shopify_product_id = EXCLUDED.shopify_product_id,
      on_shopify = true,
      status = 'draft',
      imported_at = now()
    z  kravet_catalog: upserted�
shopify_id�shopify_numeric_id�	admin_urlzEhttps://admin.shopify.com/store/designer-laboratory-sandbox/products/)Nrr������)r�r��printr�rWr'�PRODUCT_CREATEr#�float�
ValueError�getr	r5�VARIANT_UPDATE�VARIANT_CREATEr��METAFIELDS_SET�lenr6r�r8)r�rkr�r��
product_inputr�errs�prod�pid�default_variant_id�	map_price�
cost_price�main_variant_input�vu�sample_input�vcr��m�payload�mr�shopify_id_numeric�esc_pattern�	esc_colorr�r�r�s&                         r�push_oner(sR��
�(�^�F����E��t��D�	�F�6�(�#�d�9�o�.�d�
3�4�	�I�e�W�
��	�I�d�V�
����i��$�w�-�*C�*C�8�D�	�'�)�	�u��z�$�w�-�";�";�8�<��~��w��t���*�T�.�1�7�7�R�8�9���$�|�,�2�2��3�4�B��$�y�/�/�/�R�0�1�2��7�m�_�A�d�;�&7�&?�&?�4�%@��
G��M��~�	�=�9�:�D��� ��.�D���3�D�6�:�;�;��� ��+�D�
�t�*�C��j�)�'�2�1�5�d�;��	�K��u�B�t�H�~�.�a�
0�1��*.�u�+�=O�*O�E�$�u�+�&�UX�	�,0��L�@R�,R�U�4��<�(�X\�
�	
�#��I�c�?������
�����9C�C�8H��?�+�F�3��x�x�	���(+�D��O�(<�(B�(B�(D��9�%�	�^�k�3�
�=O�<P�Q�	R�B�
�)�*�<�8�D���3�D�6�:�;�;�	��V�H�D��3��x�
�3�?O�q�
Q�R�	����&���)��u�
�	�,����B�C�
�L�

�^�k�3�
�\�N�K�	L�B�
�)�*�<�8�D��	�*�4�&�1�2�
�"�6�(�/�:�;��4�
 �C�.1�2�c��	�3�$�!�$�c�G�2�	�^�l�G�4�	5�B�
�o��|�,�D��
�)�$��0�1�	��s�2�o�#6�|�#D�E�F�c�#�c�(��
T�U����3���+����'�-�-�2�6�6�s�D�A�K���%�-�-�2�6�6�s�D�A�I���=�-�-�2�6�6�s�D�A�I��y�/�)�)�#�t�4�G�
�
	�y��[�M��i�[��Y�K�@��x�t�C�5���E�{���f��R��V�� 6� 6��7�r�$�|�:L�:V�:V�PV�9W�	X�	�A�$�q�E�	�&�(�	�&��4�	�?��c��0��$�x�.���g���\�]o�\p�q����[���	��
���V3s�+AR,�	S�,R?�>R?c� �\\4p\V4\\48wdQ\R\\4R\V4R24VF"p\RVR,RVR,24K$	.pVF p\	V4pVPV4K"	\R
4VFLp\RVR,RVR,24\R
VR,24\RVR,24KN	\RR4;_uu_4p\P!W'^R7R	R	R	4\R4R	# \d,p\RTPR4RT24R	p?K�R	p?ii;i +'giLV;i)zWARNING: requested z but found z in DBz  - rkr?rlzFAILED: z: Nz
=== SUMMARY ===z  r�z    title:  r�z    handle: r�ztest_push_results.jsonrVrz 
Written: test_push_results.json)r��	TEST_SKUSrr�rrO�	Exceptionr��openr�dump)�itemsrU�resultsr��res�er&�fs        r�mainr�sQ���	�"�E�
�5�z�S��^�#�
�#�C�	�N�#3�;�s�5�z�l�&�Q�R��A��D��8��
�Q�q��|�n�5�6���G���	8��4�.�C��N�N�3���
�
��
��
��1�X�;�-�r�!�K�.�!1�2�3�
��Q�w�Z�L�)�*�
��Q�x�[�M�*�+��

�&��	,�	,���	�	�'�Q�'�
-�	�-�/���	8��H�T�X�X�h�/�0��1�#�6�7�7��	8��
-�	,�s$�E�E=�E:� E5�5E:�=F
	�__main__)N) �__doc__r�os�sys�timer2�urllib.requestr�urllib.error�SHOP�environr�r�APIrrr'r8rWr`r�r�r�r�r�r�r�r�rrr�__name__rgrr�<module>r*s�����	�
�����	4��	�����-�b�	1��	���T�F�+�c�U�-�
8��
�M�*�	��$
N� 
� 
�B.�J	
�"�
"� /�f�� ������|�@0�2�z���F�r