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

Stuck running sftp server on termux alpine for multi-user setup

The below is my journey trying to get multi-user sftp working using alpine on termux pkg update && pkg upgrade pkg install proot-distro openssh proot-distro install alpine proot-distro login alpine apk update apk upgrade apk add openssh shadow sudo apk add vim vim /etc/ssh/sshd_config Port 8022 PermitRootLogin no PasswordAuthentication yes Subsystem sftp internal-sftp Match Group sftpusers     ChrootDirectory /sftp/%u     ForceCommand internal-sftp     X11Forwarding no     AllowTcpForwarding no addgroup sftpusers adduser user1 adduser user1 sftpusers mkdir -p /sftp/user1/upload chown root:root /sftp/user1 chmod 755 /sftp/user1 chown user1:sftpusers /sftp/user1/upload How I run my server each time pkill sshd rm -f /etc/ssh/ssh_host_* ssh-keygen -A /usr/sbin/sshd -D -d -d -d From another termux session sftp -P 8022 user1@127.0.0.1 Connection reset by 127.0.0.1 port 8022 Connection closed Some troubleshooting steps mkdir -p /run/sshd chmod 75...

Recursion example with SQL

I asked my friend Chatty, can you use recursion in SQL? For example I have a table (ID, value) ordered by increasing ID. Can you guide me through using recursion to select all the rows of consecutive repeated values using and creating an SQLite database. Provide the small sample data. Is there a better way to do this? A More Modern Alternative (Window Functions) In real-world SQL, this problem is usually solved more efficiently using window functions like: LAG() ROW_NUMBER() SUM() OVER But recursion is excellent for learning traversal logic and hierarchical thinking. Recursion example using sqlite on termux DROP TABLE IF EXISTS sample; CREATE TABLE sample (     id INTEGER PRIMARY KEY,     value TEXT ); INSERT INTO sample (id, value) VALUES (1, 'A'), (2, 'A'), (3, 'A'), (4, 'B'), (5, 'B'), (6, 'C'), (7, 'A'), (8, 'A'), (9, 'D'), (10, 'D'), (11, 'D'), (12, 'D'); WITH RECURSIVE grouped AS (    ...

Bless us today

It is 515pm and I have decided to write. Today is the day before the holiday and it feels like a Friday. I did not feel like doing anything this afternoon. But I got up and made dinner. Then brush my teeth and bathe. A round of applause to all of us for being alive and making it through the day. There are many things we can applaud ourselves for. There are many things we can applaud others for. It is good to pat ourselves (and others) on the shoulders now and again. Life is not easy. No one has it easy. Comfort is an illusion. But God is real and so we pray. It is 214pm on the following Monday and I have decided to continue my writing. I have this thought. God is holding my hand and we are walking. Walking in empty space. I closed my eyes and selected a verse from the holy Quran. I landed on surah 94 verse 5 - so verily with hardship there is ease. No matter how and when we are tested we must remind ourselves of the goodness of God. God is not going to leave us stranded and empty hande...