a ab?g"@sFddlmZmZmZmZddlmZmZddZddZd dd Z dS) )get_all_entriesget_all_published_entries update_entry_using_json_response publish_entry)datetimetimezonecCs|dd}|d}|d}d|vr|d|vr||dd}d}d|vrP|dd}t||}||dd<||d }td ||S|SdS) Nsysidfieldsmetadata startDateupcomingSortOrderen-USendDater r event)calculate_sort_orderr)rZevent_entry_idZevent_entry_fieldsZevent_entry_metadata start_dateend_dateupcoming_sort_orderZ event_staterL/home/cmiss/Jenkins/workspace/SPARC-API/scripts/update_contentful_entries.pyupdate_event_sort_orders      rcCsvtd}td}i}|D]}|dd}|||<q|D]8}|d}|d}d|vr6d|vr6|ddr6|dd}d} d} d |dvrd } t|dd d } t|dd d } | | d krd } |dd} d}d|vr|dd}t| |}||dd<| rP||d}||dd<|||dd}td||}t||dd| sZ| s6||d}td||q6dS)Nrrr r r r r F publishedAtT updatedAtz%Y-%m-%dT%H:%M:%S.%fZrrrrversion)rrrstrptime total_secondsrrr)Zall_event_entriesZall_published_event_entriesZ$published_event_id_to_fields_mappingZpublished_eventZpublished_event_identryZoriginal_fields_dictZoriginal_metadata_dictentry_idZentry_had_existing_changesZentry_is_publishedZentry_updated_atZentry_published_atrrrZpublished_fields_stateZ updated_stateZ updated_entryZoriginal_staterrrupdate_all_events_sort_ordersL              r Nc Cst|tj}ttj}||}t|d}d}|dkrNd|}|dkr|durd|}n@t|tj}||}t|d} | dk} | sd}n|}|S)NiQg?r)r fromisoformat astimezonerutcnowrint) rrZstart_date_datetimer%Ztime_from_event_in_secondsZtime_from_event_in_daysrZend_date_datetimeZend_time_from_now_in_secondsZend_time_from_now_in_daysZhas_event_endedrrrrFs$    r)N) app.metrics.contentfulrrrrrrrr rrrrrs/