init commit
commit
13e5da66fa
|
@ -0,0 +1,13 @@
|
||||||
|
# wuvt-signal
|
||||||
|
|
||||||
|
Code for a wuvt signal & SMS bot
|
||||||
|
|
||||||
|
|
||||||
|
### signal
|
||||||
|
|
||||||
|
See `signal/app.py`. Requires signald + pysignald. Must provide `SIGNAL_NUMBER` env var.
|
||||||
|
|
||||||
|
|
||||||
|
### sms
|
||||||
|
|
||||||
|
See `sms/index.js`. Requires lambda to respond and AWS pinpoint + an SNS topic to receive messages.
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from signald import Signal
|
||||||
|
|
||||||
|
s = Signal(os.environ["SIGNAL_NUMBER"])
|
||||||
|
|
||||||
|
@s.chat_handler(".wuvt")#re.compile(".*?(wuvt).*?"))
|
||||||
|
def wuvt(message, match):
|
||||||
|
r = requests.get('https://www.wuvt.vt.edu/playlists/latest_track', headers={'Accept': "application/json"})
|
||||||
|
trackinfo = r.json()
|
||||||
|
|
||||||
|
if 'listeners' in trackinfo and trackinfo['listeners'] is not None:
|
||||||
|
return str(
|
||||||
|
"{dj} is currently playing \"{title}\" by {artist} with "
|
||||||
|
"{listeners:d} online listeners".format(
|
||||||
|
dj=trackinfo['dj'],
|
||||||
|
title=trackinfo['title'],
|
||||||
|
artist=trackinfo['artist'],
|
||||||
|
listeners=trackinfo['listeners']))
|
||||||
|
else:
|
||||||
|
return str("{dj} is currently playing \"{title}\" by {artist}".format(
|
||||||
|
dj=trackinfo['dj'],
|
||||||
|
title=trackinfo['title'],
|
||||||
|
artist=trackinfo['artist']))
|
||||||
|
|
||||||
|
def divide(input, by):
|
||||||
|
return (input // by), (input % by)
|
||||||
|
|
||||||
|
@s.chat_handler(".yi")
|
||||||
|
def yi(message, match):
|
||||||
|
quadraels, remainder = divide(int(time.time()), 1753200)
|
||||||
|
raels = quadraels * 4
|
||||||
|
extraraels, remainder = divide(remainder, 432000)
|
||||||
|
if extraraels == 4:
|
||||||
|
return('Yes! PARTAI!')
|
||||||
|
elif extraraels == 3:
|
||||||
|
return('Soon...')
|
||||||
|
else:
|
||||||
|
return('Not yet...')
|
||||||
|
|
||||||
|
s.run_chat()
|
|
@ -0,0 +1,48 @@
|
||||||
|
const AWS = require('aws-sdk');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
|
AWS.config.update({region: 'us-east-1'});
|
||||||
|
|
||||||
|
|
||||||
|
exports.handler = (event) => {
|
||||||
|
const message = JSON.parse(event.Records[0].Sns.Message);
|
||||||
|
//console.log(`MESSAGE: ${JSON.stringify(message)}`);
|
||||||
|
|
||||||
|
if (message.messageBody.toLowerCase().includes('wuvt')) {
|
||||||
|
fetch('https://www.wuvt.vt.edu/playlists/latest_track', {
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
}
|
||||||
|
}).then((r) => {
|
||||||
|
r.text().then((rt) => {
|
||||||
|
// Check for error
|
||||||
|
if (r.status !== 200) {
|
||||||
|
console.error(`ERROR, STATUS: ${r.status}, TEXT: ${rt}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create smsResponse
|
||||||
|
const trackinfo = JSON.parse(rt);
|
||||||
|
let smsResponse = '';
|
||||||
|
if (trackinfo.listeners) {
|
||||||
|
smsResponse = `${trackinfo.dj} is currently playing "${trackinfo.title}" by ${trackinfo.artist} with ${trackinfo.listeners} listeners.`;
|
||||||
|
} else {
|
||||||
|
smsResponse = `${trackinfo.dj} is currently playing "${trackinfo.title}" by ${trackinfo.artist}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send smsResponse
|
||||||
|
const smsParams = {
|
||||||
|
Message: smsResponse,
|
||||||
|
PhoneNumber: message.originationNumber,
|
||||||
|
};
|
||||||
|
|
||||||
|
const promise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(smsParams).promise();
|
||||||
|
promise.then().catch((err) => {
|
||||||
|
console.error(err, err.stack);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(`MESSAGE: ${JSON.stringify(message)}`);
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"node-fetch": "^2.6.0"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue