Created
February 2, 2020 22:27
-
-
Save gavlooth/eacadca6556b04696eb88f274ed9f051 to your computer and use it in GitHub Desktop.
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
#lang racket | |
#lang racket/base | |
(require xml) | |
(require sxml/sxpath) | |
(require simple-http) | |
(require racket/gui/base) | |
(define (weave xs ys) | |
(match (list xs ys) | |
[(list (cons x xs) (cons y ys)) (cons x (cons y (weave xs ys)))] | |
[(list '() ys) ys] | |
[(list xs '()) xs])) | |
(define request-meteo | |
(update-host html-requester "penteli.meteo.gr")) | |
(define (get-weather-data) | |
(get request-meteo "/stations/kos/")) | |
(define querry-values (sxpath "//div[contains(@class, 'content_values')]/div[contains(@class, 'col left_col')]/div[contains(@class, 'col_sub dist boxshadow')]/div[contains(@class, 'line')]/div[contains(@class, 'lright')]/text()")) | |
(define querry-labels (sxpath "//div[contains(@class, 'content_values')]/div[contains(@class, 'col left_col')]/div[contains(@class, 'col_sub dist boxshadow')]/div[contains(@class, 'line')]/div[contains(@class, 'lleft')]/text()")) | |
(define (write-weather-data box_) | |
(let ([out (open-output-file "test.txt" #:exists 'replace)]) | |
(write (unbox box_) out) | |
(close-output-port out))) | |
(define weather-information-labels | |
'("Temperature" "Humidity" "Dewpoint" "Wind" "Barometer" "Today's Rain" | |
"Rain Rate" "Storm Total" "Monthly Rain" "Yearly Rain" "Wind Chill" | |
"Heat Index" "Solar Radiation" "UV Index" "Sunrise" "Sunset")) | |
(define frame (new frame% [label "Weather on KOS"] | |
[width 350] | |
[height 600])) | |
(define msg (new message% [parent frame] | |
[label "A simple weather widget"])) | |
(define weather-yellow (make-color 254 235 135 0.4)) | |
(define (spawn-rows canvas dc card) | |
(letrec ([spawner (lambda (dc counter weather-values) | |
(cond | |
[(= 0 counter) null] | |
[(> counter 0) | |
(letrec ( | |
[current-cell (- card counter)] | |
[offset (* 30 current-cell)] | |
[weather-label (list-ref weather-information-labels current-cell)] | |
[weather-value (list-ref weather-values current-cell)]) | |
(send dc draw-rectangle 0 offset 150 30) | |
(send dc draw-rectangle 150 offset 350 30) | |
(send dc draw-text weather-label 10 (+ offset 10)) | |
(send dc draw-text weather-value 160 (+ offset 10))) | |
(spawner dc (- counter 1) weather-values)]))]) | |
(thread (lambda () | |
(let rec ([weather-values (querry-values (html-response-body (get-weather-data)))]) | |
(spawner dc card weather-values) | |
(sleep 300) | |
(send dc clear) | |
(printf "\nUpdating weather data!") | |
(rec (querry-values (html-response-body (get-weather-data))))))))) | |
(define canvas | |
(new canvas% [parent frame] | |
[paint-callback | |
(lambda (canvas dc) | |
(send dc set-pen (make-color 57 91 129 0.4) 1 'solid) | |
(spawn-rows canvas dc 16) | |
(send dc set-text-foreground (make-color 61 31 20)))])) | |
(define (main-) | |
(send frame show #t)) | |
(main-) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment