3
.+h                  @   s   d dl Z d dlZ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 d dl	m
Z
 d dlmZmZmZ ejdZdZdd Zd	d
 Zdd Zdd Zedkred eeZede  dS )    N)minidom)ElementTree)Element
SubElementCommentdjangoa  
{"offers":
  [
    {
      "SellerProductId": "4250755391922.",
      "ProductEan": "4250755391922",
      "Price": "289.50",
      "Stock": 5
    },
    {
      "SellerProductId": "4250755391946.",
      "ProductEan": "4250755391946",
      "Price": "249.50",
      "Stock": 5
    },
    {
      "SellerProductId": "4250755391557.",
      "ProductEan": "4250755391557",
      "Price": "234.50",
      "Stock": 5
    }
  ]
}
c             C   s"   t j| d}tj|}|jddS )zO
    :param elem:
    :return: a pretty-printed XML string for the Element
    zutf-8z  )indent)r   tostringr   ZparseStringZtoprettyxml)elemZrough_stringZreparsed r   -/data/git/entellipy_wy/cdiscount/cdiscount.pyprettify*   s    
r   c             C   s  t dddddd}tj| dd}|d	 }t|d
}t|ddt| d}x|D ]}t|dd|d  d|d  d|d  d|d  d|d  d|d  d|d  d|d  d|d  d|d  d|d  d}t|d}|jdg }	t|ddt|	 d}
x.|	D ]&}t|
ddd  d|d!  dd  d" qW qNW d#}t|}|j| tj	t
| tjjtjjt}d$| }tj| tjd% tj  tjd% tj|}|j|d&d'd( tjd% tj  tjd% d)S )*aG  
    The API quota are applied on the number of call to the methods by hour.
    The counter of call is reinitialized every hour.

    If you include more than 300 000 offers in your package you are not sure that your package will be integrated.
    Our advise is to stay below 200 000 offers in your package.
    :return:
    ZOfferPackagezNom fichier offresfalseFullzbclr-namespace:Cdiscount.Service.OfferIntegration.Pivot;assembly=Cdiscount.Service.OfferIntegration)NameZPurgeAndReplaceZPackageTypeZxmlnsF)strictofferszOfferPackage.OffersZOfferCollectionz%d)ZCapacityZOfferz%sSellerProductId
ProductEanPriceStockProductConditionEcoPartDeaTaxVatPreparationTimeStrikedPricer   )r   r   r   r   r   r   r   r   r   r   r   zOffer.ShippingInformationListZDeliveryModesZShippingInformationListZShippingInformationr   ZlegacyDeliveryModeId)ZAdditionalShippingChargesZDeliveryModeZShippingChargesz
    the OfferPublicationList element is optional and is utilized to specify on which website the updates must be done
    by default updates are applied on Cdiscount only (Id=16 for Belgium)
    z6%s/../cdiscount_files/stockandprice/Content/Offers.xml   zutf-8T)encodingxml_declarationN)r   jsonloadsr   lengetr   appendloggerdebugr   ospathdirnameabspath__file__removetimesleepsyncr   write)offers_jsontoploaded_jsonitemsr   Zoffer_collectionZofferZ	offer_xmlZoffer_shippingInformationListZdelivery_modesZshippingInformationListZdelivery_modeZcomment_offerpublicationlistcommentsource_path	file_pathtreer   r   r   
create_xml4   sV    	





















r9   c              C   s   t jjt jjt} tjjtj jd}d|  }d| }d| |f }d| }t	j
|dt	j}xtt j|D ]f\}}}	xZ|	D ]R}
t jj||
}d|krqz|t|d  }tjd|  |j||t|d   qzW qjW |j  |S )	Nz%Y%m%d%H%M%Sz#%s/../cdiscount_files/stockandpricezstockandprice_%s.zipz %s/../cdiscount_files/archive/%sz
archive/%swZDS_Storez
file is %s)r'   r(   r)   r*   r+   datetimefromtimestampr-   strftimezipfileZipFileZIP_DEFLATEDwalkjoinr"   r%   r&   r0   close)r6   	timestampZdir_pathZarchive_file_nameZarchive_file_pathZurl_pathZzipfile_handlerootdirsfilesfiler7   xxxr   r   r   zip_diry   s"    
 rJ   c             C   s.   t jd|   t|  t }t jd|  |S )Nz%szcdiscount returns %s)r%   r&   r9   rJ   info)r1   r(   r   r   r   do   s
    rL   __main__zcdiscount is starting...zcdiscount returns %s)sysr'   r>   r-   r;   r    loggingZxml.domr   Z	xml.etreer   xml.etree.ElementTreer   r   r   	getLoggerr%   Zsample_jsonr   r9   rJ   rL   __name__printresultr   r   r   r   <module>   s&   

E