[q3cpma]2021-03-27:He<<re'salittlemoduletocreateandupdateAtomfeedsusing[tDOM]thatImadetouseintwoofmyprojects:>>'''[https://sr.ht/~q3cpma/mangadex-tools/%|%mangadex-tools]'''and'''[https://sr.ht/~q3cpma/haggle/%|%haggle]'''.ExceptalittleternaryhelperIleftin,itisstandalone.======#SimpleAtomreading/writing,exportedprocs:#create,read,add_entry,writepackagerequiretdom#Ternaryproc?{testa{b""}}{tailcallif$test[listsubst$a][listsubst$b]}namespaceevalatom{namespaceexportcreatereadread_or_createadd_entrywritenamespaceensemblecreatevariablexmlnshttp://www.w3.org/2005/Atomproctimestamp{}{clockformat[clockseconds]-format%Y-%m-%dT%XZ-timezone:UTC}#nodespec:{tag?text??attrnameattrval...?}#Use{tag{}attrnameattrval...}ifyouwantanattributebutnotextprocnode{docnodespec}{variablexmlnssetattrs[lassign$nodespectagtext]setnode[$doccreateElementNS$xmlns$tag]if{$textne""}{$nodeappendChild[$doccreateTextNode$text]}if{$attrsne""}{$nodesetAttribute{*}$attrs}return$node}#args:node'snodespecprocadd{docnodeargs}{$nodeappendChild[node$doc$args]}#WrapperarounddomNodeselectNodesprocselect_nodes{docargs}{variablexmlns[$docdocumentElement]selectNodes-namespaces[listatom$xmlns]\{*}$args}#Ignoreidforlocalfeeds(afile://URIwillbeused)proccreate{pathtitle{id{}}}{variablexmlnssetpath[filenormalize$path]setatom[dictcreatepath$pathentry_count0modified1]setdoc[domcreateDocumentNS$xmlnsfeed]dictsetatomxml$docsetroot[$docdocumentElement]add$doc$roottitle$titleadd$doc$rootid[?{$idne""}{$id}{file://$path}]add$doc$rootupdated[timestamp]return$atom}procread{path}{setatom[dictcreatepath[filenormalize$path]modified0]setchan[open$path]setdoc[domparse[read$chan]]close$chandictsetatomxml$docdictsetatomentry_count[llength[select_nodes$doc//atom:entry]]return$atom}procread_or_create{pathtitle}{if{[fileexists$path]}{read$path}else{setret[create$path$title]atomwrite$retreturn$ret}}procwrite{atom}{if{[dictget$atommodified]}{setchan[open[dictget$atompath]w]puts$chan[[dictget$atomxml]asXML-indent2]close$chan}}#Addanentrytothefeedinthe_atomvariable#argsisadictionarycontainingtheoptionalvaluesforkeysid,content#andlink;noidmeanslocalfeed,thusauniqueURIbasedonfeedpath#andentrycountwillbeusedprocadd_entry{_atomtitleargs}{upvar$_atomatomsetdoc[dictget$atomxml]setid[if{[dictexists$argsid]}{\dictget$argsid\}else{\stringcat"file://[dictget$atompath]#[dictget$atomentry_count]"\}]settimestamp[timestamp]setentry[node$docentry]add$doc$entrytitle$titleadd$doc$entryid$idadd$doc$entryupdated$timestampif{[dictexists$argscontent]}{add$doc$entrycontent[dictget$argscontent]typehtml}if{[dictexists$argslink]}{add$doc$entrylink{}href[dictget$argslink]}[$docdocumentElement]appendChild$entrydictincratomentry_countdictsetatommodified1[select_nodes$doc//atom:feed/atom:updated/text()]nodeValue$timestamp}}======Anexample:======sourceatom.tclsetfeed[atomread_or_createatom.xml"Myblog"]atomadd_entryfeed"Article1"\content"Contentofarticle1"\link"http://myblog.net/2021/03/article_1.html"\id"http://myblog.net/2021/03/article_1.html"atomwrite$feed======