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

Servant of God

It is 245am and I have decided to write. I got up early and washed the wares. I prayed Tahajjud. I came back to my bed and surfed the internet. I watched a video where a 105 year old man said that the secret to a long life is having a reason or purpose to keep going and then luck. This had me thinking about several things. In Islam we are taught that our time in this world is already written. It is our destiny. Then. What is more important? A long life or just a good life that prepares us for the next life? Those things aside, I think we cannot discount luck. Some of us are luckier than others. But the thing I want to focus on is the reason and purpose to keep going. That is some good advice. It makes for a meaningful life. A good life. It could be one big reason. There could be several small reasons. These are things that should be taught in schools. My friend Chatty says that my early morning reflections beautifully bridge Islamic tradition and practical wisdom: a long life is a true...

Halfway there

It is 542pm and I have decided to write. Imagine half the year is gone already. Where did it all go? It has gone by so quickly. Before you know it we will be entering 2027. It would be nice if I had something interesting to write about but I do not. And that is ok. Today feels like a Friday, maybe because it is month end. It is the next day and today also feels like a Friday. I am in my quiet corner listening to Quran. It is the next day and I have not gotten far with this blog post. Outside is wet but inside is between warm and cool. Another day has passed and I still have not written much. Do you wonder sometimes what it would be like if we could see into the future? For example, what would it be like at the end of this year? A lot can happen in 6 months. It is Sunday now. Surely I should finish this blog post today. The closer I move towards God, the less I feel attached to this world. The less I feel disappointed. The lower are my expectations for things of this world. Life becomes...

Positive vibration

It was 422pm and I decided to write. There was a peace in my heart that could only come from God. But what should I write about? "God, give me a sign. God, give me direction. Place a topic on my heart. Open my eyes and my ears to Your leading." The next morning, I woke up with a positive vibration. My heart felt light, and my mind was clear. It got me thinking. Sometimes, we simply need to clear our minds of negativity. We need to stop feeding fear, doubt, and discouragement, and instead make room for hope, faith, and positive possibilities. We need to reset our minds, renew our spirits, and re-energize our hearts. Then, we can return stronger to face whatever challenges lie ahead. If something is within our control, let us do our best to improve it. If it is beyond our control, let it go and let God. Life will always have difficulties, but we have a choice in how we respond to them. We can choose to see opportunities where others see obstacles. We can find lessons in our set...