Skip to content

Instantly share code, notes, and snippets.

@pastak pastak/fetch.sh
Created Oct 14, 2018

Embed
What would you like to do?
#hitode909memorial_viewer
#!/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
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
You can’t perform that action at this time.