#!/usr/bin/env janet
(defn get-lines
  [file-path]
  (let [rfile (file/open file-path :r)
        file-contents (string/split "\n" (file/read rfile :all))]
    (file/close rfile)
    file-contents))

(defn write-to-file
  [file-path str]
  (let [wfile (file/open file-path :w)]
    (file/write wfile str)
    (file/close wfile)))

(defn main
  [& args]
  (let [file-path (get args 1)
        lines (sort (get-lines file-path) <)
        uniq-list @[]]
    (var new-string @"")
    (loop [line :in lines :when (-> line empty? not)]
      (let [split-lines (string/split " " line)
            url (get split-lines 1)]
        (unless (find |(= url $) uniq-list)
          (array/push uniq-list url)
          (set new-string (string new-string line "\n")))))
    (write-to-file file-path new-string)))
