Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
remvee committed Jul 17, 2011
0 parents commit 833712d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pom.xml
*jar
/lib/
/classes/
.lein-deps-sum
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: lein run -m nos-tour-comments.core
13 changes: 13 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# nos-tour-comments

Small ring app to allow following NOS tour comments on my mobile.

## Usage

lein run -m nos-tour-comments.core

## License

Copyright (C) 2011 Remco van 't Veer

Distributed under the Eclipse Public License, the same as Clojure.
6 changes: 6 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(defproject nos-tour-comments "1.0.0-SNAPSHOT"
:description "Simple NOS Tour de France comments only site."
:dependencies [[org.clojure/clojure "1.2.1"]
[hiccup "0.3.6"]
[ring/ring-core "0.3.10"]
[ring/ring-jetty-adapter "0.3.10"]])
1 change: 1 addition & 0 deletions public/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ul, li { list-style: none; padding: 0; }
16 changes: 16 additions & 0 deletions public/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="nl-nl">
<head>
<title>NOS Tour Commentaar</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
<link type="text/css" rel="stylesheet" media="screen" href="app.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>NOS Tour Commentaar</h1>
<h2 id="date">Even geduld A.U.B.</h2>
<ul id="comments">
</ul>
</body>
</html>
14 changes: 14 additions & 0 deletions public/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var updater = function() {
$.getJSON("/feed?" + Math.floor(Math.random()*999999999),
function(data) {
setTimeout(updater, 5000)

$("#date").html(data.report[0].published_at.substr(0, 11))
var html = ''
$.each(data.report, function() {
html += '<li><strong>' + this.published_at.substr(11,5) + ' ' + this.title + '</strong><p>' + this.comment + '</p></li>'
})
$("#comments").html(html)
})
}
updater()
30 changes: 30 additions & 0 deletions src/nos_tour_comments/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns nos-tour-comments.core
(:use hiccup.core
ring.middleware.file
ring.middleware.file-info
ring.adapter.jetty))

(def *url* "http://nos.nl/data/livestream/report/comments_0.js")
(def *interval* 5000)
(defn fetch [] (try (slurp *url*) (catch Exception _)))
(def data (agent (fetch)))
(defn updater [_]
(Thread/sleep *interval*)
(send-off data updater)
(fetch))
(send-off data updater)

(defn handler [req]
(case (:uri req)
"/feed" {:status 200
:headers {"Content-Type" "application/javascript"}
:body @data}
"/" {:status 301
:headers {"Location" "/app.html"}}
nil))

(def app (-> handler (wrap-file "public") (wrap-file-info)))

(defn -main []
(let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
(run-jetty #'app {:port port})))

0 comments on commit 833712d

Please sign in to comment.