#hitode909memorial_viewer
This file contains 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
#!/bin/bash | |
set -ue | |
cp /Users/pastak/worktmp/wedpar-namecard/list.txt /Users/pastak/worktmp/wedpar-namecard/list.txt.tmp | |
twurl "/1.1/search/tweets.json?q=%23hitode909memorial" \ | |
| jq .statuses[].entities | grep media_url_https | perl -ne '$_ =~ /"media_url_https": "([^"]+)"/; print "$1\n"' \ | |
>> /Users/pastak/worktmp/wedpar-namecard/list.txt.tmp | |
cat /Users/pastak/worktmp/wedpar-namecard/list.txt.tmp | uniq > /Users/pastak/worktmp/wedpar-namecard/list.txt | |
This file contains 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
import Koa from 'koa'; | |
import Router from 'koa-router'; | |
import fs from 'fs'; | |
const app = new Koa(); | |
const router = new Router(); | |
router.get('/memorial', (ctx) => { | |
ctx.body = ` | |
<div style='width: 95vw;text-align: center;'> | |
<img id='mainImg' style='margin: auto;max-width: 100vw; max-height: 95vh;'/> | |
</div> | |
<script> | |
const a = () => { | |
const mainImg = document.querySelector('#mainImg'); | |
fetch('/memorial-list') | |
.then(r => r.text()) | |
.then(t => { | |
mainImg.src = t; | |
setTimeout(a, 10 * 1000) | |
}) | |
} | |
a(); | |
</script> | |
` | |
}); | |
router.get('/memorial-list', (ctx) => { | |
const list = fs.readFileSync('list.txt').toString(); | |
const lines = list.split('\n'); | |
ctx.body = lines[Math.floor(Math.random() * lines.length)]; | |
}); | |
app | |
.use(router.routes()) | |
.use(router.allowedMethods()); | |
const port = process.env.PORT || 3000; | |
app.listen(port, () => { | |
console.log('listening on port ' + port); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment