How to Get Twitter Notifications on Currency Exchange Rate: Web Scraping and Automation

How to Get Twitter Notifications on Currency Exchange Rate: Web Scraping and AutomationDeborah KewonBlockedUnblockFollowFollowingApr 6Image by Photo Mix from PixabayAs the world becomes more integrated, we are more connected than ever.

More students study abroad and more people travel around the globe.

Whether it is for education or for tourism, when we go abroad or send money to a foreign country, we have to consider the exchange rate.

For this reason, I created an automated notification system where we can get a Twitter alert when the exchange rate of designated currency drops or goes up.

In this article, I will explain how I scraped exchange rate data from yahoo finance and set up an automated notification system via Twitter.

Let’s get started!1.

Install required packages for web scrapingI first installed a few required packages.

BeautifulSoup is for parsing HTML pages, and time-related packages are for documenting the date and time of the currency exchange.


Scrap exchange rate data from Yahoo Finance using BeautifulSoupStructure of Yahoo FinanceAs you can see above, Yahoo Finance consists of “Symbol”, “Name”, “Last price” and “Change”.

For this article, I used only “Name” and “Last price”.

Using BeautifulSoup, I parsed the exchange rate page.

After parsing, I used the for loop statement to extract some information.

Since I don’t need the whole data, I started parsing at 40th observation and stopped at 404th observation with an interval of 14 and created a currency dataframe with only “Name” and “Last price” information.

Since I’m interested in USD/JPY exchange rate (how much Japanese yen is equal to 1 US dollar?), I selected 16th observation and assigned it to now_usd_jpy (current USD/JPY Exchange rate).

dataframe “Currency”The exchange rate I extracted from Yahoo Finance is recorded in the text file I created“usdyen”.

If the current exchange rate is different from the old exchange rate, the current exchange rate replaces the old one.

Text file where I recorded the current USD/JPY exchange rate3.

Set up an automated notification system via TwitterNow is the time to set up an automated notification system via Twitter.

Let’s send out the exchange rate notification to our Twitter followers based on the exchange rate recorded on the text file.

In order to do that, I installed TwitterAPI and requested Twitter for access tokens (for more details, please refer to https://developer.


com/ en/docs/basics/authentication/guides/access-tokens.

html ).

With the access tokens, my program can now tweet USD/ JPY exchange rate in the format of “1 USD to JPY = 111.

6 (JAPAN TIME 05:06:37 04–05–19)”.

USD/JPY exchange rate tweetIf we just update the currency rate on Twitter, it is no fun.

It doesn’t really make sense to manually run the program every time we want to know the exchange rate.

Having said that, I made the program run 24/7.

Every 5 hours (60 seconds x 60 seconds x 5 hours), my algorithm automatically checks the current currency exchange rate and updates the old currency exchange rate and then posts it on Twitter.

Since Twitter doesn’t allow the same message to be posted, I used try and except block to make it acceptable.

The web scraping and automation algorithms mentioned above are very easy to use and flexible to apply for other subjects such as cryptocurrency and stock prices.

For the next article, I would like to discuss Rasberry pi-how we can use Raspberry pi to make the program run 24/7 as it is not very practical to run this python script all day long on our computer or laptop.

Thank you for reading!.I hope my article was helpful and easy to follow.

If you have any comments or feedback, please feel free to leave a comment below.

If you liked what I did, don’t hesitate to follow me on GitHub and connect with me on Linkedin.

.. More details

Leave a Reply