Created
October 20, 2014 09:24
-
-
Save tommyettinger/70da80dc2a7d7ea08b04 to your computer and use it in GitHub Desktop.
Clj-Ebay with at-at
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clj-ebay.main | |
(:require [overtone.at-at :as schedule] | |
[clj-ebay.core] | |
[clj-ebay.finding :as finder]) | |
(:gen-class)) | |
(def my-pool (schedule/mk-pool)) | |
(defn search-from-ebay | |
"comment" | |
[searched-key max-price] | |
(let [result (finder/find-items-advanced {:entries-per-page "1", | |
:global-id "EBAY-US", | |
:page-number 1, | |
:sort-order "CurrentPriceHighest", | |
:item-filter-name "MaxPrice", | |
:item-filter-value max-price, | |
:keywords searched-key })] | |
(get-in result ["findItemsAdvancedResponse" 0 "searchResult" 0 "@count"] 0))) | |
(defn -main | |
"Using EbayAPI + at-at, first project in Clojure" | |
[& args] | |
(let [searched-key (first args) max-price (second args)] | |
(declare killJob) | |
(println "Starting job") | |
(def job (schedule/every 1000 | |
#(let [countResult (search-from-ebay searched-key max-price)] | |
;(println (class countResult)) ;; <-- this returned "String" | |
(if (> (read-string countResult) 0) ;; <-- so comparing a string to 0 crashed it. | |
(do (println "Found " countResult "results") (killJob)) | |
(println "Haven't found anything yet"))) | |
my-pool)) | |
(defn killJob [] (schedule/stop job) (System/exit 0)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment