Skip to content

Instantly share code, notes, and snippets.

@ak1t0
Created January 16, 2016 14:16
Show Gist options
  • Save ak1t0/49dd142483dbc9d8e79e to your computer and use it in GitHub Desktop.
Save ak1t0/49dd142483dbc9d8e79e to your computer and use it in GitHub Desktop.
GitHub auto-downloader
(ns gh.core
(:require [clj-http.client :as client])
(:use [clojure.tools.namespace.repl :only [refresh]]
[hickory.core]
[clojure.string :only [trim]]))
;; download all repo as zip
(def target-url "https://github.com/[user-name]/")
(defn take-URL-value [x y]
(let [target x res y
c (.indexOf target :h3)]
(if (= -1 c)
(reverse res)
(recur (drop (+ c 4 1) target) (cons (first target) res)))))
(defn trim-value [x]
(map trim x))
(defn gen-zip-url [x]
(str target-url x "/archive/master.zip"))
(defn get-zip [x]
(clojure.java.io/copy
(:body (client/get (gen-zip-url x) {:as :stream}))
(java.io.File. (str x ".zip"))))
(defn get-zips [x]
(map get-zip x))
(defn get-all-zip [url]
(-> (slurp (str url "?tab=repositories"))
parse
as-hiccup
second
(nth 4)
flatten
(take-URL-value [])
rest
trim-value
get-zips)
true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment