-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnow.js
48 lines (40 loc) · 1.22 KB
/
now.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const schedule = require('node-schedule');
const sheetHelper = require('./sheetHelper');
const config = require('./config');
const express = require('express');
const Liquid = require('liquidjs');
const app = express();
const engine = new Liquid({
root: __dirname, // for layouts and partials
extname: '.liquid'
});
// register liquid engine
app.engine('liquid', engine.express());
app.set('views', './views'); // specify the views directory
app.set('view engine', 'liquid'); // set to default
let lastTweet = '';
app.get('/', (req, res) => {
res.write('<div><strong>ForesterTweetBot</strong></div>');
res.write('<div><a href="https://www.twitter.com/Forester_TN">https://www.twitter.com/Forester_TN</a></div>');
res.write('<div><strong>Last tweet:</strong> ' + lastTweet);
res.end();
});
app.get('/tweet', (req, res) => {
sheetHelper.init(() => {
sheetHelper.tweetRandom((tweet) => {
lastTweet = tweet;
res.write(tweet);
res.end();
});
});
});
app.get('/mysong/:name', function (req, res) {
sheetHelper.init(() => {
const row = sheetHelper.getRowAtIdx(12);
res.render('mysong', {
name: req.params.name,
spotifyuri: row.spotifyuri
});
});
});
module.exports = app;