a ,õkg­ ã @sˆ ddlZddlZddlmZddlmZmZmZddlm Z m Z ddl m Z m Z mZmZddlmZmZddlmZddlmZmZdd lmZddlZddlZddlZddlZddlZddlZddlZdd l m!Z!ddl"Z"ddl#Z#ddl$Z$ddl%Z%ddl&Z&dd l'm(Z(dd l)m*Z*dd l+m,Z,ddl-m.Z.ddl/m0Z0ddl1m2Z2ddl3m3Z3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9ddl:m;Z;ddlm?Z?ddl@mAZBddlCmDZDddlEmFZFddlGmHZHddlImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXddlYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_ddl&m`Z`ddlambZbddlcmdZdddlemfZfmgZgmhZhdd limjZjmkZkmlZlmmZmmnZnmoZompZpdd!lqmrZrdd"lsmtZtmuZudd#lvmwZxdd$lvmyZzdd%l{mjZ|m}Z~e# ¡e6e€ƒZedj‚ ƒ¡Z„ej… †e‡e#e„e#jˆƒ¡edj‰ejŠd&<eHed'd(d)œd*Z‹e;eƒe=eƒZŒeZƒZdaŽejd+edjedj‘d,d-Z’e`ƒZ“zefedj”ƒZ•Wne–yndZ•Yn0zegedj”ƒZ—Wne–y–dZ—Yn0zehedj”ƒZ˜Wne–y¾dZ˜Yn0Gd.d/„d/e™ƒZše ›d0¡d1d2„ƒZœejd3d4„ƒZže*ƒZŸe*ƒZ e*ƒZ¡e*ƒZ¢e*ƒZ£e¢j¤s(e# ¥d5¡e¢ ¦¡edj‰d6krle*ƒZ§eƒZ¨e¨ ©¡e§ ¦¡e§jªe¨j©d7d8d8d9d:ddd;edj‰d¡e£ ¦¡e£jªe d7d?d@dAiZ¬ejdBdC„ƒZ­iZ®eƒZ¯e ƒZ°eƒZ±ejdDdE„ƒZ²eƒZ³ejdFdG„ƒZ´e¡jªe´dHdIdJeŸjªe­dHdIdJe jªe²dHdKdLe,e.ƒe0dIdMgƒZµe¢ ªdNdO„eµ¡dPdQ„Z¶e ·e¶¡e ¸dR¡dSdT„ƒZ¹ej¸dUdVgdWdXdY„ƒZºdZd[„Z»e ¸d\¡d]edj¼fd^d_„ƒZ½e ¸d`¡dadb„ƒZ¾e ¸dc¡edj¼fddde„ƒZ¿e ¸df¡edj¼fdgdh„ƒZÀdidj„ZÁe ¸dk¡dldm„ƒZÂdndo„ZÃe ¸dp¡edj¼fdqdr„ƒZÄe ¸ds¡dtdu„ƒZÅe ¸dv¡e ¸dw¡dxdy„ƒƒZÆe ¸dz¡d{d|„ƒZÇe ¸d}¡d~d„ƒZÈe ¸d€¡e ¸d¡d‚dƒ„ƒƒZÉe ¸d„¡e ¸d…¡d†d‡„ƒƒZÊe ¸dˆ¡e ¸d‰¡dŠd‹„ƒƒZËe ¸dŒ¡ddŽ„ƒZÌe ¸d¡dd‘„ƒZÍe ¸d’¡d“d”„ƒZÎe ¸d•¡d–d—„ƒZÏe ¸d˜¡edj¼fd™dš„ƒZÐe ¸d›¡dœd„ƒZÑdždŸ„ZÒej¸d d¡d¢dd£œd¤e ¸d¥¡d/d¦d§„ƒƒZÓej¸d¨d©d¡id¤e ¸dª¡d«d¬„ƒƒZÔe ¸d­¡d®d¯„ƒZÕd°d±„ZÖd²d³„Z×d´dµ„ZØe ¸d¶¡d·d¸„ƒZÙe ¸d¹¡dºd»„ƒZÚe ¸d¼¡d½d¾„ƒZÛe ¸d¿¡dÀdÁ„ƒZÜe ¸d¡dÃdÄ„ƒZÝej¸dÅdÆgdWdÇdÈ„ƒZÞej¸dÉdÆgdWdÊdË„ƒZßej¸dÌdÆgdWe‹jàd(dÍdÎdÏ„ƒƒZáej¸dÐdÆgdWdÑdÒ„ƒZâej¸dÓdÆgdWdÔdÕ„ƒZãej¸dÖdÆgdWd0dØdÙ„ƒZäej¸dÚdÆgdWdÛdÜ„ƒZåej¸dÝdÆgdWdÞdß„ƒZæej¸dàdÆgdWdád℃Zçej¸dãdÆgdWdäd儃Zèdædç„Zédèdé„Zêdêdë„Zëej¸dìdVgdWdídZìej¸dïdVgdWdðdñ„ƒZíej¸dòdVgdWdódô„ƒZîej¸dõdVgdWdöd÷„ƒZïej¸dødVgdWdùdú„ƒZðdûdü„Zñdýdþ„Zòej¸dÿdVgdWdd„ƒZóej¸ddVgdWdd„ƒZôej¸ddVgdWdd„ƒZõej¸ddÆgdWd d „ƒZöe ¸d ¡d d „ƒZ÷e ¸d¡dd„ƒZøe ¸d¡dd„ƒZùej¸ddVgdWdd„ƒZúej¸ddVgdWdd„ƒZwej¸ddVgdWdd„ƒZyej¸ddVgdWdd„ƒZûe ¸d ¡d!d"„ƒZüej¸d#dÆgdWd$d%„ƒZýej¸d&dÆgdWd'd(„ƒZþej¸d)dVgdWd*d+„ƒZÿej¸d,dÆgdWd-d.„ƒZdS(1éN)Úget_download_count)Úinit_cf_cda_clientÚget_funded_projects_countÚget_featured_datasets)Úupdate_all_events_sort_orderÚupdate_event_sort_order)Úget_dataset_countÚinit_algolia_clientÚget_all_dataset_idsÚget_associated_datasets)Úinit_ga_reportingÚget_ga_1year_sessions)Ú MonthlyStats)Úset_featured_dataset_idÚ#get_featured_dataset_id_table_state)ÚOSparcServices)Ú ApiException)Úurlparse)ÚBackgroundScheduler)Ú OrTrigger)Ú DateTrigger)ÚIntervalTrigger)Ú ClientError)ÚdatetimeÚ timedelta)ÚFlaskÚabortÚjsonifyÚrequest)ÚCORS)Ú Marshmallow)Ú Pennsieve)ÚUnauthorizedException)ÚImage)Ú HTTPBasicAuth)ÚCache)Úcreate_doi_queryÚcreate_filter_requestÚcreate_facet_queryÚcreate_doi_aggregateÚcreate_title_queryÚcreate_identifier_queryÚ!create_pennsieve_identifier_queryÚcreate_field_queryÚcreate_request_body_for_curiesÚcreate_onto_term_queryÚcreate_multiple_doi_queryÚ create_multiple_discoverId_queryÚcreate_anatomy_queryÚget_body_scaffold_dataset_idÚcreate_multiple_mimetype_query)Ú EmailSenderÚfeedback_emailÚgeneral_interest_emailÚissue_reporting_emailÚ#creation_request_confirmation_emailÚservice_interest_email)ÚLock)Ú ElementTree)ÚConfig)ÚMapTableÚ ScaffoldTableÚFeaturedDatasetIdSelectorTable)Úprocess_resultsÚprocess_get_first_scaffold_infoÚreform_aggregation_resultsÚreform_curies_resultsÚreform_dataset_resultsÚreform_related_termsÚreform_anatomy_results)ÚContactRequestSchema)Úimg_to_base64_strÚget_path_from_mangled_list)Ústart_simulation)Úcheck_simulation)rAÚprocess_resultZENVZ SimpleCacheé,)Z CACHE_TYPEZCACHE_DEFAULT_TIMEOUT)ÚconfigÚs3z us-east-1)Zaws_access_key_idZaws_secret_access_keyZ region_namec@s`eZdZdZe ¡edƒZdZe dd„ƒZ dd„Z e dd „ƒZ d d „Z e d d „ƒZdd„ZdS)Ú BiolucidaÚi?BFcCs |t_dS©N)rQÚ_token©Úvalue©rWú7/home/cmiss/Jenkins/workspace/SPARC-API-DEV/app/main.pyÚ set_tokenlszBiolucida.set_tokencCs|jSrS)rT©ÚselfrWrWrXÚtokenpszBiolucida.tokencCs |t_dSrS)rQÚ _expiry_daterUrWrWrXÚset_expiry_datesszBiolucida.set_expiry_datecCs|jSrS)r]rZrWrWrXÚ expiry_datewszBiolucida.expiry_datecCs |t_dSrS)rQÚ_pending_authenticationrUrWrWrXÚset_pending_authenticationzsz$Biolucida.set_pending_authenticationcCs|jSrS)r`rZrWrWrXÚpending_authentication~sz Biolucida.pending_authenticationN)Ú__name__Ú __module__Ú __qualname__rTrÚnowrr]r`Ú staticmethodrYr\r^r_rarbrWrWrWrXrQgs   rQé”cCstt|ƒddfS)N)Úerrorrh)rÚstr)ÚerWrWrXÚresource_not_found‚srlc CsÈzttjtjdtjdaWn¨tjjyV}z t   d¡t   |¡WYd}~nvd}~0t yŒ}z t   d¡t   |¡WYd}~n@d}~0t yÂ}z t   d¡t   |¡WYd}~n d}~00dS)NF)Z api_tokenZ api_secretZ env_overrideÚhostz#Unable to connect to Pennsieve hostz&Unable to authorise with Pennsieve Apiz Unknown Error) r!r=ZPENNSIEVE_API_TOKENZPENNSIEVE_API_SECRETZPENNSIEVE_API_HOSTÚpsÚrequestsÚ exceptionsÚ HTTPErrorÚloggingriÚPSUnauthorizedExceptionÚ Exception)ÚerrrWrWrXÚconnect_to_pennsieve‡s ü    rvz6Starting scheduler for featured dataset id acquisitionÚ productionZcronÚ*Ú1Ú2)ÚyearÚmonthÚdayÚhourÚminuteÚsecondZ developmentZFALSEz8Starting scheduler for updating contentful event entrieséz US/Eastern)r~Útimezonec Cs¤t d¡zLtjtj›dd}|jrTd|j dd¡vrT| ¡}t |dƒ}|t d<Wn0t y†}zt  d |¡WYd}~n d}~00t js t d ¡t  ¡dS) NzGetting oSPARC viewersz/viewers©Úurlúapplication/jsonú content-typerRÚdataÚ file_viewersz!Could not retreive oSPARC viewersz1Starting scheduler for oSPARC viewers acquisition)rrÚinforoÚgetr=ÚOSPARC_API_HOSTÚokÚheadersÚjsonÚbuild_filetypes_tableÚ osparc_datartriÚviewers_schedulerÚrunningÚstart)ÚreqZviewersÚtablerkrWrWrXÚget_osparc_file_viewers¾s   " r–cCspt d¡trttƒ}|td<tr2ttƒ}|td<trFttƒ}|td<t ƒ}|td<t j slt d¡t   ¡dS)NzGathering metrics dataZ1year_sessions_countZ dataset_countZfunded_projects_countZ1year_download_countz*Starting scheduler for metrics acquisition) rrr‰Úgoogle_analyticsr Ú usage_metricsÚalgoliarÚ contentfulrrÚmetrics_schedulerr’r“)Z ga_responseZalgolia_responseZ cf_responseZ ps_responserWrWrXÚ get_metricsÕs  rœc Csnt d¡z.tjtj›dd}| ¡}t |d¡Wn0t yh}zt  d|¡WYd}~n d}~00dS)NzFetching oSPARC servicesz /servicesrƒr‡z%Request to get oSPARC services failed) rrr‰rorŠr=r‹rŽÚosparc_servicesZ set_servicesrtri)r”Z services_resprkrWrWrXÚ get_servicesîs ržÚintervalé)ÚfuncÚtriggerÚdaysé)r¡r¢Úhours)r¥cCsttƒSrS)rÚfeaturedDatasetIdSelectorTablerWrWrWrXÚór§cCs|t d¡tjrt ¡t d¡tjr0t ¡t d¡tjrHt ¡t d¡tjr`t ¡t d¡tjrxt ¡dS)Nz1Stopping scheduler for oSPARC viewers acquisitionz*Stopping scheduler for metrics acquisitionz2Stopping scheduler for updating contentful entriesz3Stopping scheduler for updating featured dataset idz&Stopping scheduler for oSPARC services) rrr‰r‘r’Úshutdownr›Ú)update_contentful_event_entries_schedulerÚfeatured_dataset_id_schedulerÚservices_schedulerrWrWrWrXÚshutdown_schedulerss     r­z/healthcCst ddi¡S)NÚstatusZhealthy)rŽÚdumpsrWrWrWrXÚhealthsr°z/contactÚPOST)Úmethodsc Csht tj¡}tƒ |¡}|d}|d}|d}t |||¡t t j |dt   d|i¡¡t  ddi¡S)NÚnameÚemailÚmessagezFeedback submissionr®Úsent)rŽÚloadsrr‡rHÚloadÚ email_senderZ send_emailÚsendgrid_emailr=Ú SES_SENDERr6Ú substituter¯)r‡Zcontact_requestr³r´rµrWrWrXÚcontact s  r½cCstjd||d|dœ|d}|S)NÚ get_objectÚ requester)ÚBucketÚKeyÚ RequestPayerZResponseContentType)ZParamsZ ExpiresIn)rPZgenerate_presigned_url)Ú s3BucketNameÚkeyÚ content_typeÚ expirationÚresponserWrWrXÚcreate_s3_presigned_url.s  ýrÈz /downloadicCs6tj d¡}tj d|¡}tj dd¡}t||||ƒS)NrÄrÃZ contentTypezapplication/octet-stream)rÚargsrŠrÈ)rÆÚ bucket_namerÄrÃrÅrWrWrXÚcreate_presigned_url9s rËz/thumbnail/neurolucidac Cstj}d|vsd|vsd|vr*tdddStj›d}zPtj||dd }| ¡|jd krz|j  d d ¡d krzt   |j ¡WStddƒWn|tj jy¨tdddYStj jyÆtddƒYStj jy}z tddt|ƒ›ƒWYd}~Sd}~00dS)NÚversionZ datasetIdÚpathéúQuery arguments are not valid.©Ú descriptionz /thumbnailé)ÚparamsÚtimeoutéÈú Content-TypeÚunknownz image/pngzFailed to retrieve thumbnail.z0Unable to make a connection to NEUROLUCIDA_HOST.iøz&Request to NEUROLUCIDA_HOST timed out.éöz)Error while requesting NEUROLUCIDA_HOST: )rrÉrr=ZNEUROLUCIDA_HOSTrorŠZraise_for_statusÚ status_coderÚbase64Ú b64encodeÚcontentrpÚConnectionErrorZTimeoutZRequestExceptionrj)Ú query_argsr„rÇrkrWrWrXÚthumbnail_from_neurolucida_fileBs"   rßz/thumbnail/segmentationc Cstj}d|vrtdddS| d|¡}|d}d}d}d}d}d }|} |rP|sTz"tj||d |›d | ›d d } Wnvtyè} z^| jdddkr´tdd|›ddWYd} ~ Stdd|›ddWYd} ~ SWYd} ~ n d} ~ 00| d ¡  d¡}d|v}d|v}|r"|s"| |7} n||7}| |7} t |ƒ|krFtdd|›ddSqF|durrtdd|›ddS||  d¡d…} | d|   d¡…d} t   | ¡}|j}d}|D]}||jdd…7}q²t |¡}t dt|dƒt|dƒf|¡}t|ƒ}|S)z° Extract a thumbnail from a mbf xml file. First phase is to find the thumbnail element in the xml document. Second phase is to convert the xml to a base64 png. rÍrÎrÏrÐrÃNFrièzbytes=ú-r¿)rÀrÁZRangerÂÚErrorÚCodeÚ NoSuchKeyrhúCould not find file: 'ú'úUnknown error for file: 'ÚBodyzUTF-8z z#Could not find thumbnail in file: 'rRrZRGBZrowsÚcols)rrÉrrŠrPr¾rrÇÚreadÚdecodeÚlenÚfindr<Ú fromstringÚattribÚtextÚbytesÚfromhexr#Ú frombytesÚintrI)rÊrÞrÃrÍÚresourceZstart_tag_foundZ end_tag_foundZ start_byteÚoffsetZend_byterÇÚexZstart_thumbnail_elementZ thumbnail_xmlÚxmlZ size_infoZim_dataÚchildZ byte_im_dataZimZ base64_formrWrWrXÚextract_thumbnail_from_xml_fileYsZ   ü  6      "rùz/exists/cCsftj}| d|¡}ztj||dd}Wnty@ddiYS0| dd¡}|dkr^ddiSddiS) NrÃr¿©rÀrÁrÂÚexistsÚfalseÚ ContentLengthrÚtrue)rrÉrŠrPÚ head_objectr)rÍrÊrÞrÃÚ head_responseÚcontent_lengthrWrWrXÚ url_exists˜s ý   rcCs0| dd¡}|d| d¡…}t |¡}| ¡S)Nzhttps://api.pennsieve.io/z"https://api.pennsieve.io/discover/ú/)ÚreplaceÚrfindrorŠrŽ)ÚuriÚrrWrWrXÚfetch_discover_file_information¯s  rz/s3-resource/discover_pathc Cs†tj d¡}z6t|ƒ}d|vr@|ddkr@|dd}|dWSWn0tyr}zt d|¡WYd}~n d}~00tdd |›d S) NrZ totalCountr ÚfilesrrÍzFailed to retrieve uri {uri}rhzFailed to retrieve uri rÐ)rrÉrŠrrtrrrir)rZ json_responseÚ file_inforörWrWrXÚget_discover_path¸s  "r c CsäzDtj||dd}| dtj¡}|rB|tjksBtdd|›dWSWn–tjjyÚ}zz|j ddd krzdWYd}~S|j ddd krœdWYd}~St|j dd|j ddƒWYd}~SWYd}~nd}~00dSdS)Nr¿rúrýizFile too big to download: rÐrárâZ404rhú.Provided path was not found on the s3 resourceZ403é“úEThere is a permission issue when accessing the file at specified pathÚMessage)rÕÚOK)rhr )r r) rPrÿrŠr=ZDIRECT_DOWNLOAD_LIMITrÚbotocorerprrÇ)rÍrÊrrrurWrWrXÚs3_header_checkÅs ý@rz/s3-resource/c Csàtj}| d|¡}|}t||ƒ}|ddks8|ddkr¢t|ƒ}||krTtdddt||ƒ}|ddkrp|}n2|ddkrŠtdddn|ddkr¢tdddtj||d d }tj d ¡}|d  ¡} |durÜt   | ¡S| S) NrÃrrhr r rÐrÕrr¿rúZ encodeBase64rç) rrÉrŠrrJrrPr¾rérÚrÛ) rÍrÊrÞrÃZs3_pathrÇZs3_path_modifiedZ response2Ú encode_base64rôrWrWrXÚdirect_download_urlÞs2        ý   rz /scicrunch-dataset//c Csˆ| dd¡d|}t|ƒ}z&tjtj›dtj›|d}| ¡WStjj y‚}z$t   |¡t  d|i¡WYd}~Sd}~00dS)NzDOI:rRrú/_search?api_key=©rŽri) rr&roÚpostr=ÚSCI_CRUNCH_HOSTÚKNOWLEDGEBASE_KEYrŽrprqrrrir¯)Zdoi1Zdoi2Údoir‡rÇrurWrWrXÚsci_doisþ  rz /pubmed/z/pubmed//c Cs`zt d|›d¡}|jWStjjyZ}z$t |¡t d|i¡WYd}~Sd}~00dS)Nz https://pubmed.ncbi.nlm.nih.gov/rri) rorŠrïrprqrrrirŽr¯)Úid_rÇrurWrWrXÚpubmeds  rz/scicrunch-query-string/c Cs®tj d¡}tj d¡}tj d¡}tj d¡}t||||ƒ}z*tjtj›dtj ›|d}t |  ¡ƒWStj j y¨}z$t |¡t  d|i¡WYd}~Sd}~00dS)NÚfieldÚcurieÚsizeÚfromrrri)rrÉÚgetlistrŠr-rorr=rrrArŽrprqrrrir¯)Úfieldsrr Zfrom_r‡rÇrurWrWrXÚ sci_organ"s    þ r$z/dataset_info/using_doicCs<tj d¡}tj d¡}t|ƒ}|dur4tt|ƒƒSt|ƒS)NrZ raw_response)rrÉrŠr&rEÚdataset_search)rÚrawÚqueryrWrWrXÚget_dataset_info_doi5s    r(z!/dataset_info/using_multiple_doisz"/dataset_info/using_multiple_dois/cCs tj d¡}t|ƒ}tt|ƒƒS)NÚdois)rrÉr"r0rAr%)r)r'rWrWrXÚget_dataset_info_dois@s r*z./multiple_dataset_info/using_multiple_mimetypez//multiple_dataset_info/using_multiple_mimetype/cCs tj d¡}t|ƒ}tt|ƒƒS)NÚq)rrÉr"r4rAr%)r+r'rWrWrXÚget_file_info_from_mimetypeHs r,z(/dataset_info/using_multiple_discoverIdsz)/dataset_info/using_multiple_discoverIds/cCs tj d¡}t|ƒ}tt|ƒƒS)NÚ discoverIds)rrÉr"r1rAr%)r-r'rWrWrXÚget_dataset_info_discoverIdsRs r.z/dataset_info/using_titlecCs tj d¡}t|ƒ}tt|ƒƒS)NÚtitle)rrÉrŠr*rEr%)r/r'rWrWrXÚget_dataset_info_title[s r0z%/dataset_info/using_object_identifiercCs tj d¡}t|ƒ}tt|ƒƒS©NÚ identifier)rrÉrŠr+rEr%©r2r'rWrWrXÚ"get_dataset_info_object_identifiercs r4z/dataset_info/anatomycCs6tj dd¡}|dkr"tdddSt|ƒ}tt|ƒƒS)Nr2éÿÿÿÿrhz Identifier for API call not set.rÐ)rrÉrŠrr2rGr%r3rWrWrXÚget_dataset_info_anatomyks  r6z(/dataset_info/using_pennsieve_identifiercCs tj d¡}t|ƒ}tt|ƒƒSr1)rrÉrŠr,rEr%r3rWrWrXÚ%get_dataset_info_pennsieve_identifiervs r7z/segmentation_info/c CsZtj}d|vrtdddS| d|¡}| d¡}z6t||ƒ}|ddkrTtdddtj||d d }WnvtyÜ}z^|jd d d kr¨tdd|›ddWYd}~Stdd|›ddWYd}~SWYd}~n d}~00|d  ¡}t   |¡}|  d¡}i} |dur|j | d<ndddddœ| d<|  d¡} | durJ| j | d<n ddi| d<| S)NÚ dataset_pathrÎz,Query arguments must include 'dataset_path'.rÐrÃrrhr r¿rúrárârãrärårærçz./{*}sparcdata/{*}subjectÚsubjectrR)ZageZsexÚspeciesZ subjectidz./{*}sparcdata/{*}atlasZatlasZorgan)rrÉrrŠrrPr¾rrÇrér<rírìrî) rÊrÞrÃr8rÇrörôr÷Zsubject_elementr‰Z atlas_elementrWrWrXÚget_segmentation_info_from_file~s<      ý  6         r;z/current_doi_listcCsBtƒ}tt|ƒƒ}g}|ddD]}| |dd¡q"d|iS)NrÚbucketsrÄrÚresults)r)rCr%Úappend)r'r=Z doi_resultsÚresultrWrWrXÚ get_all_doi«s  r@c Cstz0|}dtji}tjtj›d||d}| ¡WStjjyn}z"t  |¡t d|iƒWYd}~Sd}~00dS)NÚapi_keyú/_search)rŽrÓri) r=rrorrrŽrprqrrrir)r'ÚpayloadrÓrÇrurWrWrXr%¶sÿÿ  r%z/search/rRé )r'Úlimitr“)Údefaultsz/search/c CsÒzŒtj d¡durtj d¡}tj d¡dur:tj d¡}tj d¡durVtj d¡}t tj›d|›d|›d|›dtj› ¡}t| ¡ƒWStj j yÌ}z$t   |¡t  d|i¡WYd}~Sd}~00dS) NrEr'r“z /_search?q=z&size=z&from=z &api_key=ri)rrÉrŠror=rrrArŽrprqrrrir¯)r'rEr“rÇrurWrWrXÚ kb_searchÈs   * rGz/filter-search/r'z/filter-search//c CsÞtj d¡}tj d¡}tj d¡}tj d¡}t|||||ƒ}z,tjtj›dtj ›|d}t |  ¡ƒ}Wnltj j y´}z,t |¡tt|ƒddœƒd fWYd}~Sd}~0t jyØtd d d œƒd fYS0|S) NÚtermZfacetr r“rrzc Csòt|ƒ\}}g}||D]¬}||d|›dd<z2tjtj›dtj›|d}| ¡}| |¡WqtjyŽt dddœƒd fYSt yÂ}zt   d |›|¡WYd}~qd}~00qg}|D]} || d|›d 7}qÎt |ƒS) NZ aggregationsrMrrrrJrKrLrØz$Could not search SciCrunch for path r<) r(rorr=rrrŽr>rKrrtrrri) Útype_Ztype_mapr‡r=rÍrÇZ json_resultrörMr?rWrWrXÚ get_facets÷s.  þÿÿ *rPcCs&d|vr"t | d¡¡}|j|d<dS)NZreadmeZmarkdown)rorŠrï)ÚrespZmark_reqrWrWrXÚinject_markdownsrRc CsB| d¡}| d¡}|dus$|dur(dSt|ƒ}|j}ztj|d |¡dd}Wn|tyÌtjdk}|rvt   d¡ztj|d |¡dd}Wn6tyÆ}z|r®t   |¡WYd}~YdSd}~00Yn0|d   ¡}zt  |¡} Wn2ty}zt   |¡WYd}~dSd}~00|  d ¡|  d ¡|  d ¡d œ|d<dS)NÚidrz{}/files/template.jsonr¿rúZTRUEzXRequired file template.json was not found under /files folder, trying under /packages...z{}/packages/template.jsonrçÚuuidr³rÑ)rTr³rÑZstudy)rŠrÚnetlocrPr¾Úformatrr=ÚSPARC_API_DEBUGGINGrrÚwarningrirérŽr·Ú ValueError) rQrrZ parsed_uriÚbucketrÇÚ debuggingrkÚtemplateZ template_jsonrWrWrXÚinject_template_datasL  ý   ÿý     ýr]cCsFi}|D]8}|d ¡}|d=| |d¡s2g||<|| |¡q|S)NZ file_typeF)ÚlowerrŠr>)Zosparc_viewersr•ZviewerZfiletyperWrWrXrKs  rz/sim/dataset/c Cs’tjdkrŽz@t d tj|¡¡}|jrH| ¡}t |ƒt |ƒt |ƒWSWn6t y€}zt  d|›|¡WYd}~n d}~00tdddSdS)NÚGETz{}/datasets/{}úCould not fetch SIM dataset rhúResource not foundrЩrÚmethodrorŠrVr=ÚDISCOVER_API_HOSTrŒrŽrRr]rrtrrrir)rr”Ú json_datarörWrWrXÚ sim_datasetUs (rfz&/sim/dataset//versions/c Csštjdkr–zBt d tj||¡¡}|jrJ| ¡}t |ƒt |ƒt |ƒWSWn<t yˆ}z$t  d|›d|›|¡WYd}~n d}~00tdddSdS)Nr_z{}/datasets/{}/versions/{}r`z version rhrarÐrb)rZversion_r”rerörWrWrXÚsim_dataset_versionscs .rgz/get_osparc_datacCsttƒSrS)rrrWrWrWrXÚget_osparc_datassrhz /sim/servicecCsTtjdkrPtj d¡}tjjddtd}tjjddtd}t |||¡}t|ƒSdS)Nr_ÚsearchrErÒ)ÚdefaultÚtypeÚskipr)rrcrÉrŠrórZsearch_servicesr)rirErlr=rWrWrXÚ osparc_searchxs   rmz /sim/filecCs tjdkrtj}td|iƒSdS)Nr_rˆ)rrcrZfile_extensionsr)Ú extensionsrWrWrXÚosparc_extensions‚s  ÿroz/project/r_cCs4t|ƒ}t|dƒdkr$t|dƒStddddS)NÚhitsrrhrarÐ)r rërr)Z project_idÚdatasetsrWrWrXÚdatasets_by_project_id‹s rrz"/get_featured_datasets_identifierscCs dtƒiS)NÚ identifiers)rrWrWrWrXÚ!get_featured_datasets_identifiers•srtz/get_featured_dataset)rÔc Cs¢ttƒd}|dkrd}zBt d tj|¡¡ ¡}|dgkrVt d tjd¡¡ ¡}|WSty}zt   d|›|¡WYd}~n d}~00t ddd dS) NÚfeatured_dataset_idr5é z{}/datasets?ids={}rqzCould not get featured dataset rhz,An error occured while fetching the resourcerÐ) rr¦rorŠrVr=rdrŽrtrrrir)rurÇrörWrWrXÚget_featured_dataset™s  (rwz/get_owner_email/csPtjj}tjj |¡}‡fdd„|Dƒ}|s:tdddntd|djiƒSdS)Ncsg|]}|jˆkr|‘qSrW)Zint_id)Ú.0Úx©Úowner_idrWrXÚ °r¨z#get_owner_email..rhzOwner not foundrÐr´r)rnZ_apiZ _organizationZ organizationsZ get_membersrrr´)r{ZorgÚmembersÚresrWrzrXÚget_owner_email«s rz!/get_body_scaffold_info/cCs:t|ƒ}|r(t|ƒ}tt|ƒƒ}|r(|Stdd|›dS)NrhzWhole body info not found for rÐ)r3r,rBr%r)r:rSr'r?rWrWrXÚget_body_scaffold_infoºs r€z/thumbnail/Fc Csütƒ}z´t| ¡stƒWdƒn1s00Ytjd |¡}d| ¡i}tjd||d}t   |j ¡}|dkr¶|s¶t|  d¡Wdƒn1s¢0Yt |dƒ}|WStyð}zt d|›|¡WYd}~n d}~00td d ƒS) Nz/thumbnail/{0}r\r_©rs¼eyJzdGF0dXMiOiJBZG1pbiB1c2VyIGF1dGhlbnRpY2F0aW9uIHJlcXVpcmVkIHRvIHZpZXcvZWRpdCB1c2VyIGluZm8uIFlvdSBtYXkgbmVlZCB0byBsb2cgb3V0IGFuZCBsb2cgYmFjayBpbiB0byByZXZlcmlmeSB5b3VyIGNyZWRlbnRpYWxzLiJ9rRTz Could not get the thumbnail for rhz-An error occured while fetching the thumbnail)rQÚbiolucida_lockr\Úauthenticate_biolucidar=ÚBIOLUCIDA_ENDPOINTrVrorrÚrÛrÜrYÚthumbnail_by_image_idrtrrrir)Úimage_idZrecursive_callÚblr„rrÇZencoded_contentrörWrWrXr…Ås($ÿ ÿ( (r…z/image/c Csltjd |¡}zt d|¡}t| ¡ƒWSty`}zt  d|›|¡WYd}~n d}~00t ddƒS)Nz/image/info/{0}r_zCould not get image info for rhz/An error occured while getting the image's info) r=r„rVrorÚprocess_biolucida_resultrŽrtrrrir)r†r„rÇrörWrWrXÚimage_info_by_image_idås (r‰z/image_search/c Csjtjd |¡}zt d|¡}| ¡WSty\}zt d|›|¡WYd}~n d}~00ddidfS)Nz%/imagemap/search_dataset/discover/{0}r_z$Could not search images for dataset riz3An error occured while searching images for datasetrh) r=r„rVrorrŽrtrrri)Z dataset_idr„rÇrörWrWrXÚimage_search_by_dataset_idðs  (rŠz/image_xmp_info/cCsvtjd |¡}zt d|¡}Wn"tjjyBtdddYS0| ¡}|ddkrdt |dƒStdd |›dS) Nz/image/xmpmetadata/{0}r_rÎú)Unable to make a connection to Biolucida.rÐr®Úsuccessr‡zXMP info not found for ) r=r„rVrorrprÝrrŽÚprocess_biolucida_results©r†r„r?rÇrWrWrXÚimage_xmp_infoûs  rz/image_blv_link/cCsztjd |¡}zt d|¡}Wn"tjjyBtdddYS0| ¡}|ddkrht d|diƒStdd |›dS) Nz/image/blv_link/{0}r_rÎr‹rÐr®rŒÚlinkzBLV link not found for ) r=r„rVrorrprÝrrŽrrŽrWrWrXÚimage_blv_link s r‘cCsdtƒ}tjd}tjtjddœ}g}i}tjd||||d}|jtjj kr`|  ¡}|  |d¡dS)Nz /authenticaterR)ÚusernameÚpasswordr\r±)rr‡r r\) rQr=r„ZBIOLUCIDA_USERNAMEZBIOLUCIDA_PASSWORDrorrÙZcodesrŒrŽrY)r‡r„rCr rrÇrÜrWrWrXrƒs þrƒcCshd}tjdrd}|rXt ¡}|rJd|vrJ|d}| ||¡}td|iƒStdddn td d ddS) NTÚTESTINGFÚstaterTrÎzState not specifiedrÐrhúDatabase not available)ÚapprOrÚget_jsonZ pushStaterr)r•Zcommitrer•rTrWrWrXÚget_share_link*s    r™cCs^|rNt ¡}|r@d|vr@|d}| |¡}|r@td| |¡iƒStdddn tddddS)NrTr•rÎz#Key missing or did not find a matchrÐrhr–)rr˜Z pullStaterr)r•rerTr•rWrWrXÚget_saved_state:s  ršz/map/getshareidcCsttƒSrS)r™ÚmaptablerWrWrWrXÚget_map_share_linkHsrœz /map/getstatecCsttƒSrS)ršr›rWrWrWrXÚ get_map_stateNsrz/scaffold/getshareidcCsttƒSrS)r™Ú scaffoldtablerWrWrWrXÚget_scaffold_share_linkTsrŸz/scaffold/getstatecCsttƒSrS)ršržrWrWrWrXÚget_scaffold_stateZsr ú/tasksc# CsJtj}d|vrˆzFtjtjtj|ddœd}| ¡}d|vsD|dsRddidfWSWqžty„}zt   d|¡WYd}~qžd}~00nt j d sžddidfS|r:d |vr:d |vr:|d }|d }|d }d d tj i}dtjd}tjtjtjtjtjtjg} tjtjtjtjtjtjg} tj} d} d} g}|rNd|vrN|d} | dkr’dtjd}tjtjtjg} tjtjtjg} tj} tj} | dkrØdtjd}tjtjtjg} tjtjtjg} tj} tj} nº| dkrdtjd}tjtjtjg} tjtjtjg} tj} tj} nt| dkrddtjd}tjtjtjg} tjtjtjg} tj} tj } n.| dkr’|  !tj"tj#g¡|  !tj"tj#g¡| dkrþd| }tj$||d}d| ¡vrþ| ¡dgkrþ| ¡ddd |}| ¡ddd}||| | | dddidœ}tj|||d}tj%}d| ¡vr®| ¡dgkr®| ¡ddd }|rðd!|vrð|d!}| &¡}|j'}|j(}d tj ||d"d#œ}d|d$}ztj|||d%Wn.tyî}zt)|ƒWYd}~n d}~00|D]¸}d|}tj$||d}d| ¡vrô| ¡dgkrô| ¡ddd | ¡ddd | ¡ddd&| ¡ddd'| ¡ddd(d|gddid)œ}tj|||dqô|j*d*kr0d+|vr|d+rd,|vr|d,d-krd.} t+ ,d/|i¡}!| d0krd1} t- ,d/|i¡}!nÐ| d2kr4d3} t. ,d/|i¡}!n²| d4krRd5} t/ ,d/|i¡}!n”| dkrpd6} t0 ,d/|i¡}!nv| dkrŽd7} t0 ,d/|i¡}!nX| dkr¬d8} t0 ,d/|i¡}!n:| dkrÊd9} t0 ,d/|i¡}!n| dkræd:} t0 ,d/|i¡}!|d+}"t1|"ƒdkrt2 3tj4|d+| |!¡t5||| ¡ddd d;S| ¡Sn t6ddS)?NZ captcha_token)ZsecretrÇ)r„rŽrŒrizFailed Captcha Validationi™z0Could not validate captcha, bypassing validationr”r/rÑÚ AuthorizationúBearer z%https://www.wrike.com/api/v4/folders/r¡rRrkÚnewsÚeventZtoolsAndResourcesZcommunitySpotlightZresearchz#https://www.wrike.com/api/v4/tasks/©r„rr‡rZ subTaskIdsFZBacklog)r/rÑÚ customStatusÚ followersÚ responsiblesÚfollowÚdates)r„rŽrrSÚ attachmentZXMLHttpRequest)r¢z X-File-Namer†zX-Requested-Withz /attachments)r„r‡rZcustomStatusIdZ followerIdsZresponsibleIds)r/rÑr§r¨r©rªZ superTasksr«rÕÚ userEmailZsendCopyrþz%SPARC Reported Error/Issue SubmissionrµZfeedbackzSPARC Feedback SubmissionZinterestz!SPARC Service Interest SubmissionÚgeneralz$SPARC Question or Inquiry SubmissionzSPARC Research SubmissionzSPARC News SubmissionzSPARC Event SubmissionzSPARC Tool/Resource SubmissionzSPARC Story Submission)r/rÑÚtask_idrÎzMissing title or descriptionrÐ)7rÚformrorr=Z TURNSTILE_URLZNUXT_TURNSTILE_SECRET_KEYrŽrtrrrir—rOÚ WRIKE_TOKENZDRC_FEEDBACK_FOLDER_IDZCCB_HEAD_WRIKE_IDZDAT_CORE_TECH_LEAD_WRIKE_IDZMAP_CORE_TECH_LEAD_WRIKE_IDZK_CORE_TECH_LEAD_WRIKE_IDZSIM_CORE_TECH_LEAD_WRIKE_IDZMODERATOR_WRIKE_IDZDRC_WRIKE_CUSTOM_STATUS_IDZNEWS_AND_EVENTS_FOLDER_IDZCOMMS_LEAD_1_WRIKE_IDZCOMMS_LEAD_2_WRIKE_IDZCOMMS_LEAD_3_WRIKE_IDZCOMMS_WRIKE_CUSTOM_STATUS_IDZNEWS_TEMPLATE_TASK_IDZEVENT_TEMPLATE_TASK_IDZTOOLS_AND_RESOURCES_FOLDER_IDZ$TOOLS_AND_RESOURCES_TEMPLATE_TASK_IDZCOMMUNITY_SPOTLIGHT_FOLDER_IDZ$COMMUNITY_SPOTLIGHT_TEMPLATE_TASK_IDÚextendZ SUE_WRIKE_IDZ JYL_WRIKE_IDrŠr réÚfilenamerÅÚprintrÙr8r¼r6r:r7r9rër¹rºr»rr)#r°Z captchaReqZ captchaResprör/rÑZnewTaskDescriptionÚhedr„r¨r©r§ZtaskTypeZtemplateTaskIdZtemplateSubTaskIdsZ templateUrlZ templateRespr‡rQr Z new_task_idr¬Z file_dataÚ file_namerÅrZattachment_urlrkZ subTaskIdZsubTaskTemplateUrlZsubTaskTemplateRespZ subTaskDatar9Úbodyr­rWrWrXÚcreate_wrike_task_s@þþ$        þ ù ý ü ý þ ø ý  ,        ý r¸c CsŒtjjtjd}z"|jjjjt |ƒgd¢dd}Wn6t yh}zt dd|›dWYd}~Sd}~00|szt dddS|j sŒt dd dS|j   d ¡s¤t dd dS|j   d ¡d j}|j   d ig¡d }|rÔ|jnd}|j   dig¡d }|rø|jnd}|j   d¡} t| ƒd kr| d } | r0| j d¡ng} |j   d¡} t| ƒd krV| d } | rh| j d¡ng} dd„| | Dƒ} |||| dœS)N)Z access_token)Ú firstnameÚlastnamer´Ú newsletterÚ event_nameF)Z contact_idÚproperties_with_historyZarchivedrÎz2Exception thrown when getting contact properties: rÐz-Failed to retrieve contact data from HubSpot.zContact properties not foundr´z Contact Email property not foundrr¹rRrºr»ú;r¼cSsg|] }|r|‘qSrWrW©rxÚtagrWrWrXr|3r¨z*get_contact_properties..)r´r¹rºÚtags)ÚhubspotZClientÚcreater=ZHUBSPOT_API_TOKENZcrmZcontactsZ basic_apiZ get_by_idrjrrr½rŠrVrëÚsplit)Ú object_idÚclientÚ contact_datarkr´Zfirstname_datar¹Z lastname_datarºZnewsletter_tags_dataZnewsletter_tagsZevents_tags_dataZ events_tagsrÁrWrWrXÚget_contact_propertiess<"(      ürÈc CsØd|›d}ddtjdœ}|||dœ||dœ}zHtj|||d} t| jƒd krpt d |›d | j›d | j›¡|   ¡WSt yÒ} zBt d |›d|›| ¡t dd|›d|›d| ›dWYd} ~ Sd} ~ 00dS)Nz#https://api.emailoctopus.com/lists/z /contactsr…r£)rÖr¢)Z FirstNameZLastName)Ú email_addressr#r®rÁ)rŽrZ200z:Emailoctopus contact did not get added/updated for email: z. Returned a response of z: z4Could not add or update contact with email address: z in emailoctopus list: éôz1Could not add/update contact with email address: z! from emailoctopus list with ID: ú due to the following error: rÐ) r=ZEMAIL_OCTOPUS_API_KEYroÚputrjrÙrrrirïrŽrtr) Zlist_idr´r¹rºrÁr®r„rrCrÇrörWrWrXÚ"add_or_update_emailoctopus_contact<s" þü  rÍz/hubspot_webhookc sæt ¡}t|tƒrhzt |¡}WnFtjyf}z,t d|›¡t ddiƒdfWYd}~Sd}~00|s†t d¡t ddiƒdfSt j   dt›¡t j   d|›¡d |d vsÂd |d vrât d |›¡t dd iƒdfSdtj vsúdtj vr$t dtj ›¡t ddtj ›iƒdfStj  d¡}tj d}z t|ƒ}Wn4tyzt d|›¡t ddiƒdfYS0zÐtt ¡ƒ}||dkrÂt dtt›d|›¡t dhƒdfWStj}d}tj|dd}|›|›|›|›} t tj d¡|  d¡tj¡ ¡} t | ¡ d¡} t  | |¡sJt d¡t ddiƒdfWSWnLt!y˜} z2t d| ›¡t dd| ›iƒdfWYd} ~ Sd} ~ 00|d }|d ‰|d ‰d} ‡‡fdd „}t"j#|d! $¡t d"d#d$œƒd%fS)&Nz.Webhook request body has invalid JSON format: rizInvalid JSON formatrÎz'Webhook request does not contain a bodyzInvalid payloadz"Received Hubspot webhook request: zHubspot webhook request body: ZsubscriptionTyperZobjectIdz5Required keys missing in the following body payload: z Required keys missing in payloadzX-HubSpot-Request-TimestampzX-HubSpot-Signature-V3zKRequired signature header(s) not present in the following request headers: z$Invalid signature timestamp format: z"Invalid signature timestamp formatrNz¥r¨z.execute_webhook..cSsi|] }|d“qS)FrWr¿rWrWrXrÒ¦r¨zUnsupported subscription type: rŒzWebhook processed successfully©r®rµrÕ) r—Z app_contextrÈrtrrrirÍr=ZEMAIL_OCTOPUS_MASTER_LIST_IDr>Úupdater) rÇrör¹rºr´Zemailoctopus_contactZ tags_to_addrÀZtags_to_removeZupdated_contact_tags©rÅZsubscription_typerWrXÚexecute_webhooks2  $       z(hubspot_webhook..execute_webhook)ÚtargetrŒz/Webhook request received and signature verifiedrÓéÌ)%rr˜Ú isinstancerjrŽr·rKrrrirr—Úloggerr‰rrŠrórYÚtimeÚcurrentr„r¯ÚhmacÚnewr=ÚHUBSPOT_CLIENT_SECRETÚencodeÚhashlibÚsha256ÚdigestrÚrÛrêZcompare_digestrtÚ threadingÚThreadr“)r·rkZsignature_headerZtimestamp_headerZsignature_timestampZ current_timer„rcZstringified_bodyZ raw_stringZhashed_signatureZbase64_hashed_signaturerörÇrÖrWrÕrXÚhubspot_webhookQsj &      ý ,ræz/mailchimp_subscribec Csæt ¡}|rÖd|vrÖd|vrÖd|vrÖ|d}|d}|d}tdtjƒ}d|}|d||dœdœ}z6tj|||d }|jd krˆ| ¡WSd | ¡WSWn0t yÈ}zt   d |¡WYd}~n d}~00d didfSt ddddS)NrÉÚ first_nameÚ last_nameÚAnyUserú;https://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/rÑ)ZFNAMEZLNAME)rÉr®Z merge_fields©r„rŽÚauthrÕz(Failed to subscribe user with response: z!Could not subscribe to newsletterrizAn error occured while trying to unsubscribe to the newsletterrÊrÎúMissing email_addressrÐrí)rerÉrìr„r‡rQrörWrWrXÚunsubscribe_to_mailchimpÓs(  ÿý  " rñz&/mailchimp_member_info/c Cs |rtdtjƒ}d|}z4tj||d}|jdkr<| ¡WSd| ¡WSWn6ty‚}zt  d|›|¡WYd}~n d}~00ddid fSt d d d dS) Nrérê)r„rìrÕz)Failed to get member info with response: zFailed to get member info for riz(Could not get member info from MailChimprÊrÎrðrÐ) r$r=rîrorŠrÙrŽrtrrrir)rÉrìr„rQrörWrWrXÚget_mailchimp_member_infoïs þ  ( ròz/get-organ-curies/c CsŒtj d¡}t|ƒ}i}z,tjtj›dtj›|d}t |  ¡ƒ}Wn>t y‚}z&t   d|¡dddœdfWYd}~Sd}~00t|ƒS) Nr:rrzFailed getting Uberon IDsrJÚ BaseExceptionrLrØ)rrÉr"r.rorr=rrrDrŽrórrrir)r:Z requestBodyr?rÇrörWrWrXÚget_available_uberonidss" þ þýrôz/get-related-terms/c Cs°tjjdddtjjdddtjjdddtjdœ}i}z*tjtj›d |›|d }t| ¡ƒ}WnDt y¦}z,t   d |›|¡d d dœdfWYd}~Sd}~00t |ƒS)NÚ directionZOUTGOING)rjÚrelationshipTypez BFO:0000050Úentailrþ)rõrör÷rAz/graph/neighbors/)rÓz*Failed getting related terms with payload rJrórLrØ) rrÉrŠr=rroZSCI_CRUNCH_SCIGRAPH_HOSTrFrŽrórrrir)r'rCr?rÇrörWrWrXÚget_related_termss(üþþýrøz /simulation_ui_file/cCs¤ttt|ƒƒƒ}t |j¡}zd|dd}|d}|dddd}t dd|›d |›¡}t d d|¡}tt t ||ƒ¡ƒWSt yžt d d d Yn0dS)Nr=rZs3urizabi-simulation-fileZdatasetrÍz s3://[^/]*/rRzfiles/z s3://|/.*rhz$no simulation UI file could be foundrÐ) rAr%r,rŽr·r‡ÚreÚsubrrrtr)r2r=Z results_jsonÚitemrrÍrÄZs3_bucket_namerWrWrXÚsimulation_ui_file9s   rüz /pmr_filecCs€t ¡}|rpd|vrpz@t tj›d|d›¡}|jdkrHt |j ¡WS|  ¡WSWq|t dddYq|0n t ddddS)NrÍrrÕrÎz invalid pathrÐz missing path) rr˜rorr=ZPMR_HOSTrÙrÚrÛrÜrŽr)r‡rQrWrWrXÚpmr_fileKs  rýz/start_simulationcCsJt ¡}|r:d|vr:d|dvr:d|dvr:t t|ƒ¡StddddS)NÚsolverr³rÌrÎz)Missing solver name and/or solver versionrÐ)rr˜rŽr¯Údo_start_simulationr©r‡rWrWrXrK[s$rKz/check_simulationcCsRt ¡}|rBd|vrBd|vrBd|dvrBd|dvrBt t|ƒ¡StddddS)NZjob_idrþr³rÌrÎz1Missing solver name, solver version and/or job idrÐ)rr˜rŽr¯Údo_check_simulationrrrWrWrXrLes,rLz/pmr_latest_exposurecCs°t ¡}|r d|vr zptj|dddid}|jdkrxz$| ¡dddd dd }Wnd }Yn0t|d WS| ¡WSWq¬td ddYq¬0n td dddS)NZ workspace_urlÚAcceptz$application/vnd.physiome.pmr2.json.1rrÕÚ collectionÚitemsrZlinksZhrefrRrƒrÎzInvalid workspace URLrÐzMissing workspace URL)rr˜rorŠrÙrŽrr)r‡rQr„rWrWrXÚpmr_latest_exposureos$  ÿ $ ÿrz/onto_term_lookupc CsÂtj d¡}ddi}dtji}t|ƒ}zbtjtj›d|||d}| ¡}|dd}|dd}|d kr||d }|d } nd d i} | WSt y¸} zt   d| ¡WYd} ~ n d} ~ 00t dƒS)NrHrr…rArB)rrÓrŽrpÚtotalr rÚ_sourceÚlabelz not foundz.An error occured while fetching from SciCrunchrÊ) rrÉrŠr=rr/roZSCI_CRUNCH_INTERLEX_HOSTrŽrtrrrir) rHrrÓr'rÇr=rprr?rerörWrWrXÚfind_by_onto_term‰s& ÿÿ   "r z/search-readme/c Csxd|}ddtji}ztj||d}| ¡WStjjyr}z(t |¡t |ƒddœdfWYd}~Sd}~00dS)Nz2https://dash.readme.com/api/v1/docs/search?search=r¢zBasic r¦z9Readme is not currently reachable, please try again laterrIrØ) r=ZREADME_API_KEYrorrŽrprqrrrirj)r'r„rrÇrurWrWrXÚ search_readme©sþ  þýr z/metricscCstSrS)r˜rWrWrWrXÚmetrics»sr z/event_updatedcCsrtj d¡}|tjkr*tdd|›dnDt ¡}|rbz t|ƒWStdd|›dYqn0n tddddS)NZevent_updated_secret_keyr zInvalid secret key: rÐrÎzInvalid event data: zMissing event data)rrrŠr=ZCTF_CDA_ACCESS_TOKENrr˜r)Z secret_keyr¥rWrWrXÚ event_updatedÀs   r z/all_dataset_idscCs"tƒ}dd„|Dƒ}d}| |¡S)NcSsg|] }t|ƒ‘qSrW)rj)rxÚelementrWrWrXr|Ór¨z#all_dataset_ids..z, )r Újoin)ÚlistZ string_listÚ delimiterrWrWrXÚall_dataset_idsÐsr)rDr)F(ÚatexitrÚZapp.metrics.pennsieverZapp.metrics.contentfulrrrZ!scripts.update_contentful_entriesrrZapp.metrics.algoliarr r r Zapp.metrics.gar r Zscripts.monthly_statsrZ"scripts.update_featured_dataset_idrrZapp.osparc.servicesrrZboto3rárÝrÛrÂZhubspot.crm.contactsrrŽrrrùroräÚ urllib.parserZ!apscheduler.schedulers.backgroundrZapscheduler.triggers.combiningrZapscheduler.triggers.daterZapscheduler.triggers.intervalrZbotocore.exceptionsrrrZflaskrrrrZ flask_corsrZflask_marshmallowr Z pennsiever!Zpennsieve.baser"rsZPILr#Ú requests.authr$Z flask_cachingr%Zapp.scicrunch_requestsr&r'r(r)r*r+r,r-r.r/r0r1r2r3r4Zscripts.email_senderr5r6r7r8r9r:r;Z xml.etreer<Ú app.configr=Z app.dbtabler>r?r@Zapp.scicrunch_process_resultsrArBrCrDrErFrGZapp.serializerrHZ app.utilitiesrIrJZapp.osparc.osparcrKrÿrLrZapp.biolucida_process_resultsrrMrˆÚ basicConfigrcr—Z LOG_LEVELÚupperÚ log_levelrÚÚsetLevelÚgetattrÚWARNINGZ DEPLOY_ENVrOÚcacheZmar¹rnrÆZSPARC_PORTAL_AWS_KEYZSPARC_PORTAL_AWS_SECRETrPr‚Z DATABASE_URLr›ÚAttributeErrorržr¦ÚobjectrQZ errorhandlerrlZbefore_first_requestrvr‘r›r¬r«rªr’r‰r“Zmonthly_stats_email_schedulerÚmsZmonthly_stats_required_checkZadd_jobrWrr–r˜r—r™ršrœrržZfeatured_dataset_id_triggerr­ÚregisterZrouter°r½rÈZDEFAULT_S3_BUCKET_NAMErËrßrùrrr rrrrr$r(r*r,r.r0r4r6r7r;r@r%rGrNrPrRr]rrfrgrhrmrorrrtÚcachedrwrr€r…r‰rŠrr‘rƒr™ršrœrrŸr r¸rÈrÍrærïrñròrôrørürýrr r r r rrWrWrWrXÚs                 D    $     ü         ÿ         >  '           ,   0                     7&]#