I don't think the issue you are having is with slurp. If you could post more of the code that is causing you problems, it would be easier to debug. Entering the following at the repl seems to work fine for me (you can just do (slurp "http://tycho.usno.navy.mil/cgi-bin/timer.pl") and notice that it is changing every time):
(require '[clojure.string :as string]) (defn get-time [] (-> (slurp "http://tycho.usno.navy.mil/cgi-bin/timer.pl") (string/split #"<BR>") (nth 1) (string/split #"\t") first)) (get-time) ;; "Jun. 10, 14:19:07 UTC" (get-time) ;; "Jun. 10, 14:19:10 UTC" (get-time) ;; "Jun. 10, 14:19:12 UTC" - Mark On Fri, Jun 10, 2011 at 9:22 AM, Thomas <[email protected]> wrote: > Hi Ivan et al, > > I have managed to re-read the string every 15 seconds, the problem is > that the slurp reads stale data. It returns always the same string, > even though I can see in my browser that it has changed. This also > happens when I just do the slurp in the REPL. Apologies for not making > this clearer in the original post. > > Thomas > > On Jun 10, 9:03 am, Ivan Koblik <[email protected]> wrote: > > Hi Thomas, > > > > You need to execute this line: > > (dosync (ref-set location (read-json (slurp url)))) > > every time you want to re-query the string. > > > > To do this periodically you could do something like this [1]: > > > > (import '(java.util TimerTask Timer)) > > (let [task (proxy [TimerTask] [] > > (run [] (dosync (ref-set location (read-json (slurp url))))))] > > (. (new Timer) (schedule task (long 15000)))) > > > > [1]:http://www.mail-archive.com/[email protected]/msg00136.html > > > > Cheers, > > Ivan. > > > > On 6 June 2011 14:51, Thomas <[email protected]> wrote: > > > > > > > > > > > > > > > > > Hi All, > > > > > I recently started playing with Clojure and loving it... and finding > > > of course the usual problem(s). In my little program I am reading a > > > JSON string that changes regularly, up to once every 15 seconds or so, > > > through HTTP. I know that the string changes, I can see that in my > > > browser and I can see things change in another (web)app that consumes > > > the string. My current code looks like this: > > > > > (def url "http://xxxx.xxxxx.xx" ) > > > (def location (ref nil)) > > > (dosync (ref-set location (read-json (slurp url)))) > > > > > My problem is, that once I have started the program it reads the > > > string successfully, but subsequent reads are the same, even though I > > > know that the string has changed. What should I do differently? (I > > > loop through the function with a bit of code from Rich Hickeys > > > ants.clj) > > > > > TIA > > > Thomas > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Clojure" group. > > > To post to this group, send email to [email protected] > > > Note that posts from new members are moderated - please be patient with > > > your first post. > > > To unsubscribe from this group, send email to > > > [email protected] > > > For more options, visit this group at > > >http://groups.google.com/group/clojure?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to [email protected] > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
