← back to Mdc Onboard

__pycache__/import-drafts.cpython-314.pyc

121 lines

+
�jjK+����Rt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RI	t	Rt
R]
R2t]!R]
!R444t]	PP!]	PP#]	PP%]44R4t]	P*!]RR	7R
]P,9tR]P,9d:]!]P,]P,P3R4^,,4MRt]P6!R]P84t]P6!R
]P84tRtRt Rt!Rt"Rt#.ROt$Rt%Rt&]'R8Xd
]&!4R#R#)u�
MDC → Phillipe Romano (Type II contract vinyl) DRAFT onboard.

Creates Shopify DRAFT products for dw_unified.mdc_catalog rows not yet on Shopify,
following the proven vahallan-onboard (quote-only) + knoll-onboard (private-label)
pattern. PRIVATE LABEL — "MDC" / mdcwall.com / the real book & designer names are
NEVER customer-facing; the only real datum pushed to Shopify is the opaque mfr SKU
code, stored in hidden custom+dwc manufacturer_sku metafields (per task spec).

Per product (task contract):
  * title       = dw_catalog.dw_title  (already title-cased "... | Phillipe Romano",
                  guaranteed to contain no "Wallpaper"/"Unknown" — re-guarded here)
  * status      = draft   (activation DRAFT->ACTIVE is a SEPARATE Steve-gated step
                  through settlement + the 5-field gate + publish-ex-Google)
  * Sample var  = {DW_SKU}-Sample @ $4.25, inventory_management=null (no inventory)
  * quote-only  => tags 'quotes' + 'contact-for-price'  (no sellable/priced variant)
  * metafields  = custom.manufacturer_sku, dwc.manufacturer_sku (both = mfr_sku),
                  global.Brand=Phillipe Romano, global.width (when known),
                  global.unit_of_measure, custom.color/real_color_name
  * >=1 image   = image_url  (every row has one; re-guarded)

BUDGET_CAT=backlog: this is a STANDALONE importer. It does NOT touch the shared
upload/variant-create budget (budget.cjs) and does NOT auto-activate — the drafts
land as backlog, to be drip-activated later under the activation-lane cap. Nothing
here consumes the "upload" pool.

PostgreSQL-first write-back: the moment a product is created, its shopify_product_id
+ on_shopify=true is written back to mdc_catalog (the local dw_unified mirror,
host=/tmp) BEFORE moving on — so the run is fully resumable and never double-creates.

Cost: $0 (local) — plain urllib POSTs to the Shopify Admin API (unmetered) + local
PG. No browser, no Gemini, no Claude API.

Usage:
  python3 import-drafts.py                 # DRY-RUN: print first 3 payloads, create nothing
  python3 import-drafts.py --limit 3 --commit   # create 3 real drafts (test batch)
  python3 import-drafts.py --commit             # create ALL remaining (~45 min)
Nz)designer-laboratory-sandbox.myshopify.comzhttps://z/admin/api/2024-10c#�"�TFEpVPR4'gKVPR^4^,P4x�KG	R#5i)zSHOPIFY_ADMIN_TOKEN=�=N)�
startswith�split�strip)�.0�ls& �import-drafts.py�	<genexpr>r
,sA���
6�M�����3�4�(�Q�W�W�S�!�_�Q�
�
%�
%�
'�
'�M�s
�A�/Az//Users/macstudio3/Projects/secrets-manager/.env�outT)�exist_okz--commitz--limitzo\b(mdc|mdcwall|vycon|genon|bolta|lentex|nvolve|candice\s+olson|thom\s+filicia|jonathan\s+mark|taniya\s+nayak)\bz\b(wallpaper|unknown)\bc���\P!RRRRRRRRRV.
R	R	R
7pVP'd/\P!RVP
R,,4VP#)
�psqlz-hz/tmpz-d�
dw_unifiedz-vzON_ERROR_STOP=1z-tAz-cT)�capture_output�textzpsql error: :Ni�N)�
subprocess�run�
returncode�sys�exit�stderr�stdout)�sql�rs& r	rr>s\�������f�d�L�$�HY��t�S�*�:>�T�	K�A��|�|�|�����!�(�(�4�.�0�1��8�8�O�c
�r�\PP\V,V\P
!V4P
4R\RR/R7p\^4FGp\P!\PPV^-R7P44u#	\)R	4h \PPd^pTPR8XdG\P !\#TP$P'RR44^,4Rp?K�hRp?ii;i)
zX-Shopify-Access-TokenzContent-Typezapplication/json)�method�data�headers)�timeouti�zRetry-After�3Nz429 retries exhausted)�urllib�request�Request�API�json�dumps�encode�TOKEN�range�loads�urlopen�read�error�	HTTPError�code�time�sleep�floatr�get�RuntimeError)r�path�body�req�_�es&&&   r	�apir;Fs���
�.�.�
 �
 ��t��F��z�z�$��&�&�(�+�U�N�DV�W�!�Y�C��1�X��	��:�:�f�n�n�4�4�S�"�4�E�J�J�L�M�M���.�
/�/��	�|�|�%�%�	��v�v��}��
�
�5������}�c�!B�C�a�G�H�(���	�s �(AB:�:D6�AD1�0D1�1D6c�f�V'd)\V4P4'd
RVRVR2#R#)z<tr><td><strong>z</strong></td><td>z
</td></tr>�)�strr)�label�vals&&r	�spec_rowrATs6��JM�RU�VY�RZ�R`�R`�Rb�Rb�
�e�W�$6�s�e�:�F�j�hj�jrc�r�VR,;'gRpVR,;'g
VR,pRVRVR2pV#)�private_label_collectionr=�pattern_name�dw_skuz<p>z from the Phillipe Romano z� collection &mdash; a high-performance Type II commercial wallcovering. Priced per single roll; request a memo sample to see the material in hand, or contact us for a quote.</p>�)r�coll�pat�intros&   r	�
build_bodyrJXsN���
'�(�.�.�B�D��^��+�+��(��C��3�%�1�$��8a�b�E��Lrc���VR,;'gRP4pVR,;'gRpVR,;'gRpVR,;'gRpVR,p\RRRR	VVR
RR3	Uu0uF'pV'gK
VP4'gK%VkK)	up4pR
RRRRRRVR,/R
RRRRRRVR,/R
RRRRRRR/R
RRRRRRR/.pV'd3VPR
RRRRRRV/4VPR
RRRRRRV/4VR,'dLVR,P4'd/VPR
RRRRRRVR,P4/4V'dVPR
RRRRRRV/4.R<Op	V	Frwr�r�VPV
4pV'gK!\	V4P4'gKBVPR
VRVRV
R\	V4P4/4Kt	RRVR\V4R RR!RR"R#R$R%P
V4R&R'R(R)R*./.R+R,R*R-R.R/VR02R1R2R3R4R5R4R6^/.R7R8VR9,R:V/.R;V/
/#uupi)=�dw_titler=rCrD�
color_namerEzPhillipe Romano�Wallcovering�
CommercialzType II�quoteszcontact-for-price�display_variant�	namespace�custom�key�manufacturer_sku�type�single_line_text_field�value�mfr_sku�dwc�global�Brand�unit_of_measurezPriced Per Single Roll�color�real_color_name�width�product�title�	body_html�vendor�product_type�status�draft�tagsz, �options�name�Size�values�Sample�variants�option1�pricez4.25�skuz-Sample�inventory_managementN�requires_shippingT�taxable�grams�images�src�	image_url�alt�
metafields))�materialrSr{�multi_line_text_field)�backingrSr}rW)�weightrS�product_weightrW)�fire_ratingrSr�rW)�
pattern_matchrS�
match_typerW)�certificationsrSr�rW)r�sorted�appendr4r>rJ�join)rrbrGrHr^�dw�trh�mfs�_specs�_col�_ns�_key�_typ�_vs&              r	�
build_payloadr�ds���
�z�]�
 �
 �b�'�'�)�E�
�(�)�/�/�R�D�
�n��#�#��C�
�l�O�!�!�r�E�
�h�K�B���>�<��D��X�*�,=�����
���w�w�y��1����D�

�h��'9�6�C[�]d�fg�hq�fr�s�	�e��'9�6�C[�]d�fg�hq�fr�s�	�h��w�6�C[�]d�fw�x�	�h��'8�6�C[�]d�f~��	�C�
��
�
�K��5�'�V�Me�gn�pu�v�w��
�
�K��5�2C�V�Me�gn�pu�v�w���z�z�a��j�&�&�(�(��
�
�K��5�'�6�C[�]d�fg�ho�fp�fv�fv�fx�y�z�
��
�
�K��5�.�&�Jb�dk�mp�q�r��F�"(���4�
�U�U�4�[��
�2�#�b�'�-�-�/�/��J�J��S�%��v�t�W�c�RT�g�m�m�o�^�_�"(�
����Z��]��#����'���	�	�$���V�V�X��z�:�;��i��7�F�E�b�T��>�,�d�4G����w��3�4�	�E�1�[�>�5�%�8�9��c�
�
�
��As�6
I#�I#�I#c��RRPR\44,R,p\P!\	V44#)z+SELECT coalesce(json_agg(json_build_object(�,c3�2"�TF
pRVRV2x�K	R#5i)�'z',NrF)r�cs& r	r
�fetch_rows.<locals>.<genexpr>�s���/�$�Q�a��s�"�Q�C�L�$�s�z]) ORDER BY dw_sku),'[]') FROM mdc_catalog WHERE NOT on_shopify AND shopify_product_id IS NULL)r��COLSr&r+r)�sels r	�
fetch_rowsr��s?��8��8�8�/�$�/�/�0�A�A�C��:�:�d�3�i� � rc���\4p\R\V4R\'dRMRR\R28d\MR2RR7^;p;r#VR\p\\PP\R	4R
4;_uu_4p\\PP\R4R
4;_uu_4pVEF1pVR,;'gR
P4pVRVR,RVR,RVR,2p	Rp
V'gRp
Me\PV4'dRp
MGVR,;'gR
P4'gRp
M\PV	4'dRp
V
'd`V^,
pVP\P !RVR,RV
RV/4R,4\RVR,RV
2RR7EK \#V4p\'g<V^8d)\\P !V^R7R,4V^,
pEKr\%RR V4pVR!,R",p
\'R#V
R$VR",24VP\P !RVR,R%V
RV/4R,4V^,
pV^,^8Xd$\R&VR'\V4R(VR)VR*2	RR7\(P*!R+4EK4	RRR4RRR4\R.\'dRMRR/VR0VR1V2RR7R# \,d�pT^,
p\/T\0P2P44'dTP74R,,M
\9T4p\R-TR,RT2RR7\(P*!^4Rp?EKRp?ii;i +'giL�;i +'giL�;i)3z!candidates (not yet on Shopify): z
  |  mode=�COMMITzDRY-RUNz  |  limit=�allT)�flushNzleak-skipped.jsonl�az
created.jsonlrLr=� rDrMr{zempty-titleztitle-has-wallpaper-or-unknownrxzno-imagezprivate-label-coinage-leakrE�reasonrb�
z  SKIP z: )�indent:NixN�POSTz/products.jsonra�idz+UPDATE mdc_catalog SET shopify_product_id='z', on_shopify=true WHERE id=�pidz  �/z created (err z, skip �)g�������?:N��Nz  ERR z
DONE mode=z	 created=z errors=z	 skipped=�ʚ;)r��print�lenr��LIMIT�open�osr6r��OUTr�	TITLE_BAN�search�	HARD_LEAK�writer&r'r�r;rr1r2�	Exception�
isinstancer"r.r/r-r>)�rows�created�errs�skipped�todo�leak_log�created_logrrb�	compositer��payload�respr�r:�details                r	�mainr��sl���<�D�	�-�c�$�i�[�
�v�v�8�[d�Be�ep�z�CH�{H�qv�NS�qT�U�]a�b� � �G� �d����<�D�
�r�w�w�|�|�C�!5�6��
<�
<��
�r�w�w�|�|�C��1�3�
7�
7�;��A��z�]�(�(�b�/�/�1�E� �'��1�^�#4�"5�Q�q���6G�q��:���X�I��F�����!�!�%�(�(�9Y����n�*�*��1�1�3�3�j�V��!�!�)�,�,�9U����1������t�z�z�8�Q�x�[�(�F�T[�]b�*c�d�gk�k�l����(��}�B�v�h�7�t�D��#�A�&�G��6��Q�;��$�*�*�W�Q�7��>�?��1����
��6�#3�W�=���9�o�d�+���B�3�%�H!�!"�4��	�+�,��!�!�$�*�*�h��(��U�C�QX�Z_�-`�"a�dh�"h�i��1����R�<�1�$��B�w�i�q��T���>�$��w�w�i�WX�Y�ae�f��
�
�4� �?�8�=�N
�J�6�6�x�y�9��7�)�8�TX�SY�Yb�cj�bk�
l�tx�y���
���	��+5�a����9O�9O�+P�+P�����$��VY�Z[�V\����q��{�m�2�f�X�6�d�C��
�
�1�
�
��	
��C8�
7��=�
<�s{�
7O(�O	�<O	�O	�6O	�	O	� O	�>	O	�B1O	�:B>L6
�8O	�=O(�6O
�BO

�O	�
O
�O	�O%
� O(�(O8	�__main__r�)r�rYrErLrDrMrCr`r}r~r{r�r�r�rx)(�__doc__r&rrr1�urllib.requestr"�urllib.error�rer��SHOPr%�nextr�r)r6r��dirname�abspath�__file__r��makedirs�argvr��int�indexr��compile�Ir�r�rr;rArJr�r�r�r��__name__rFrr	�<module>r�s@��%�LI�H�H�H�3��
�4�&�*�+���
6��L�M�
6�	6��	�����R�W�W�_�_�R�W�W�_�_�X�%>�?��G�����C�$��	�s�x�x�	��9B�c�h�h�9N��S�X�X�c�h�h�n�n�Y�/�!�3�
4�	5�TY��

�J�J�8�9;���
?�	�
�J�J�1�2�4�4�8�	��0�k�	�3�lG��
!�,z�^�z���F�r