|
14 | 14 | Error |
15 | 15 | (reason [_] (name error-code))) |
16 | 16 |
|
| 17 | +(defrecord UserError [reason] |
| 18 | + Error |
| 19 | + (reason [_] reason)) |
| 20 | + |
17 | 21 | (defn get-url [url params headers] |
18 | 22 | (->> {:query-params params |
19 | 23 | :headers headers |
|
114 | 118 |
|
115 | 119 | (defn transduce-merged-data [mal-username xf f map-result] |
116 | 120 | (go |
117 | | - (let [mal-data (fetch-mal-watching mal-username) |
118 | | - ani-data (apply fetch-anilist-airing (get-year-and-season)) |
119 | | - mal-data (<! mal-data) |
120 | | - ani-data (<! ani-data) |
121 | | - combined-xf (comp (filter #(= 2 (count %))) |
122 | | - (map (partial apply merge)) |
123 | | - xf)] |
124 | | - (cond |
125 | | - (nil? mal-data) (println "could not fetch mal data for" mal-username) |
126 | | - (nil? ani-data) (println "could not currently running shows for" (get-year-and-season)) |
127 | | - (error? mal-data) mal-data |
128 | | - (error? ani-data) ani-data |
129 | | - :else |
130 | | - (->> (concat mal-data ani-data) |
131 | | - (group-by :id) |
132 | | - vals |
133 | | - (transduce combined-xf f) |
134 | | - map-result))))) |
| 121 | + (if-not (empty? mal-username) |
| 122 | + (let [mal-data (fetch-mal-watching mal-username) |
| 123 | + ani-data (apply fetch-anilist-airing (get-year-and-season)) |
| 124 | + mal-data (<! mal-data) |
| 125 | + ani-data (<! ani-data) |
| 126 | + combined-xf (comp (filter #(= 2 (count %))) |
| 127 | + (map (partial apply merge)) |
| 128 | + xf)] |
| 129 | + (cond |
| 130 | + (nil? mal-data) (println "could not fetch mal data for" mal-username) |
| 131 | + (nil? ani-data) (println "could not currently running shows for" (get-year-and-season)) |
| 132 | + (error? mal-data) mal-data |
| 133 | + (error? ani-data) ani-data |
| 134 | + :else |
| 135 | + (->> (concat mal-data ani-data) |
| 136 | + (group-by :id) |
| 137 | + vals |
| 138 | + (transduce combined-xf f) |
| 139 | + map-result))) |
| 140 | + (UserError. "Please enter your MAL username in the settings")))) |
135 | 141 |
|
136 | 142 | (defn fetch-merged-data [mal-username xf] |
137 | 143 | (transduce-merged-data mal-username xf conj identity)) |
|
0 commit comments