
    %PhW                         d dl Z d dlZd dlZd dlZd dlZd dlmZ  ej        d          Zd Z	d Z
d Zedk    r ej         e                       dS dS )    N)access_tokens	   c                   K   | d| d| }|dd}t           4 d {V  	 |                     ||          4 d {V }|j        }|                                 d {V }	|dv r[|	                    dg           }
t	          dt          |
                      |
cd d d           d {V  cd d d           d {V  S |	                    d	d
          }t	          d| d|            g cd d d           d {V  cd d d           d {V  S # 1 d {V swxY w Y   n=# t          $ r0}t	          d|            g cY d }~cd d d           d {V  S d }~ww xY w	 d d d           d {V  d S # 1 d {V swxY w Y   d S )Nz/admin/api/z#/customers.json?limit=250&since_id=zapplication/json)zX-Shopify-Access-TokenzContent-Type)headers)      	customersu&   Clients récupérés dans cet appel : errorszErreur inconnuezErreur z: u1   Exception lors de la récupération des clients: )	semaphoregetstatusjsonprintlen	Exception)session	shop_linkdatelast_customer_idaccess_tokenurlr   response	http_codedecoded_responser	   error_messagees                ./var/www/sites/Harken/API/get_all_customers.pyfetch_customersr      s     
^
^4
^
^L\
^
^C".* G
         	{{3{88       H$O	)1#8#8#8#8#8#8 
** 0 4 4[" E EIS3y>>SSTTT$                          %5$8$8CT$U$UM@I@@@@AAA                                         	 	 	IaIIJJJIIIII!             	                             sp   E3D"ADD"?,D+D"
D	D"D	D"!E3"
E,E?E E3EE33
E= E=c                   K   g }d}d}t          j                    4 d {V }	 t          d         }|dz  }t          || |||           d {V }|r$|                    |           |d         d         }nn6|t          t                    z  dk    rt          j        d           d {V  	 d d d           d {V  n# 1 d {V swxY w Y   t          j	        
                    t          j	                            t                              }t          j	                            |d          }	t          |	dd	          5 }
t          j        d
|i|
dd           d d d            n# 1 swxY w Y   t          j        d
|id          S )Nr   T   idz../Customers/Customers.jsonwzutf-8)encodingr	   F   )ensure_asciiindent)r&   )aiohttpClientSessionr   r   extendr   asynciosleepospathdirnameabspath__file__joinopenr   dumpdumps)r   r   all_customersr   token_indexr   r   r	   
script_dirfile_path_jsonfs              r   get_all_customersr;   %   st     MK$&& ' ' ' ' ' ' ''	'(+L1K-gy$HXZfggggggggI $$Y///#,R=#6   S///144mA&&&&&&&&&	' 	'' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '& !:!:;;JW\\*.KLLN	ncG	4	4	4 Q	;.aPPPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q :{M2GGGGs$   B
B??
C	C	E**E.1E.c                  \   K   d} d}t          | |           d {V }t          |           d S )Nz https://harkenb2b.myshopify.com/z2024-10)r;   r   )r   r   customers_jsons      r   mainr>   G   sE      2ID,Y========N	.    __main__)r   r+   r(   timer-   Harken.API.tokensr   	Semaphorer   r   r;   r>   __name__run r?   r   <module>rG      s        				 + + + + + + Ga  	  2H H HD   zGK r?   