Matt's Roof Garden

Powered by 🌱Roam Garden

May 24th, 2021

random Twitter smartblock

Because clojure.string/lower-case does not work in Roam's datalog Test_String-XxX ,but (?i) works! Still doesn't work in JS though...

:q [:find ?s 
        :where 
            [?e :block/string ?s]
            [(re-find #"(?i)twitter\.com.*status" ?s)]]
            
:q [:find ?str
    :where [(re-pattern "twitter.com.*status") ?re-str]
                [?page-entity :block/string ?str]
                [(re-seq ?re-str ?str)]]
            
            
let queryText = `[:find ?str
    :where [(re-pattern "twitter.com.*status") ?re-str]
                [?page-entity :block/string ?str]
                [(re-seq ?re-str ?str)]]`;


window.roamAlphaAPI.q(queryText);

let query = `[:find (sum ?n)
              :with ?e
              :where (or-join [?s ?e]
                (and [?e :block/string ?s]
                             (not (or [(clojure.string/starts-with? ?s "${String.fromCharCode(96,96,96)}")]
                                      [(clojure.string/starts-with? ?s "{{")]
                                      [(clojure.string/starts-with? ?s "<%")]
                                      [(clojure.string/starts-with? ?s ":q ")])))
                     [?e :node/title ?s])
                     [(re-pattern "${String.fromCharCode(91,92,92,119,39,93,43)}") ?pattern]
                     [(re-seq ?pattern ?s) ?w]
                     [(count ?w) ?n]]`;

let results = window.roamAlphaAPI.q(query);

return [query, results];

try {
     let queryText = `[:find ?uid
                                :where 
                                    [(re-pattern "twitter.com.*status") ?re-str]
                                            [?e :block/string ?str]
                                            [(re-find ?re-str ?str)]
                                            [?e :block/uid ?uid]]`;
      let blocks = window.roamAlphaAPI.q(queryText);


        var random_result = blocks[Math.floor(Math.random() * blocks.length)];
        //console.log(random_result)
        var paren = "(("
        var block = paren.concat(random_result, "))")
        console.log( block)
        console.log("--------------------------------------------------------------------------")
    } catch(e) { 
      console.log(e);
      console.log("--------------------------------------------------------------------------")
    }