a «…gk'ã @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@m?ZAddlBmCZCddlDmEZFddlGmHZHddlImJZJddlKmLZLddlMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ddl]m^Z^m_Z_m`Z`maZambZbmcZcddl&mdZdddlemfZfddlgmhZhdd limjZjmkZkmlZldd!lmmnZnmoZompZpmqZqmrZrmsZsmtZtdd"lumvZvdd#lwmxZxmyZydd$lzm{Z|dd%lzm}Z~dd&lmnZ€mZ‚e# ƒ¡e6e„ƒZ…ehj† ‡¡Zˆe…j‰ Še‹e#eˆe#jŒƒ¡ehje…jŽd'<eLe…d(d)d*œd+Ze;e…ƒe=e…ƒZe^ƒZ‘da’ej“d,ehj”ehj•d-d.Z–edƒZ—zejehj˜ƒZ™Wnešy†dZ™Yn0zekehj˜ƒZ›Wnešy®dZ›Yn0zelehj˜ƒZœWnešyÖdZœYn0Gd/d0„d0eƒZže… Ÿd1¡d2d3„ƒZ e…j¡d4d5„ƒZ¢e…j¡d6d7„ƒZ£e*ƒZ¤e*ƒZ¥e*ƒZ¦e*ƒZ§e*ƒZ¨e§j©sNe# ªd8¡e§ «¡ehjd9kr’e*ƒZ¬eƒZ­e­ ®¡e¬ «¡e¬j¯e­j®d:d;d;dehjd?krÖehj°d@krÖe¨j©sÄe# ªdA¡e¨ «¡e¨j¯e d:dBdCdDiZ±e…j¡dEdF„ƒZ²iZ³eƒZ´e ƒZµeƒZ¶e…j¡dGdH„ƒZ·eƒZ¸e…j¡dIdJ„ƒZ¹e¦j¯e¹dKdLdMe¤j¯e²dKdLdMe¥j¯e·dKdNdOe,e.ƒe0dLdPgƒZºe§ ¯dQdR„eº¡dSdT„Z»e ¼e»¡e… ½dU¡dVdW„ƒZ¾e…j½dXdYgdZd[d\„ƒZ¿d]d^„ZÀe… ½d_¡d`ehjÁfdadb„ƒZÂe… ½dc¡ddde„ƒZÃe… ½df¡ehjÁfdgdh„ƒZÄe… ½di¡ehjÁfdjdk„ƒZÅdldm„ZÆe… ½dn¡dodp„ƒZÇdqdr„ZÈe… ½ds¡ehjÁfdtdu„ƒZÉe… ½dv¡dwdx„ƒZÊe… ½dy¡e… ½dz¡d{d|„ƒƒZËe… ½d}¡d~d„ƒZÌe… ½d€¡dd‚„ƒZÍe… ½dƒ¡e… ½d„¡d…d†„ƒƒZÎe… ½d‡¡e… ½dˆ¡d‰dŠ„ƒƒZÏe… ½d‹¡e… ½dŒ¡ddŽ„ƒƒZÐe… ½d¡dd‘„ƒZÑe… ½d’¡d“d”„ƒZÒe… ½d•¡d–d—„ƒZÓe… ½d˜¡d™dš„ƒZÔe… ½d›¡ehjÁfdœd„ƒZÕe… ½dž¡dŸd „ƒZÖd¡d¢„Z×e…j½d£d¤d¥dd¦œd§e… ½d¨¡d;d©dª„ƒƒZØe…j½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âe…j½dÈdÉgdZdÊdË„ƒZãe…j½dÌdÉgdZdÍd΄ƒZäe…j½dÏdÉgdZejåd)dÐdÑdÒ„ƒƒZæe…j½dÓdÉgdZdÔdÕ„ƒZçe…j½dÖdÉgdZd×dØ„ƒZèe…j½dÙdÉgdZdÚdÛ„ƒZée…j½dÜdÉgdZdÝdÞ„ƒZêe…j½dßdÉgdZdàdᄃZëe…j½dâdÉgdZdÚPENNSIEVE_API_TOKENÚPENNSIEVE_API_SECRETÚPENNSIEVE_API_HOSTÚpsÚrequestsÚ exceptionsÚ HTTPErrorÚloggingrjÚPSUnauthorizedExceptionÚ Exception©ÚerrrXrXrYÚconnect_to_pennsieve‰s ü    r|c CsTzttjtjtjddaWn4tyN}zt d|›¡WYd}~n d}~00dS)N)Úapi_keyrnZapi_hostZ api2_hostz'Error connecting to pennsieve 2 agent: ) r"r>rprqrrÚps2ryrwrjrzrXrXrYÚconnect_to_pennsieve2srz6Starting 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-typerSÚdataÚ file_viewersz!Could not retreive oSPARC viewersz1Starting scheduler for oSPARC viewers acquisition)rwÚinfortÚgetr>ÚOSPARC_API_HOSTÚokÚheadersÚjsonÚbuild_filetypes_tableÚ osparc_dataryrjÚviewers_schedulerÚrunningÚstart)ÚreqZviewersÚtablerlrXrXrYÚ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) rwr’Úgoogle_analyticsr Ú usage_metricsÚalgoliarÚ contentfulrrÚmetrics_schedulerr›rœ)Z ga_responseZalgolia_responseZ cf_responseZ ps_responserXrXrYÚ get_metricsÞs  r¥c Csnt d¡z.tjtj›dd}| ¡}t |d¡Wn0t yh}zt  d|¡WYd}~n d}~00dS)NzFetching oSPARC servicesz /servicesrŒrz%Request to get oSPARC services failed) rwr’rtr“r>r”r—Úosparc_servicesZ set_servicesryrj)rZ services_resprlrXrXrYÚ get_services÷s r§Úintervalé)ÚfuncÚtriggerÚdaysé)rªr«Úhours)r®cCsttƒSrT)rÚfeaturedDatasetIdSelectorTablerXrXrXrYÚ ó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) rwr’ršr›Úshutdownr¤Ú)update_contentful_event_entries_schedulerÚfeatured_dataset_id_schedulerÚservices_schedulerrXrXrXrYÚshutdown_schedulerss     r¶z/healthcCst ddi¡S)NÚstatusZhealthy)r—ÚdumpsrXrXrXrYÚhealth$sr¹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—ÚloadsrrrIÚloadÚ email_senderZ send_emailÚsendgrid_emailr>Ú SES_SENDERr7Ú substituter¸)rZcontact_requestr¼r½r¾rXrXrYÚcontact)s  rÆcCstjd||d|dœ|d}|S)NÚ get_objectÚ requester)ÚBucketÚKeyÚ RequestPayerZResponseContentType)ZParamsZ ExpiresIn)rQZgenerate_presigned_url)Ú s3BucketNameÚkeyÚ content_typeÚ expirationÚresponserXrXrYÚcreate_s3_presigned_url7s  ýrÑz /downloadicCs6tj d¡}tj d|¡}tj dd¡}t||||ƒS)NrÍrÌZ contentTypezapplication/octet-stream)rÚargsr“rÑ)rÏÚ bucket_namerÍrÌrÎrXrXrYÚcreate_presigned_urlBs 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_HOSTrtr“Zraise_for_statusÚ status_coder–Úbase64Ú b64encodeÚcontentruÚConnectionErrorZTimeoutZRequestExceptionrk)Ú query_argsrrÐrlrXrXrYÚthumbnail_from_neurolucida_fileKs"   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Ú NoSuchKeyriúCould not find file: 'ú'úUnknown error for file: 'ÚBodyzUTF-8z z#Could not find thumbnail in file: 'rSrŠZRGBZrowsÚcols)rrÒrr“rQrÇrrÐÚreadÚdecodeÚlenÚfindr=Ú fromstringÚattribÚtextÚbytesÚfromhexr$Ú frombytesÚintrJ)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_formrXrXrYÚextract_thumbnail_from_xml_filebsZ   ü  6      "rz/exists/cCsftj}| d|¡}ztj||dd}Wnty@ddiYS0| dd¡}|dkr^ddiSddiS) NrÌrÈ©rÉrÊrËÚexistsÚfalseÚ ContentLengthrÚtrue)rrÒr“rQÚ head_objectr)rÖrÓrçrÌÚ head_responseÚcontent_lengthrXrXrYÚ url_exists¡s ý   r cCs0| dd¡}|d| d¡…}t |¡}| ¡S)Nzhttps://api.pennsieve.io/z"https://api.pennsieve.io/discover/ú/)ÚreplaceÚrfindrtr“r—)ÚuriÚrrXrXrYÚ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}rizFailed to retrieve uri rÙ)rrÒr“rryrwrjr)rZ json_responseÚ file_inforÿrXrXrYÚget_discover_pathÁs  "rc 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ÈrrizFile too big to download: rÙrêrëZ404riú.Provided path was not found on the s3 resourceZ403é“úEThere is a permission issue when accessing the file at specified pathÚMessage)rÞÚOK)rir)rr) rQrr“r>ZDIRECT_DOWNLOAD_LIMITrÚbotocorerurrÐ)rÖrÓr r r{rXrXrYÚ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ÌrrirrrÙrÞrrÈrZ encodeBase64rð) rrÒr“rrKrrQrÇròrãrä) rÖrÓrçrÌZs3_pathrÐZs3_path_modifiedZ response2Ú encode_base64rýrXrXrYÚ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:rSr ú/_search?api_key=©r—rj) r r'rtÚpostr>ÚSCI_CRUNCH_HOSTÚKNOWLEDGEBASE_KEYr—rurvrwrjr¸)Zdoi1Zdoi2ÚdoirrÐr{rXrXrYÚsci_doisþ  r$z /pubmed/z/pubmed//c Cs`zt d|›d¡}|jWStjjyZ}z$t |¡t d|i¡WYd}~Sd}~00dS)Nz https://pubmed.ncbi.nlm.nih.gov/r rj) rtr“rørurvrwrjr—r¸)Úid_rÐr{rXrXrYÚpubmeds  r&z/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Úfromrrrj)rrÒÚgetlistr“r.rtr r>r!r"rBr—rurvrwrjr¸)Úfieldsr(r)Zfrom_rrÐr{rXrXrYÚ sci_organ+s    þ r-z/dataset_info/using_doicCs<tj d¡}tj d¡}t|ƒ}|dur4tt|ƒƒSt|ƒS)Nr#Z raw_response)rrÒr“r'rFÚdataset_search)r#ÚrawÚqueryrXrXrYÚget_dataset_info_doi>s    r1z!/dataset_info/using_multiple_doisz"/dataset_info/using_multiple_dois/cCs tj d¡}t|ƒ}tt|ƒƒS)NÚdois)rrÒr+r1rBr.)r2r0rXrXrYÚget_dataset_info_doisIs r3z./multiple_dataset_info/using_multiple_mimetypez//multiple_dataset_info/using_multiple_mimetype/cCs tj d¡}t|ƒ}tt|ƒƒS)NÚq)rrÒr+r5rBr.)r4r0rXrXrYÚget_file_info_from_mimetypeQs r5z(/dataset_info/using_multiple_discoverIdsz)/dataset_info/using_multiple_discoverIds/cCs tj d¡}t|ƒ}tt|ƒƒS)NÚ discoverIds)rrÒr+r2rBr.)r6r0rXrXrYÚget_dataset_info_discoverIds[s r7z/dataset_info/using_titlecCs tj d¡}t|ƒ}tt|ƒƒS)NÚtitle)rrÒr“r+rFr.)r8r0rXrXrYÚget_dataset_info_titleds r9z%/dataset_info/using_object_identifiercCs tj d¡}t|ƒ}tt|ƒƒS©NÚ identifier)rrÒr“r,rFr.©r;r0rXrXrYÚ"get_dataset_info_object_identifierls r=z/dataset_info/anatomycCs6tj dd¡}|dkr"tdddSt|ƒ}tt|ƒƒS)Nr;éÿÿÿÿriz Identifier for API call not set.rÙ)rrÒr“rr3rHr.r<rXrXrYÚget_dataset_info_anatomyts  r?z(/dataset_info/using_pennsieve_identifiercCs tj d¡}t|ƒ}tt|ƒƒSr:)rrÒr“r-rFr.r<rXrXrYÚ%get_dataset_info_pennsieve_identifiers r@z/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ÌrrirrÈrrêrërìrírîrïrðz./{*}sparcdata/{*}subjectÚsubjectrS)ZageZsexÚspeciesZ subjectidz./{*}sparcdata/{*}atlasZatlasZorgan)rrÒrr“rrQrÇrrÐròr=rörõr÷) rÓrçrÌrArÐrÿrýrZsubject_elementr’Z atlas_elementrXrXrYÚget_segmentation_info_from_file‡s<      ý  6         rDz/current_doi_listcCsBtƒ}tt|ƒƒ}g}|ddD]}| |dd¡q"d|iS)Nr#ÚbucketsrÍr(Úresults)r*rDr.Úappend)r0rFZ doi_resultsÚresultrXrXrYÚ get_all_doi´s  rIc Cstz0|}dtji}tjtj›d||d}| ¡WStjjyn}z"t  |¡t d|iƒWYd}~Sd}~00dS)Nr}ú/_search)r—rÜrj) r>r"rtr r!r—rurvrwrjr)r0ÚpayloadrÜrÐr{rXrXrYr.¿sÿÿ  r.z/search/rSé )r0Ú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) NrMr0rœz /_search?q=z&size=z&from=z &api_key=rj)rrÒr“rtr>r!r"rBr—rurvrwrjr¸)r0rMrœrÐr{rXrXrYÚ kb_searchÑs   * rOz/filter-search/r0z/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œrrzr!r"rBr—rurvrwrjrrkrS) r0ÚtermsZfacetsr)rœrrÐrFr{rXrXrYÚ filter_searchås*    þ *ÿÿ rVz/get-facets/c 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 aggregationsrUr'rrrRrSrTráz$Could not search SciCrunch for path rE) r)rtr r>r!r"r—rGrSrryrwrj) Útype_Ztype_maprrFrÖrÐZ json_resultrÿrUrHrXrXrYÚ get_facetss.  þÿÿ *rXcCs&d|vr"t | d¡¡}|j|d<dS)NZreadmeZmarkdown)rtr“rø)ÚrespZmark_reqrXrXrYÚinject_markdownsrZc 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ÈrZTRUEzXRequired file template.json was not found under /files folder, trying under /packages...z{}/packages/template.jsonrðÚuuidr¼rÚ)r\r¼rÚZstudy)r“rÚnetlocrQrÇÚformatrr>ÚSPARC_API_DEBUGGINGrwÚwarningrjròr—rÀÚ ValueError) rYr%rZ parsed_uriÚbucketrÐÚ debuggingrlÚtemplateZ template_jsonrXrXrYÚinject_template_data$sL  ý   ÿý     ýrecCsFi}|D]8}|d ¡}|d=| |d¡s2g||<|| |¡q|S)NÚ file_typeF)Úlowerr“rG)Zosparc_viewersržZviewerZfiletyperXrXrYr˜Ts  r˜z/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 riúResource not foundrÙ©rÚmethodrtr“r^r>ÚDISCOVER_API_HOSTr•r—rZrerryrwrjr)r%rÚ json_datarÿrXrXrYÚ sim_dataset^s (roz&/sim/dataset//versions/c Csštjdkr–zBt d tj||¡¡}|jrJ| ¡}t |ƒt |ƒt |ƒWSWn<t yˆ}z$t  d|›d|›|¡WYd}~n d}~00tdddSdS)Nrhz{}/datasets/{}/versions/{}riz version rirjrÙrk)r%Zversion_rrnrÿrXrXrYÚsim_dataset_versionsls .rpz/get_osparc_datacCsttƒSrT)rr™rXrXrXrYÚget_osparc_data|srqz /sim/servicecCsTtjdkrPtj d¡}tjjddtd}tjjddtd}t |||¡}t|ƒSdS)NrhÚsearchrMrÛ)ÚdefaultÚtypeÚskipr)rrlrÒr“rür¦Zsearch_servicesr)rrrMrurFrXrXrYÚ osparc_searchs   rvz /sim/filecCs tjdkrtj}td|iƒSdS)Nrhr‘)rrlr¦Zfile_extensionsr)Ú extensionsrXrXrYÚosparc_extensions‹s  ÿrxz/project/rhcCs4t|ƒ}t|dƒdkr$t|dƒStddddS)NÚhitsrrirjrÙ)r rôrr)Z project_idÚdatasetsrXrXrYÚdatasets_by_project_id”s r{z"/get_featured_datasets_identifierscCs dtƒiS)NÚ identifiers)rrXrXrXrYÚ!get_featured_datasets_identifiersžsr}z/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_idr>é z{}/datasets?ids={}rzzCould not get featured dataset riz,An error occured while fetching the resourcerÙ) rr¯rtr“r^r>rmr—ryrwrjr)r~rÐrÿrXrXrYÚget_featured_dataset¢s  (r€z/reva/subject-idsc Csªz^t dtj›¡}|d}g}|D]&}|dddkr$| |dd¡q$td|dœƒd fWSty¤}z.t d |›¡td |d œƒd fWYd}~Sd}~00dS) Nú /packages/ÚchildrenråÚ packageTypeÚ Collectionr¼Úsuccess)r·ÚidsrÞz+Error while getting REVA subject id files: ©r·r¾éô) r~r“r>Ú,REVA_3D_TRACING_PRIMARY_FOLDER_COLLECTION_IDrGrryrwrj)Úprimary_folderÚprimary_childrenZ subject_idsrrlrXrXrYÚgetRevaSubjectIds³srŒz /reva/tracing-files/c sød‰d‰d‰zœt dtj›¡}|d}t‡fdd„|Dƒdƒ}|durtt dˆ›¡td d ˆ›d œƒd fWSt d|d d›¡}|d}t‡fdd„|Dƒdƒ}|durèt dˆ›dˆ›¡td ˆ›dˆ›d œƒd fWSt d|d d›¡}|d}t‡fdd„|Dƒdƒ} | dur^t dˆ›dˆ›¡td ˆ›dˆ›d œƒd fWSt d| d d›¡} | d} t‡fdd„| Dƒdƒ} | durÔt dˆ›dˆ›¡td ˆ›dˆ›d œƒd fWSt d| d d›¡} | d}g}|D]š}t d|d d›¡}|d}|D]n}|d d}t d|›d¡}|dd d}t d|›d|›¡d}| t |d dƒt |ƒdœ¡q$qütd|dœƒdfWSt yò}z.t d|›¡td|d œƒd fWYd}~Sd}~00dS)!NzCoordinates-DataZInSituz Vagus-nerverr‚c3s"|]}|ddˆkr|VqdS©rår¼NrX©Ú.0r©Ú subject_idrXrYÚ Êr±z&getRevaTracingFiles..z/REVA tracing folder not found with subject id: ÚERRORz"Folder not found with subject id: r‡rirår[c3s"|]}|ddˆkr|VqdSrrXrŽ)Úcoordinates_folder_namerXrYr’Ðr±zREVA tracing folder z not found for subject: ú folder not found for subject: c3s"|]}|ddˆkr|VqdSrrXrŽ)Úin_situ_folder_namerXrYr’Ör±c3s"|]}|ddˆkr|VqdSrrXrŽ)Úvagus_nerve_folder_namerXrYr’Ür±ú/viewrú/files/rr¼)r¼Ús3Urlr…©r·rrÞz'Error while getting REVA tracing files z#Error while getting tracing files: rˆ) r~r“r>r‰ÚnextrwrjrrGrkry)r‘rŠr‹Ú subject_childÚsubject_folderÚsubject_childrenZcoordinates_childZcoordinates_folderZcoordinates_childrenZ in_situ_childZin_situ_folderZin_situ_childrenZvagus_nerve_childZvagus_nerve_folderZvagus_nerve_childrenZvagus_tracing_filesZvagus_region_childZvagus_region_folderZvagus_region_childrenZvagus_file_childÚfile_package_idZ vagus_fileZ vagus_file_idZvagus_file_presigned_urlrlrX)r”r–r‘r—rYÚgetRevaTracingFilesÁsX   (r¡z!/reva/micro-ct-files/c sˆ›d‰z¾t dtj›¡}|d}t‡fdd„|Dƒdƒ}|durrt dˆ›¡tddˆ›d œƒd fWSt d|d d ›¡}|d}t‡fd d„|Dƒdƒ}|duræt dˆ›dˆ›¡tdˆ›dˆ›d œƒd fWSt d|d d ›¡}|d}g} |D]¨} | d d } t d| ›d¡} | dd d } t d| ›d| ›¡d}| d d}| d}| d d}| dd d}|  t |ƒt |ƒt |ƒt |ƒt |ƒdœ¡qtd| dœƒdfWSt y}z.t d|›¡td|d œƒdfWYd}~Sd}~00dS)Nz-MicroCTVisualizationrr‚c3s"|]}|ddˆkr|VqdSrrXrŽrrXrYr’ùr±z&getRevaMicroCtFiles..z/REVA microCT folder not found with subject id: r“z*MicroCT folder not found with subject id: r‡rirår[c3s"|]}|ddˆkr|VqdSrrXrŽ)Ú"micro_ct_visualization_folder_namerXrYr’ÿr±z REVA microCT r•r˜rr™rr¼ZstoragerƒZfileType)r¼ršrtrƒr)r…r›rÞz'Error while getting REVA microCT files z#Error while getting microCT files: rˆ) r~r“r>Z*REVA_MICRO_CT_PRIMARY_FOLDER_COLLECTION_IDrœrwrjrrGrkry)r‘rŠr‹rržrŸZmicro_ct_childZmicro_ct_visualization_folderZmicro_ct_childrenZmicro_ct_filesZ micro_childr Zmicro_child_fileZmicro_child_file_idZmicro_file_presigned_urlÚ file_nameÚ file_sizeZ package_typerfrlrX)r¢r‘rYÚgetRevaMicroCtFilesòs>    .r¥z/get_owner_email/csPtjj}tjj |¡}‡fdd„|Dƒ}|s:tdddntd|djiƒSdS)Ncsg|]}|jˆkr|‘qSrX)Zint_id)rÚx©Úowner_idrXrYÚ r±z#get_owner_email..rizOwner not foundrÙr½r)rsZ_apiZ _organizationZ organizationsZ get_membersrrr½)r¨ZorgÚmembersÚresrXr§rYÚget_owner_emails r¬z!/get_body_scaffold_info/cCs:t|ƒ}|r(t|ƒ}tt|ƒƒ}|r(|Stdd|›dS)NrizWhole body info not found for rÙ)r4r-rCr.r)rCr[r0rHrXrXrYÚ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]rh©r–s¼eyJzdGF0dXMiOiJBZG1pbiB1c2VyIGF1dGhlbnRpY2F0aW9uIHJlcXVpcmVkIHRvIHZpZXcvZWRpdCB1c2VyIGluZm8uIFlvdSBtYXkgbmVlZCB0byBsb2cgb3V0IGFuZCBsb2cgYmFjayBpbiB0byByZXZlcmlmeSB5b3VyIGNyZWRlbnRpYWxzLiJ9rSTz Could not get the thumbnail for riz-An error occured while fetching the thumbnail)rRÚbiolucida_lockr]Úauthenticate_biolucidar>ÚBIOLUCIDA_ENDPOINTr^rtrrãrärårZÚthumbnail_by_image_idryrwrjr)Úimage_idZrecursive_callÚblrr–rÐZencoded_contentrÿrXrXrYr²/s($ÿ ÿ( (r²z/image/c Csltjd |¡}zt d|¡}t| ¡ƒWSty`}zt  d|›|¡WYd}~n d}~00t ddƒS)Nz/image/info/{0}rhzCould not get image info for riz/An error occured while getting the image's info) r>r±r^rtrÚprocess_biolucida_resultr—ryrwrjr)r³rrÐrÿrXrXrYÚimage_info_by_image_idOs (r¶z/image_search/c Csjtjd |¡}zt d|¡}| ¡WSty\}zt d|›|¡WYd}~n d}~00ddidfS)Nz%/imagemap/search_dataset/discover/{0}rhz$Could not search images for dataset rjz3An error occured while searching images for datasetri) r>r±r^rtrr—ryrwrj)Z dataset_idrrÐrÿrXrXrYÚimage_search_by_dataset_idZs  (r·z/image_xmp_info/cCsvtjd |¡}zt d|¡}Wn"tjjyBtdddYS0| ¡}|ddkrdt |dƒStdd |›dS) Nz/image/xmpmetadata/{0}rhr×ú)Unable to make a connection to Biolucida.rÙr·r…rzXMP info not found for ) r>r±r^rtrrurærr—Úprocess_biolucida_results©r³rrHrÐrXrXrYÚimage_xmp_infoes  r»z/image_blv_link/cCsztjd |¡}zt d|¡}Wn"tjjyBtdddYS0| ¡}|ddkrht d|diƒStdd |›dS) Nz/image/blv_link/{0}rhr×r¸rÙr·r…ÚlinkzBLV link not found for ) r>r±r^rtrrurærr—rrºrXrXrYÚimage_blv_linkts r½cCsdtƒ}tjd}tjtjddœ}g}i}tjd||||d}|jtjj kr`|  ¡}|  |d¡dS)Nz /authenticaterS)ÚusernameÚpasswordr]rº)r–rrr]) rRr>r±ZBIOLUCIDA_USERNAMEZBIOLUCIDA_PASSWORDrtrrâZcodesr•r—rZ)r´rrKrr–rÐrårXrXrYr°ƒs þr°cCshd}tjdrd}|rXt ¡}|rJd|vrJ|d}| ||¡}td|iƒStdddn td d ddS) NTÚTESTINGFÚstater\r×zState not specifiedrÙriúDatabase not available)ÚapprPrÚget_jsonZ pushStaterr)ržZcommitrnrÁr\rXrXrYÚget_share_link”s    rÅcCs^|rNt ¡}|r@d|vr@|d}| |¡}|r@td| |¡iƒStdddn tddddS)Nr\rÁr×z#Key missing or did not find a matchrÙrirÂ)rrÄZ pullStaterr)ržrnr\rÁrXrXrYÚget_saved_state¤s  rÆz/map/getshareidcCsttƒSrT)rÅÚmaptablerXrXrXrYÚget_map_share_link²srÈz /map/getstatecCsttƒSrT)rÆrÇrXrXrXrYÚ get_map_state¸srÉz/scaffold/getshareidcCsttƒSrT)rÅÚ scaffoldtablerXrXrXrYÚget_scaffold_share_link¾srËz/scaffold/getstatecCsttƒSrT)rÆrÊrXrXrXrYÚget_scaffold_stateÄsrÌú/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Ð)rr—r…rjzFailed Captcha Validationi™z0Could not validate captcha, bypassing validationrÀr8rÚÚ AuthorizationúBearer z%https://www.wrike.com/api/v4/folders/rÍrSrtÚnewsÚeventZtoolsAndResourcesZcommunitySpotlightZresearchz#https://www.wrike.com/api/v4/tasks/©rr–rrZ subTaskIdsFZBacklog)r8rÚÚ customStatusÚ followersÚ responsiblesÚfollowÚdates)rr—r–r[Ú attachmentZXMLHttpRequest)rÎz X-File-NamerzX-Requested-Withz /attachments)rrr–ZcustomStatusIdZ followerIdsZresponsibleIds)r8rÚrÓrÔrÕrÖZ superTasksr×rÞÚ userEmailZsendCopyrz%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)r8rÚÚtask_idr×zMissing title or descriptionrÙ)7rÚformrtr r>Z TURNSTILE_URLZNUXT_TURNSTILE_SECRET_KEYr—ryrwrjrÃrPÚ 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“rròÚfilenamerÎÚprintrâr9rÅr7r;r8r:rôrÂrÃrÄrr)#rÜZ captchaReqZ captchaResprÿr8rÚZnewTaskDescriptionÚhedrrÔrÕrÓZtaskTypeZtemplateTaskIdZtemplateSubTaskIdsZ templateUrlZ templateResprrYrZ new_task_idrØZ file_datar£rÎr–Zattachment_urlrlZ subTaskIdZsubTaskTemplateUrlZsubTaskTemplateRespZ subTaskDatarBÚbodyrÙrXrXrYÚ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ärSråræú;rçcSsg|] }|r|‘qSrXrX©rÚtagrXrXrYr©r±z*get_contact_properties..)r½räråÚtags)ÚhubspotZClientÚcreater>ZHUBSPOT_API_TOKENZcrmZcontactsZ basic_apiZ get_by_idrkrrrèr“rWrôÚsplit)Ú object_idÚclientÚ contact_datarlr½Zfirstname_dataräZ lastname_dataråZnewsletter_tags_dataZnewsletter_tagsZevents_tags_dataZ events_tagsrìrXrXrYÚget_contact_properties€s<"(      ü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—r–Z200z: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: rˆz1Could not add/update contact with email address: z! from emailoctopus list with ID: ú due to the following error: rÙ) r>ZEMAIL_OCTOPUS_API_KEYrtÚputrkrârwrjrør—ryr) Zlist_idr½rärårìr·rr–rKrÐrÿrXrXrYÚ"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: rjzInvalid 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 formatrOzr±z.execute_webhook..cSsi|] }|d“qS)FrXrêrXrXrYrür±zUnsupported subscription type: r…zWebhook processed successfullyr‡rÞ) rÃZ app_contextróryrwrjr÷r>ZEMAIL_OCTOPUS_MASTER_LIST_IDrGÚupdater) ròrÿrärår½Zemailoctopus_contactZ tags_to_addrëZtags_to_removeZupdated_contact_tags©rðZsubscription_typerXrYÚexecute_webhookús2  $       z(hubspot_webhook..execute_webhook)Útargetr…z/Webhook request received and signature verifiedr‡éÌ)%rrÄÚ isinstancerkr—rÀrSrwrjrrÃÚloggerr’r–r“rüraÚtimeÚcurrentrr¸ÚhmacÚnewr>ÚHUBSPOT_CLIENT_SECRETÚencodeÚhashlibÚsha256ÚdigestrãräróZcompare_digestryÚ threadingÚThreadrœ)rârlZsignature_headerZtimestamp_headerZsignature_timestampZ current_timerrlZstringified_bodyZ raw_stringZhashed_signatureZbase64_hashed_signaturerÿròrÿrXrþrYÚhubspot_webhook»sj &      ý ,rz/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©rr—ÚauthrÞz(Failed to subscribe user with response: z!Could not subscribe to newsletterrjzÚMAILCHIMP_API_KEYrtrörâr—ryrwrjr) rnrôrrrrrrYrÿrXrXrYÚsubscribe_to_mailchimps4 þýý  " rz/mailchimp_unsubscribec Cs¼t ¡}|r¬d|vr¬|d}tdtjƒ}d|}ddi}z6tj|||d}|jdkr^| ¡WSd| ¡WSWn0t yž}zt   d |¡WYd}~n d}~00d d id fSt d dddS)Nrôrrr·Z unsubscribedrrÞz*Failed to unsubscribe user with response: z#Could not unsubscribe to newsletterrjz>An error occured while trying to unsubscribe to the newsletterrˆr×úMissing email_addressrÙr)rnrôrrrrYrÿrXrXrYÚunsubscribe_to_mailchimp=s(  ÿý  " rz&/mailchimp_member_info/c Cs |rtdtjƒ}d|}z4tj||d}|jdkr<| ¡WSd| ¡WSWn6ty‚}zt  d|›|¡WYd}~n d}~00ddid fSt d d d dS) Nrr)rrrÞz)Failed to get member info with response: zFailed to get member info for rjz(Could not get member info from MailChimprˆr×rrÙ) r%r>rrtr“râr—ryrwrjr)rôrrrYrÿrXrXrYÚget_mailchimp_member_infoYs þ  ( rz/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) NrCrrzFailed getting Uberon IDsrRÚ BaseExceptionrTrá)rrÒr+r/rtr r>r!r"rEr—rrwrjr)rCZ requestBodyrHrÐrÿrXrXrYÚget_available_uberonidsqs" þ þýrz/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)rsÚrelationshipTypez BFO:0000050Úentailr)rrr r}z/graph/neighbors/)rÜz*Failed getting related terms with payload rRrrTrá) rrÒr“r>r"rtZSCI_CRUNCH_SCIGRAPH_HOSTrGr—rrwrjr)r0rKrHrÐrÿrXrXrYÚget_related_terms‰s(üþþý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)NrFrZs3urizabi-simulation-fileZdatasetrÖz s3://[^/]*/rSzfiles/z s3://|/.*riz$no simulation UI file could be foundrÙ) rBr.r-r—rÀrÚreÚsubrrryr)r;rFZ results_jsonÚitemrrÖrÍZs3_bucket_namerXrXrYÚsimulation_ui_file£s   r%z /pmr_filecCs€t ¡}|rpd|vrpz@t tj›d|d›¡}|jdkrHt |j ¡WS|  ¡WSWq|t dddYq|0n t ddddS)NrÖr rÞr×z invalid pathrÙz missing path) rrÄrtr r>ZPMR_HOSTrârãrärår—r)rrYrXrXrYÚpmr_fileµs  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©rrXrXrYrLÅs$rLz/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_simulationrr)rXrXrYrMÏs,rMz/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.1r®rÞÚ collectionÚitemsrZlinksZhrefrSrŒr×zInvalid workspace URLrÙzMissing workspace URL)rrÄrtr“râr—rr)rrYrrXrXrYÚpmr_latest_exposureÙs$  ÿ $ ÿr.z/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)NrPr+rŽr}rJ)r–rÜr—ryÚtotalr©rÚ_sourceÚlabelz not foundz.An error occured while fetching from SciCrunchrˆ) rrÒr“r>r"r0rtZSCI_CRUNCH_INTERLEX_HOSTr—ryrwrjr) rPr–rÜr0rÐrFryr/rHrnrÿrXrXrYÚfind_by_onto_termós& ÿÿ   "r2z/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 laterrQrá) r>ZREADME_API_KEYrtr r—rurvrwrjrk)r0rr–rÐr{rXrXrYÚ search_readmesþ  þýr3z/metricscCstSrT)r¡rXrXrXrYÚmetrics%sr4z/event_updatedcCsrtj d¡}|tjkr*tdd|›dnDt ¡}|rbz t|ƒWStdd|›dYqn0n tddddS)NZevent_updated_secret_keyrzInvalid secret key: rÙr×zInvalid event data: zMissing event data)rr–r“r>ZCTF_CDA_ACCESS_TOKENrrÄr)Z secret_keyrÑrXrXrYÚ event_updated*s   r5z/all_dataset_idscCs"tƒ}dd„|Dƒ}d}| |¡S)NcSsg|] }t|ƒ‘qSrX)rk)rÚelementrXrXrYr©=r±z#all_dataset_ids..z, )r Újoin)ÚlistZ string_listÚ delimiterrXrXrYÚall_dataset_ids:sr:)rLr)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 rrríZhubspot.crm.contactsrr—rwr"rtr Ú urllib.parserZ!apscheduler.schedulers.backgroundrZapscheduler.triggers.combiningrZapscheduler.triggers.daterZapscheduler.triggers.intervalrZbotocore.exceptionsrrrZflaskrrrrZ flask_corsrZflask_marshmallowr Z pennsiever!Z pennsieve2Z Pennsieve2Zpennsieve2.directr"Zpennsieve.baser#rxZPILr$Ú requests.authr%Z flask_cachingr&Zapp.scicrunch_requestsr'r(r)r*r+r,r-r.r/r0r1r2r3r4r5Zscripts.email_senderr6r7r8r9r:r;r<Z xml.etreer=Ú app.configr>Z app.dbtabler?r@rAZapp.scicrunch_process_resultsrBrCrDrErFrGrHZapp.serializerrIZ app.utilitiesrJrKZapp.osparc.osparcrLr(rMr*Zapp.biolucida_process_resultsr¹rNrµÚ basicConfigrdrÃZ LOG_LEVELÚupperÚ log_levelrÚsetLevelÚgetattrÚWARNINGZ DEPLOY_ENVrPÚcacheZmarÂrsrñZSPARC_PORTAL_AWS_KEYZSPARC_PORTAL_AWS_SECRETrQr¯Z DATABASE_URLrÇÚAttributeErrorrÊr¯ÚobjectrRZ errorhandlerrmZbefore_first_requestr|rršr¤rµr´r³r›r’rœZmonthly_stats_email_schedulerÚmsZmonthly_stats_required_checkZadd_jobr_r™rŸr¡r r¢r£r¥r¦r§Zfeatured_dataset_id_triggerr¶ÚregisterZrouter¹rÆrÑZDEFAULT_S3_BUCKET_NAMErÔrèrr rrrrr$r&r-r1r3r5r7r9r=r?r@rDrIr.rOrVrXrZrer˜rorprqrvrxr{r}Úcachedr€rŒr¡r¥r¬r­r²r¶r·r»r½r°rÅrÆrÈrÉrËrÌrãrór÷rrrrrr!r%r&r.r2r3r4r5r:rXrXrXrYÚs"                   D    $     ü          ÿ         >  '           ,   0            0 "         7 & ]#