a Fmg@sxddlmZddlmZmZmZmZmZddlm Z ddl m Z m Z ddl Z ddl Z ddlZddZdd Zd d ZdS) )Config)get_cda_client_entry get_cma_entry update_entry_using_json_response publish_entryget_cma_published_entry)get_all_dataset_ids)datetime timedeltaNc Cs ztjdkrztjdkrzttj}ttj}d|dvrz|ddd}|durzt|d}|t dkrzd|dvrg|ddd<d|ddd<d|dvrg|ddd<d|dvrd|ddd<|d|d d }t d tj|}t tj|d d d|d vrzt|d dd}t|d dd}|| dkrz|d|d d } t d tj| t d|durWdSt|} ttj} t|| | } | rt|} t| dd} t| d}z | d}Wntyd}Yn0t|d}t}|| t|dkrH|dkrH| durH|WSt| ddksd| durt| ddkr| d| d<n t| d<| d}tdt|d}||| d<|d| d<|| d<|tjt | dWn0ty}zt!d|WYd}~n d}~00dS) N developmentFALSEdateToClearFeaturedDatasetsfieldszen-USz%Y-%m-%drfeaturedDatasetsmetadata)rrhomepagesysversion publishedAt updatedAtz%Y-%m-%dT%H:%M:%S.%fZz/Setting featured dataset id selector state infolast_used_time%Y-%m-%d %H:%M:%S.%ffeatured_dataset_id time_delta)daysFavailable_dataset_idsTlimited_available_idsz)Error while setting featured dataset id: )"r DEPLOY_ENVSPARC_API_DEBUGGINGrCTF_HOMEPAGE_IDrr strptimenow total_secondsrrlogginginfo#get_featured_dataset_id_table_staterrset_limited_dataset_idsint Exceptionfloatr lencopyrrandomrandintpopstrftime updateState&FEATURED_DATASET_ID_SELECTOR_TABLENAMEjsondumpsprint)featuredDatasetIdSelectorTableZhomepage_cma_staging_entryZhomepage_cma_published_entryZdate_to_clear_datasetsZdatetime_date_to_clear_datasetsZupdated_published_state updated_entryZhomepage_staging_updated_atZhomepage_staging_published_atoriginal_state table_stateZcf_homepage_responseZlimited_ids_were_setrrZtime_delta_in_hoursZtime_delta_in_daysr%Zavailable_dataset_ids_arrayZ random_indexer>Q/home/cmiss/Jenkins/workspace/SPARC-API-DEV/scripts/update_featured_dataset_id.pyset_featured_dataset_id sv              ( r@cCsf|d}z |d}Wnty*g}Yn0t|t|kr@dS||d<|tjt|ddSdS)Nrfeatured_datasetsFT)r,setr4rr5r6r7)tabler<Zcontentful_stateZpersisted_limited_available_idsZupdated_limited_available_idsr>r>r?r*Ts   r*cCsptdggdd}|dur$|Sz6|tj}|durP|tjt|d}t |WS|YS0dS)Nrr)rrrrT) r r%r3 pullStaterr5r4r6r7loads)rCZ default_data current_stater>r>r?r)cs   r)) app.configrapp.metrics.contentfulrrrrrapp.metrics.algoliarr r r6r'r0r@r*r)r>r>r>r?s  J