Removed logs and don't overwrite existing markdown files

This commit is contained in:
Simon Cambier 2024-06-24 18:38:41 +02:00
parent 1341dd2833
commit f90cc7d2a0
2 changed files with 17 additions and 5 deletions

View File

@ -15,20 +15,27 @@
"Downloads the media from the item." "Downloads the media from the item."
(def files @[]) (def files @[])
(def media (item "media_attachments")) (def media (item "media_attachments"))
(pp (item "media_attachments")) (if dbg
(pp (item "media_attachments")))
(each m media (each m media
(def url (m "url")) (def url (m "url"))
(def folder (string save-path "attachments/")) (def folder (string save-path "attachments/"))
(array/push files {:path (string "./attachments/" (utils/get-image url folder)) (array/push files {:path (string "./attachments/" (utils/get-image url folder))
:description (m "description")})) :description (m "description")}))
(pp files) (if dbg (pp files))
files) files)
(defn write-markdown [item] (defn write-markdown [item]
(def files (download-media item)) (def files (download-media item))
(def id (item "id")) (def id (item "id"))
(def fout (file/open (string save-path id ".md") :w)) (def path (string save-path id ".md"))
(if (utils/exists? path)
(do
(print (string "Skipping " id))
(break)))
(def fout (file/open path :w))
(def inline (string (def inline (string
"mastodon-url:: " (item "url") " \n" "mastodon-url:: " (item "url") " \n"

View File

@ -1,5 +1,10 @@
(import httprequest :as r) (import httprequest :as r)
(def exists? (fn [path]
"Returns whether a file exists at the specified path."
(def f (file/open path :r))
(if f (do (file/close f) true) false)))
(defn get-image [url folder &named headers opts] (defn get-image [url folder &named headers opts]
"Download an image from a URL and save it to a file. Returns the path to the saved file." "Download an image from a URL and save it to a file. Returns the path to the saved file."
(default headers {}) (default headers {})