Continuing from last blog post, I was able to send an SMS to myself using twilio and nodejs. So now I have the capability to send email or sms with data scraped from a website and schedule this to happen daily for example. And I coded all this from my android phone using termux and vim. Pretty cool. Next up I want to be able to store the exchange rates in a database and display it on a webpage to show historical values.
See results below
This is my code
require("dotenv").config();
const axios = require("axios");
const twilio = require("twilio");
const client = twilio(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_AUTH_TOKEN
);
async function sendUsdRate() {
try {
const response = await axios.get(
process.env.MY_API
);
// Get USD row
const usdRow = response.data.data.find(
row => row[0] === "United States Dollar"
);
const buyingRate = usdRow[1];
const sellingRate = usdRow[2];
const message =
`USD Rates\n` +
`Buying: ${buyingRate}\n` +
`Selling: ${sellingRate}`;
const sms = await client.messages.create({
body: message,
from: process.env.TWILIO_PHONE_NUMBER,
to: process.env.MY_PHONE_NUMBER,
});
console.log("SMS sent:", sms.sid);
} catch (error) {
console.error(error);
}
}
sendUsdRate();

Comments