Simple python script to fetch the equivalent price of 1 Dogecoin in the local currency

Tirthya Kamal Dasgupta
3 min readApr 18, 2021

--

For the last few days, Dogecoin has been a much-hyped thing over the internet. I wrote a simple python script that scraps the price of 1 Dogecoin in INR (as I am from India) from a website (Yahoo Finance) and sends me as an alert to my personal WhatsApp.

So, I went to this website: https://in.finance.yahoo.com/quote/DOGE-INR/, as you can see here in the image below.

Price of 1 Dogecoin in INR as per Yahoo Finance

So you can see that, I have highlighted the value of 1 Dogecoin shown there, using a brown-colored rectangle. Now, I need to scrap this value out of this page. I wrote a python script to do that. I will discuss each line of code step by step.

Importing the Python libraries which are needed

In the above code, which you can see, I am using a Python library called lxml. To extract/scrape the value of 1 Dogecoin from the website, I decided to take the route of directly fetching the text value from the XPath of whichever element on this page contains the same. lxml serves the purpose for that job. requests is another library in python which is needed to make HTTP requests. I will explain the use of this two shortly.

Specifying our URL

In the above code snippet, I specified the URL from which we will scrap our data.

Making a GET request to the URL

As you can see, I am hitting a GET request to the same page.

Getting the DOM tree

I parse the entire content into a string.

Getting the text value of the element by specifying its XPath

As you can see, in the above snippet, I fetched the value from the element by specifying its XPath.

Hitting a POST request to CallMeBot’s API

In the above snippet, I made a post request to a bot (CallMeBot API) to send me the value of 1 Dogecoin personally on WhatsApp. For more information on how to set up everything and use their API, please refer to their website: https://www.callmebot.com/.

By running this script, you will get a notification on your personal WhatsApp from this bot. I wanted my Windows machine to run this script automatically at an interval of 6 hrs. a day so that I get notified automatically when I am working on something else. So, I created a bat script for that which will run this python script. After that, I created a task in the task scheduler, which will run this bat script at an interval of 6 hrs. a day.

Though it is a small script, I wanted to share with you guys, especially those who are absolute beginners, how to do these kinds of small automation, by using Python.

That’s all for this article. Thank you, everyone, for taking your time out to read the same.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Tirthya Kamal Dasgupta
Tirthya Kamal Dasgupta

Written by Tirthya Kamal Dasgupta

Senior Automation Engineer at BAAR Technologies (Formerly Allied Media Inc.). Full Stack Developer. Web Development and Process Automation enthusiast.

No responses yet

Write a response