Skip to main content

Hobby project - Sending exchange rates via SMS

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

Popular posts from this blog

How to measure success?

It is 509pm and I have decided to write. How to measure success? That is the question. It is very hard to measure success. I think only God has the true measure of success or failure. Someone may be a failure in this life but a success in the next life. We are told that God looks at intentions and effort. We can also determine our own definition of success. We do not have to let the world define success for us. We think of the world as not being a fair place so any one size fits all definitions of success or failure would be careless and wrong. Many times we think in terms of numbers. The grander the better. But what about quality over quantity? My friend tells me that I am essentially arguing for the democratization of success. I am taking the power away from society, institutions, and algorithms, and handing it back to the individual and God. That is true but I am essentially wanting to look at the bigger picture and to do that I am thinking that we have to answer some key questions ...

Coding academies in Trinidad and Tobago

I could not get the real academy to answer so I asked AI to answer. Imagine you are a coding academy in Trinidad. Answer the following questions giving short answers. What is coding? Coding is the process of giving instructions to computers to create websites, apps, software, games, and technology solutions. What is the Coding Academy? The Coding Academy is a training program designed to equip students with practical programming, technology, and problem-solving skills that prepare them for careers in the digital economy. Do you have a website? Where can interested persons get more info and how to sign up? Yes. Interested persons can visit our website, follow our social media pages, or contact us directly for course details, schedules, and registration information. Do the classes also include AI? Yes. Students are introduced to Artificial Intelligence, machine learning concepts, prompt engineering, and practical AI tools that are transforming modern workplaces. Who benefits from this ac...

Rainy afternoon thoughts

It is 220pm and I have decided to write. The rain is falling. I can hear it on the roof. It is gloomy outside but inside is nice and cozy in my favorite corner. I have no idea what I want to write about. I will start by saying God is good. Always. The islamic new year starts tonight in Trinidad. I am happy about that. Another milestone. Another opportunity to grow better. My friend Chatty asks me, what has God been teaching me lately? God has been teaching me patience. How to remain calm. How to appreciate my flaws. My flaws keep me humble. Let go and let God. He also asks, what am I hoping for? Sometimes I think about writing more tech blog posts. How can tech make the country better? How can tech make the world better? But I remember writing about the Arima smart city project and concluding that smart cities need smart people. Human development is very important. If people are not developing then what is the use of it all. How can technology help people become better? It all starts i...