Created
November 27, 2019 21:39
-
-
Save ericmigi/89cd16c31687810210c453c7374c08f8 to your computer and use it in GitHub Desktop.
latest copy einkcaltrain
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
| const request = require('request') | |
| const express = require('express') | |
| const app = express() | |
| const port = 3000 | |
| var south; | |
| var north; | |
| //app.get('/', (req, res) => res.send('Next southbound: '+ south.type + ' in ' + south.time + '<br>Next northbound: ' + north.type + ' in ' + north.time)) | |
| app.get('/caltrain.css', (req, res) => res.send('.clock{padding:0;text-align:left}.time{font-weight:700;font-size:6em;text-align:center;line-height:100%;font-family:"Space Mono", monospace;}.clock.widget .time{font-size:400%;margin-bottom:1em;font-family:"Space Mono", monospace;}')) | |
| app.get('/base.css', (req, res) => res.send('body.dark,body.dark .bg-themeable,body.light .fg-themeable,html.inverted body.dark .fg-themeable,html.inverted body.light,html.inverted body.light .bg-themeable{background-color:#000;color:#fff}body.dark .fg-themeable,body.light,body.light .bg-themeable,html.inverted body.dark,html.inverted body.dark .bg-themeable,html.inverted body.light .fg-themeable{background-color:#fff;color:#000}body{font-family:Helvetica Neue,Helvetica Neue LT,sans-serif;margin:0;overflow-x:hidden;overflow-y:scroll}body.standalone{margin:2em}.h1,h1{font-size:500%;line-height:100%}.h1,.h2,h1,h2{font-weight:700}.h2,h2{font-size:200%;margin-bottom:1em}.h3,h3{letter-spacing:.33em;opacity:.5;text-transform:uppercase;font-weight:400}#kindle-console{max-height:50%;line-height:1em;overflow:scroll;position:fixed;bottom:0;left:0;right:0;background:#fff;border-top:1px solid #ccc;color:#000;width:100%;opacity:.85;text-align:left;font-family:monospace;font-size:.5em;word-wrap:break-word;padding:0 0 .3em}#kindle-console>div{padding:.5em}.widget{margin-bottom:2em}.menu{float:right}.menu .menu-button{text-align:right;padding:1em;opacity:.5;width:1em;height:1em;background-size:1em;background-repeat:no-repeat;background-position:50%;background-image:url(/outline-more_horiz-24px.e768254a.svg)}.menu:not(.expanded) .menu-content{display:none}.menu-item{padding:.5em 1em}.menu-item:active{background:#000;color:#fff}.menu .menu-content{background:#fff;position:absolute;z-index:100;right:1em;border:1px solid #000}button{padding:.5em 1em;background:#000;color:#fff;border:none;border-radius:10em;font-size:.7em}#settings-container{border-top:1px dotted grey}')) | |
| var header = '<html class="screensaver gr__eink_page"><head><meta http-equiv="refresh" content="60"><meta name="viewport" content="width=device-width, user-scalable=no"><title>Caltrain</title><link href="https://fonts.googleapis.com/css?family=Space+Mono&display=swap" rel="stylesheet"><meta charset="utf-8"><link href="/base.css" rel="stylesheet"><style>body{overflow:hidden};</style><link rel="stylesheet" href="/caltrain.css"><style type="text/css">body, select {font-size:36px}.kindle-fullheight {height:887px</style></head>'; | |
| app.get('/', (req, res) => { | |
| const clockBlock = (title,train) => { | |
| return '<div id="clock-container" class="clock" style="margin: 20px;">'+ | |
| '<div class="section-header" style="display:block; margin-bottom: 20px;">' + | |
| '<div class="date h3" style="flex-grow: 1; padding: 10px 0px; float: left;">' + title + '</div>' + | |
| '<div class="date h3" style="padding: 10px 20px; background-color: black; color: white; border-radius: 10px; float: right;">' + | |
| train.type + | |
| '</div>' + | |
| '</div>' + | |
| '<div class="time" style="clear:both; padding: 30px 0;">' + train.time.replace(' min.', 'm') + '</div>' + | |
| '</div>'; | |
| } | |
| request({ | |
| url: "https://wrapapi.com/use/ericmigi/caltrain/paloalto/0.0.1", | |
| json: true, | |
| method: "POST", | |
| body: { | |
| "wrapAPIKey": "7TI1gW8AVNYbyLzMiicfF69gHwUrUoG6" | |
| } | |
| }, function(err,resp,body) { | |
| console.log('next southbound train: ' + body.data.south[0].type + ' in ' + body.data.south[0].time); | |
| console.log('next northbound train: ' + body.data.north[0].type + ' in ' + body.data.north[0].time); | |
| south = body.data.south[0]; | |
| north = body.data.north[0]; | |
| const responseBody = | |
| header + | |
| '<body data-gr-c-s-loaded="true">' + | |
| clockBlock("NORTH",north) + | |
| '<div style="border: 5px dotted black;border-style: none none dotted;margin:32px 0;"></div>' + | |
| clockBlock("SOUTH",south) + | |
| '</body></html>'; | |
| res.send(responseBody) | |
| }); | |
| }) | |
| app.listen(port, () => console.log(`Example app listening on port ${port}!`)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment