Permalink
Browse files

added files

  • Loading branch information...
1 parent 02408cf commit d15df6d667d21bdbc281f4100917428602f83576 @cormullion committed Apr 12, 2013
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,57 @@
+#!/usr/bin/env newlisp
+
+(change-dir
+ (string (env "HOME") "/projects/simple-weather-forecast/")) ; for local testing only
+
+(load "json.lsp" "cgi.lsp") ; uses standard modules
+
+(context 'Forecast)
+
+(set 'latitude 51
+ 'longitude 0.0
+ 'apikey "???"
+ 'start-time (time-of-day))
+
+(set 'curl-command
+ (format "curl -s https://api.forecast.io/forecast/%s/%f,%f?units=si"
+ apikey latitude longitude))
+
+(define (render t)
+ ; evaluate any newLISP code in template t between {% and %}
+ (replace [text]{%(.*?)%}[/text] t
+ (if (catch (eval-string $1) 'result)
+ (string result)
+ (string "[error: " $1 "]")) 0))
+
+(define (make-symbol day-details day-number key symbol-name)
+ ; make and assign values to symbols for relevant elements
+ (set (sym (string "day" day-number symbol-name)) (lookup key day-details)))
+
+(set 'curl-d (exec curl-command))
+(set 'data (first curl-d))
+(unless data (println "no data found") (exit))
+(set 'json (json2expr data))
+(set 'currently (json (chop (ref "currently" json))))
+(set 'time-stamp (last (currently (chop (ref "time" currently)))))
+(set 'summary (last (currently (chop (ref "summary" currently)))))
+(set 'icon (last (currently (chop (ref "icon" currently)))))
+(set 'pressure (last (currently (chop (ref "pressure" currently)))))
+(set 'temperature (last (currently (chop (ref "temperature" currently)))))
+(set 'humidity (last (currently (chop (ref "humidity" currently)))))
+(set 'precipIntensity (last (currently (chop (ref "precipIntensity" currently)))))
+(set 'visibility (last (currently (chop (ref "visibility" currently)))))
+(set 'daily (json (chop (ref "daily" json))))
+(set 'days (ref-all "time" daily))
+; daily forecasts for next 7 days
+(dolist (day days)
+ (set 'a-day (daily (chop (chop day))))
+ (make-symbol a-day $idx "time" "date")
+ (make-symbol a-day $idx "time" "time")
+ (make-symbol a-day $idx "summary" "summary")
+ (make-symbol a-day $idx "icon" "icon")
+ (make-symbol a-day $idx "temperatureMin" "temperature-min")
+ (make-symbol a-day $idx "temperatureMax" "temperature-max"))
+
+(set 'template (read-file "template.html"))
+(println "Content-Type: text/html\r\n\r\n" (render template))
+(exit)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,124 @@
+#forecast p {
+ margin: 2px;
+}
+
+#forecast div {
+ float: left;
+ display: inline;
+}
+
+#today p {
+ margin: 2px;
+}
+
+body {
+ width: 800px;
+ margin-right: auto;
+ margin-left: auto;
+ color: rgb(255, 255, 255);
+ font-family: Helvetica, sans-serif;
+ background-attachment: fixed;
+ background-image: url(http://daycaster.org/otteryweather/linen.jpg);
+}
+
+.footer {
+ margin-left: 2px;
+ margin-bottom: 2px;
+ margin-right: 2px;
+ margin-top: 5pt;
+ font-size: 5pt;
+}
+
+#highlowcurrently {
+ text-align: right;
+ right: 220px;
+ top: 30px;
+ position: absolute;
+}
+
+#bigtemperature {
+ right: 70px;
+ top: 0px;
+ font-size: 60pt;
+ position: absolute;
+}
+
+#precipitation {
+ font-size: 11pt;
+ float: right;
+ display: inline;
+ text-align: center;
+}
+
+#humidity {
+ font-size: 11pt;
+ float: right;
+ display: inline;
+ text-align: center;
+}
+
+#pressure p {
+ margin: 2px;
+}
+
+#visibility p {
+ margin: 2px;
+}
+
+#precipitation p {
+ margin: 2px;
+}
+
+#humidity p {
+ margin: 2px;
+}
+
+#placename {
+ font-size: 26pt;
+ float: left;
+ margin: 3px;
+}
+
+#pressure {
+ font-size: 11pt;
+ float: left;
+ text-align: center;
+}
+
+#visibility {
+ font-size: 11pt;
+ float: left;
+ text-align: center;
+}
+
+#forecast {
+ clear: both;
+ text-align: center;
+ margin: 6px;
+}
+
+#footer {
+ text-align: center;
+ clear: both;
+ margin: 20px;
+}
+
+#weathersummary {
+ font-size: 20pt;
+ text-align: center;
+}
+
+#time {
+ clear: both;
+ text-align: center;
+}
+
+#bigtime {
+ font-size: 40pt;
+ margin: 0pt;
+}
+
+#date {
+ font-size: 12pt;
+}
+
Oops, something went wrong.

0 comments on commit d15df6d

Please sign in to comment.