<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sunil Aleti's Blog]]></title><description><![CDATA[Sunil Aleti's Blog]]></description><link>https://blog.sunilaleti.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 12 May 2026 15:12:16 GMT</lastBuildDate><atom:link href="https://blog.sunilaleti.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Automating my Gym slot Reservation]]></title><description><![CDATA[I'm a Graduate student at UT Arlington. I always feel that taking care of both physically and mentally are essential to our success. So, I start my daily routine at Fitness Recreation Center (gym) and registering slots daily is a hassle and due to co...]]></description><link>https://blog.sunilaleti.dev/automating-my-gym-slot-reservation</link><guid isPermaLink="true">https://blog.sunilaleti.dev/automating-my-gym-slot-reservation</guid><category><![CDATA[Python]]></category><category><![CDATA[selenium]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Sun, 28 Mar 2021 02:41:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1616844293043/25Eu4l2xR.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I'm a Graduate student at UT Arlington. I always feel that taking care of both physically and mentally are essential to our success. So, I start my daily routine at Fitness Recreation Center (gym) and registering slots daily is a hassle and due to covid the gym slots are very limited and I don't want to miss them. </p>
<p>So I have written a python script that automatically registers my gym slot every day</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616833797811/cr3mTCI_U.png" alt="Screen Shot 2021-03-27 at 3.29.30 AM.png" /></p>
<h3>Creating and Deploying a python script on Heroku.com</h3>

<p>Prerequisites:</p>
<ul>
<li>Python</li>
<li>Selenium</li>
<li>webdriver (I used Chrome webdriver)</li>
</ul>
<p>Let's Begin:</p>
<p><strong>Step 1 :</strong></p>
<p>import all necessary modules</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> selenium <span class="hljs-keyword">import</span> webdriver
<span class="hljs-keyword">from</span> selenium.webdriver.common.keys <span class="hljs-keyword">import</span> Keys
<span class="hljs-keyword">from</span> time <span class="hljs-keyword">import</span> sleep
<span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> environ
</code></pre>
<p><strong>Step 2:</strong></p>
<p>Enter the location of Chrome Webdriver and assign it to the <strong>browser</strong> variable</p>
<pre><code class="lang-python">browser=webdriver.Chrome(<span class="hljs-string">"/Users/sunilaleti/Documents/chromedriver"</span>)
</code></pre>
<p><strong>Step 3:</strong></p>
<p>There are few steps to register, i.e opening the portal, authentication(email and password) and slot booking.</p>
<p>we have <code>broswer.get()</code> to open the webpage and for the authentication steps we need to grab the XPath of that element</p>
<p>To grab Xpath of an element:
    inspect &gt;&gt; copy &gt;&gt; copy Xpath</p>
<iframe src="https://giphy.com/embed/ho6UwVDsZikK5XKqf2" width="480" height="256" class="giphy-embed"></iframe><p><a href="https://giphy.com/gifs/ho6UwVDsZikK5XKqf2"></a></p>

<pre><code class="lang-python"><span class="hljs-comment"># to click on sign in button</span>
browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="divLoginOptions"]/div[2]/div[2]/div/button'</span>).click()

<span class="hljs-comment"># to enter my email for authentication</span>
browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="i0116"]'</span>).send_keys(environ.get[<span class="hljs-string">"Email"</span>])
browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="idSIButton9"]'</span>).click()

<span class="hljs-comment"># to enter my password</span>
browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="i0118"]'</span>).send_keys(environ.get[<span class="hljs-string">"Password"</span>])

<span class="hljs-comment"># to click on submit</span>
browser.find_element_by_xpath(<span class="hljs-string">'/html/body/div/form[1]/div/div/div[2]/div/div/div[1]/div[2]/div[2]/div/div[2]/div/div[3]/div[2]/div/div/div/div/input'</span>).click()

<span class="hljs-comment"># to scroll the window</span>
browser.execute_script(<span class="hljs-string">"window.scrollTo(0,document.body.scrollHeight)"</span>)

<span class="hljs-comment"># to book gym slot</span>
browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="divBookingSlots"]/div/div[1]/div/button'</span>).click()
</code></pre>
<p></p><h4>Source Code:</h4><p></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> selenium <span class="hljs-keyword">import</span> webdriver
<span class="hljs-keyword">from</span> selenium.webdriver.common.keys <span class="hljs-keyword">import</span> Keys
<span class="hljs-keyword">from</span> time <span class="hljs-keyword">import</span> sleep
<span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> environ


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">Booking</span>():</span>
     browser=webdriver.Chrome(<span class="hljs-string">"/Users/sunilaleti/Documents/chromedriver"</span>) <span class="hljs-comment">#Enter Location of Chrome driver</span>
    browser.maximize_window()
    <span class="hljs-keyword">try</span>:
        browser.get(<span class="hljs-string">"https://reclink.uta.edu/booking/5dcc386e-4bd5-4474-80ec-a47472d3963a"</span>)
        sleep(<span class="hljs-number">2</span>)
        browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="divLoginOptions"]/div[2]/div[2]/div/button'</span>).click()
        browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="i0116"]'</span>).send_keys(environ.get[<span class="hljs-string">"Email"</span>])
        browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="idSIButton9"]'</span>).click()
        sleep(<span class="hljs-number">2</span>)
        browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="i0118"]'</span>).send_keys(environ.get[<span class="hljs-string">"Password"</span>])
        sleep(<span class="hljs-number">2</span>)
        browser.find_element_by_xpath(<span class="hljs-string">'/html/body/div/form[1]/div/div/div[2]/div/div/div[1]/div[2]/div[2]/div/div[2]/div/div[3]/div[2]/div/div/div/div/input'</span>).click()
        browser.execute_script(<span class="hljs-string">"window.scrollTo(0,document.body.scrollHeight)"</span>)
        browser.find_element_by_xpath(<span class="hljs-string">'//*[@id="divBookingSlots"]/div/div[1]/div/button'</span>).click()
        print(<span class="hljs-string">"Booked Successfully"</span>)

    <span class="hljs-keyword">except</span>:
        print(<span class="hljs-string">"Booking Failed"</span>)

    <span class="hljs-keyword">finally</span>:
        browser.quit()

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    Booking()
</code></pre>
<p><strong>Step 4:</strong></p>
<p>We have written our python script, now we should deploy this on Heroku (which is a container-based cloud Platform as a Service (PaaS)). Developers use Heroku to deploy, manage, and scale modern apps.</p>
<p>For deploying this python script, we also need a Procfile and requirements.txt file.
Push these files to GitHub and connect to it Heroku</p>
<p>You can get these files from my <a href="https://github.com/aletisunil/AutomateGymSlot">GitHub repo</a></p>
<p>And in order deploy selenium script in heroku, we need to add these in our code</p>
<pre><code class="lang-python">chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get(<span class="hljs-string">"GOOGLE_CHROME_BIN"</span>)
chrome_options.add_argument(<span class="hljs-string">"--headless"</span>)
chrome_options.add_argument(<span class="hljs-string">"--disable-dev-shm-usage"</span>)
chrome_options.add_argument(<span class="hljs-string">"--no-sandbox"</span>)
browser = webdriver.Chrome(executable_path=environ.get(<span class="hljs-string">"CHROMEDRIVER_PATH"</span>), options=chrome_options)
</code></pre>
<p>Add these values in <strong>Config Vars</strong>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616841468319/nyZMfDbbh.png" alt="Screen Shot 2021-03-27 at 5.37.31 AM.png" /></p>
<p><strong>Step 5:</strong></p>
<p>Add <strong>Heroku Scheduler</strong> add-on to schedule this python script to execute everyday </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616841718807/CZQO5rSEm.png" alt="Screen Shot 2021-03-27 at 5.41.46 AM.png" /></p>
<p><strong>That's it</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616843826866/b43Pf2Fc2.jpeg" alt="B897E7F5-0148-487A-AD7F-DDDD50E3D986.jpg" /></p>
<div class="hn-embed-widget" id="buymeacoffee"></div><div class="hn-embed-widget" id="links"></div>]]></content:encoded></item><item><title><![CDATA[How to change Twitter Source Label]]></title><description><![CDATA[You might have seen some people using completely different source labels.

Well, today we will see how to change the Twitter source label
First, we need to have a Twitter developer account, if you don't have.
1) Just navigate to Twitter Developer web...]]></description><link>https://blog.sunilaleti.dev/how-to-change-twitter-source-label-1</link><guid isPermaLink="true">https://blog.sunilaleti.dev/how-to-change-twitter-source-label-1</guid><category><![CDATA[Python]]></category><category><![CDATA[Twitter]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Tue, 02 Mar 2021 23:32:55 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809058491/NYxLs_0O6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You might have seen some people using completely different source labels.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809038091/rHgdJNDzF.jpeg" alt="Alt Text" /></p>
<p>Well, today we will see how to change the Twitter source label</p>
<p>First, we need to have a Twitter developer account, if you don't have.</p>
<p><b>1) </b>Just navigate to <a target="_blank" href="https://developer.twitter.com/en">Twitter Developer website</a></p>
<p><b>2) </b>Just fill out the form with details about ‘what you want to do with their API’. This process may take like 10 minutes and you will get a verification email instantly once you submitted the form.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809039814/kWamXtiIT.png" alt="Alt Text" /></p>
<hr />

<p>After getting approval from Twitter. Now we can create an app</p>
<p><b>1) </b>Open this <a target="_blank" href="https://developer.twitter.com/en/portal/projects-and-apps">link</a> and click on "create app"</p>
<p><b>2) </b>Give your app a name and this name will be shown on your tweets as a source label. And you can't name an app which is already present.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809041475/ZmAonobAk.png" alt="Alt Text" /></p>
<p><b>3) </b>Next, you will be redirected to API keys, tokens and click on "App Settings"</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809042953/Yiq7s4zzo.png" alt="Alt Text" /></p>
<p><b>4) </b>Now scroll down to the App permissions section and change the option from “Read” to “Read and Write” and click on Save.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809044468/vz88uV3zr.png" alt="Alt Text" /></p>
<p><b>5) </b>Scroll down to <b>Authentication settings</b> and turn on 3rd party authentication. It also asks for your website link, you can use your Instagram profile or your Twitter profile.
Then click on Save.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809045980/-DHD26onp.png" alt="Alt Text" /></p>
<p><b>6) </b>Now scroll to the top, and click on the option called <b>” Keys and Tokens”</b>. Click on it and there you can see your Twitter API keys and Access Tokens by click on the <b>“view keys”</b> button and <b>“generate”</b> button respectively.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809047594/KtQZLBoq0.png" alt="Alt Text" /></p>
<p><b>7) </b>Now you have access to Twitter APIs, to create a Twitter app, you need to download Python.</p>
<p><b>8) </b>Now, open the file location of where you have installed python and navigate to "Scripts" folder</p>
<pre><code class="lang-python">C:\Users\<span class="hljs-string">"YourUsername"</span>\AppData\Local\Programs\Python\Python37\Scripts
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809049368/KzJJgcePb.png" alt="Alt Text" /></p>
<p><b>9) </b>Now, Open Command Prompt, and type cd, give space and paste your python file location and click enter</p>
<pre><code class="lang-python">cd C:\Users\<span class="hljs-string">"YourUsername"</span>\AppData\Local\Programs\Python\Python37\Scripts
</code></pre>
<p><b>10) </b>Now type the command and hit enter</p>
<pre><code class="lang-python">pip install tweepy
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809051644/5f1OseBij.png" alt="Alt Text" /></p>
<p><b>11) </b>Once installed, close the command prompt. Now in the python scripts folder, right-click and click on New &gt; text document to create a new document.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809053752/QSXHA7iP5.png" alt="Alt Text" /></p>
<p><b>12) </b>Now open that document and paste this code inside</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> tweepy
auth = tweepy.OAuthHandler(<span class="hljs-string">"CONSUMER KEY HERE"</span>, <span class="hljs-string">"CONSUMER KEY SECRET HERE"</span>)
auth.set_access_token(<span class="hljs-string">"ACCESS TOKEN HERE"</span>, <span class="hljs-string">"ACCESS TOKEN SECRET HERE"</span>)
api = tweepy.API(auth)
tweet = input(<span class="hljs-string">" "</span>)
api.update_status(status =(tweet))
<span class="hljs-keyword">print</span> (<span class="hljs-string">"Done!"</span>)
</code></pre>
or

<p>If you want to tweet with a media file like photo or video, you can use the below code</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> tweepy
auth = tweepy.OAuthHandler(<span class="hljs-string">"CONSUMER KEY HERE"</span>, <span class="hljs-string">"CONSUMER KEY SECRET HERE"</span>)
auth.set_access_token(<span class="hljs-string">"ACCESS TOKEN HERE"</span>, <span class="hljs-string">"ACCESS TOKEN SECRET HERE"</span>)
api = tweepy.API(auth)
tweet = input(<span class="hljs-string">""</span>)
<span class="hljs-comment">#image location</span>
image=<span class="hljs-string">"C:/Users/facadmin1/Downloads/introdev.PNG"</span>  
api.update_with_media(image, tweet)
<span class="hljs-keyword">print</span> (<span class="hljs-string">"Done!"</span>)
</code></pre>
or

<p>To reply to tweet with your custom source label then copy the link of the tweet that you want to reply for
https://twitter.com/aleti_sunil/status/1356776567154876416 and last "1356776567154876416" is the tweet id</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> tweepy
auth = tweepy.OAuthHandler(<span class="hljs-string">"CONSUMER KEY HERE"</span>, <span class="hljs-string">"CONSUMER KEY SECRET HERE"</span>)
auth.set_access_token(<span class="hljs-string">"ACCESS TOKEN HERE"</span>, <span class="hljs-string">"ACCESS TOKEN SECRET HERE"</span>)
api = tweepy.API(auth)
tweet = input(<span class="hljs-string">""</span>)
api.update_status(tweet, in_reply_to_status_id = tweetid)
<span class="hljs-keyword">print</span> (<span class="hljs-string">"Done!"</span>)
</code></pre>
<p>Now replace the placeholders with your twitter APIs. Remember that there are 4 APIs to change – API Key, API Secret Key, Access Token, and Access Token Secret.
Once done, it should look like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809055494/EQ04BINAi.jpeg" alt="Alt Text" /></p>
<p><b>13) </b>Now save the file and name it anything, but change the save as type to “All files” and add “.py” at the end of the file name to save it as a python file and click save.</p>
<p><b>14) </b>Now open that .py file you just made. That’s it, you can type anything in this command line and click enter.
It will be tweeted as a new tweet. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614809057305/E6vLgSW5a.png" alt="Alt Text" /></p>
<p>That's it. Hola you finally did it</p>
<p>If you still have any queries, check out the video</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=otwEZXrC8O0">https://www.youtube.com/watch?v=otwEZXrC8O0</a></div>
<p>Hope it's useful</p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[Some AI-based websites]]></title><description><![CDATA[We all know, Artificial Intelligence (AI) is one of the most transformative tech evolutions of our times.
Well, if you still not aware of what AI is?
It is the simulation of human intelligence in machines that are programmed to think like humans and ...]]></description><link>https://blog.sunilaleti.dev/some-ai-based-websites</link><guid isPermaLink="true">https://blog.sunilaleti.dev/some-ai-based-websites</guid><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Mon, 08 Feb 2021 09:11:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827260704/QBJZ8L3LN.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We all know, Artificial Intelligence (AI) is one of the most transformative tech evolutions of our times.</p>
<p>Well, if you still not aware of what AI is?
It is the simulation of human intelligence in machines that are programmed to think like humans and mimic their actions. </p>
<p></p><h2>Here are some boggling sites</h2><br /><p></p>
<p></p><h4><a href="https://quickdraw.withgoogle.com/" target="_blank"> Quick Draw</a></h4>
This site allows you to draw doodles and site makes a guess about it using AI. This may not be 100% accurate but keeps on improving itself through Machine Learning.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827220847/oGvP7MCiq.png" alt="Alt Text" /><br /><p></p>
<p></p><h4><a href="https://experiments.withgoogle.com/ai/ai-duet/view/" target="_blank"> AI Duet</a></h4>
This site has a digital piano that responds to your tune. Helpful for making something creative
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827223281/tWL77xc3c.png" alt="Alt Text" /><br /><p></p>
<p></p><h4><a href="https://thing-translator.appspot.com/" target="_blank">Thing Translator</a></h4>
This site allows you to scan an object through the camera and guess it using its AI Mechanism 
<br /><p></p>
<p></p><h4><a href="https://app.inferkit.com/generate" target="_blank">Article Writer</a></h4>
You just have to type some info about the topic in the given box, select words length and this site generates article
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827225448/Buh5yU_2u.png" alt="Alt Text" /><br /><p></p>
<p></p><h4><a href="https://icons8.com/upscaler" target="_blank">Icons 8 upscaler</a></h4>
This site holds the capacity to enlarge an image up to 8x and change any blurry image to the sharper one. It uses state of the Art AI technology to analyze the image and make it clear
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827227783/g31QHrd9o.png" alt="Alt Text" />
<br /><p></p>
<p></p><h4><a href="https://thispersondoesnotexist.com/" target="_blank">This Person does not exist</a></h4>
This site allows you to generate an image of a person who doesn't actually exist in this world.
<br /><p></p>
<p></p><h4><a href="https://affinelayer.com/pixsrv/" target="_blank">Pix2Pix</a></h4>
You can now turn simple line drawings into beautiful works of art. Sketch a simple line drawing and watch the pix2pix AI automatically transform your creation into cats, buildings or shoes.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827230260/d0UmvCT_2.png" alt="Alt Text" /><br /><p></p>
<p></p><h4><a href="http://evenstranger.pw/" target="_blank">Even Stranger Things</a></h4>
A fun generator that uses AI image recognition to transform whatever image you upload into a Stranger Things poster.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827248691/CsLB4kXTG.png" alt="Alt Text" /><br /><p></p>
<p></p><h4><a href="https://krisp.ai/" target="_blank">Krisp</a></h4>
Krisp is an AI-powered noise cancelling app that removes background noise from your calls with one click. With a single button, helps you to have a productive and professional conferencing experience without background noise.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827251400/qmvI-R2k-.png" alt="Alt Text" /><br /><p></p>
<p></p><h4><a href="https://github.com/NVIDIA/FastPhotoStyle" target="_blank">FastPhotoStyle</a></h4>
Earlier this year, NVIDIA released a new AI algorithm called FastPhotoStyle that can transfer the style from any photo to a different image, producing impressive, photo-realistic results.<p></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827253969/MXJ37Lkb7.png" alt="Alt Text" /><br /></p>
<p></p><h4><a href="https://research.google.com/semantris/" target="_blank">Semantris</a></h4>
Created by Google, Semantris is a set of online word association games powered by machine learning, natural language understanding (NLP) technology.<p></p>
<p>Each time you enter a clue, the model looks at the words in play and selects the one it thinks is most related. The model learned the connections between words after being fed billions of conversational text samples on the internet.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827256874/py2alNU2M.png" alt="Alt Text" /><br /></p>
<p></p><h4><a href="https://books.google.com/talktobooks/" target="_blank">Talk to Books</a></h4>
Google Research has developed multiple activities to teach AI the art of human conversation. In Talk to Books, you can type in any statement or a question, and the model will scan over 100,000 books to find a variety of responses based on your input.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1612827259305/OAVdvAdmB.png" alt="Alt Text" /><br /><br /><p></p>
Feel free to add any websites which boggled your brains too :)










]]></content:encoded></item><item><title><![CDATA[Building a PDF Locker GUI Application]]></title><description><![CDATA[I'm a Indian and I recently moved to the USA to pursue my Master's degree at UT Arlington. So I need to carry some essential documents digitally like passport, health reports and other Government id's to be on the safer side and I don't want others t...]]></description><link>https://blog.sunilaleti.dev/guiapplication</link><guid isPermaLink="true">https://blog.sunilaleti.dev/guiapplication</guid><category><![CDATA[Python]]></category><category><![CDATA[GUI]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Sun, 24 Jan 2021 01:15:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1611450665220/-6GZi85ov.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I'm a <strong>Indian</strong> and I recently moved to the <strong>USA</strong> to pursue my Master's degree at <strong>UT Arlington</strong>. So I need to carry some essential documents digitally like passport, health reports and other Government id's to be on the safer side and I don't want others to have my sensitive information. So I thought of encrypting these files with a password so that only I can see. </p>
<p>So I started building a GUI Application which encrypts these files.</p>
<p>Well, I'm using two major modules for this project,</p>
<ul>
<li>
<b>PyPDF2</b> - Which helps us to extract information, merging documents and encrypting documents etc...

Simply run <b>pip install PyPDF2</b> to install this module.
</li>
<li>
<b>Tkinter</b> - To create GUI application and it's the only framework built into the Python standard library.
</li>
</ul>

<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/5a6jkqa95by19lh9nzuu.png" alt="Alt Text" /></p>
<p>Before building a GUI Application, we will see how easy it is to encrypt files using PyPDF2 module</p>
<p><b>Code to encrypt files</b></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> PyPDF2

<span class="hljs-comment">#Locate pdf file inside PdfFileReader funtion</span>
pdf_reader = PyPDF2.PdfFileReader(pdf_file)
pdf_writer = PyPDF2.PdfFileWriter()
<span class="hljs-keyword">for</span> page_num <span class="hljs-keyword">in</span> range(pdf_reader.numPages):
    pdf_writer.addPage(pdf_reader.getPage(page_num))
<span class="hljs-comment">#encrypt method encrypts files with given password</span>
pdf_writer.encrypt(<span class="hljs-string">"password"</span>)

<span class="hljs-comment">#create a pdf file and make it in wb mode           </span>
result_pdf = open(<span class="hljs-string">'Lockedfile.pdf'</span>,<span class="hljs-string">'wb'</span>)  
pdf_writer.write(result_pdf)
<span class="hljs-comment">#Close the file</span>
result_pdf.close()
</code></pre>
<p>Now we will build a GUI Application using Tkinter (has a bigger community which compared to other GUI frameworks)</p>
<p><b>Code to build GUI App</b></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> tkinter <span class="hljs-keyword">as</span> tk
<span class="hljs-keyword">from</span> tkinter <span class="hljs-keyword">import</span> messagebox
<span class="hljs-keyword">import</span> PyPDF2
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image,ImageTk
<span class="hljs-keyword">from</span> tkinter.filedialog <span class="hljs-keyword">import</span> askopenfile

root = tk.Tk()
root.title(<span class="hljs-string">"PDF Locker"</span>)

canvas =  tk.Canvas(root,width=<span class="hljs-number">600</span>,height=<span class="hljs-number">300</span>)
canvas.grid(columnspan=<span class="hljs-number">3</span>)

<span class="hljs-comment">#logo</span>
logo = Image.open(<span class="hljs-string">'/Users/sunilaleti/Desktop/logo.png'</span>)
logo = ImageTk.PhotoImage(logo)
logo_label = tk.Label(image=logo)
logo_label.image=logo
logo_label.grid(column=<span class="hljs-number">1</span>,row=<span class="hljs-number">0</span>)

<span class="hljs-comment">#instructions</span>
instructions=tk.Label(root,text=<span class="hljs-string">"Enter a password and select a pdf to encrypt\n"</span>)
instructions.grid(columnspan=<span class="hljs-number">3</span>,column=<span class="hljs-number">0</span>,row=<span class="hljs-number">1</span>)

<span class="hljs-comment">#Creating a input field for password </span>
password=tk.Entry(root,show=<span class="hljs-string">"*"</span>,width=<span class="hljs-number">15</span>)
password.grid(column=<span class="hljs-number">1</span>,row=<span class="hljs-number">2</span>)

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">open_file</span>():</span>
    pdf_file=askopenfile(parent=root,mode=<span class="hljs-string">"rb"</span>,title=<span class="hljs-string">"choose a file"</span>,filetypes=[(<span class="hljs-string">"PDF Files"</span>,<span class="hljs-string">" *.pdf"</span>)])
    FileName=file.name.split(<span class="hljs-string">"."</span>)[<span class="hljs-number">0</span>]
    <span class="hljs-keyword">if</span> pdf_file <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
        pdf_reader = PyPDF2.PdfFileReader(pdf_file)
        pdf_writer = PyPDF2.PdfFileWriter()
        <span class="hljs-keyword">for</span> page_num <span class="hljs-keyword">in</span> range(pdf_reader.numPages):
            pdf_writer.addPage(pdf_reader.getPage(page_num))
        pdf_writer.encrypt(password.get())
        encryptedFile=FileName+<span class="hljs-string">"_Encrypted.pdf"</span>
        result_pdf = open(encryptedFile,<span class="hljs-string">'wb'</span>)  

        pdf_writer.write(result_pdf)
        result_pdf.close()
        <span class="hljs-comment">#To clear input field </span>
        password.delete(<span class="hljs-number">0</span>, <span class="hljs-string">'end'</span>)
        <span class="hljs-comment">#Message box to show success message</span>
        messagebox.showinfo(<span class="hljs-string">"Success"</span>,<span class="hljs-string">"File encrypted successfully"</span>)
    <span class="hljs-keyword">else</span>:
        messagebox.showerror(<span class="hljs-string">"Failed"</span>,<span class="hljs-string">"Unable to encrypt file"</span>)



<span class="hljs-comment">#Creating "Browse file" button using tk.Button</span>
browse_btn=tk.Button(root,text=<span class="hljs-string">"Browse file"</span>,command=<span class="hljs-keyword">lambda</span>:open_file(),width=<span class="hljs-string">"15"</span>,height=<span class="hljs-string">"2"</span>)
browse_btn.grid(column=<span class="hljs-number">1</span>,row=<span class="hljs-number">4</span>)

canvas=tk.Canvas(root,width=<span class="hljs-number">600</span>,height=<span class="hljs-number">250</span>)
canvas.grid(columnspan=<span class="hljs-number">3</span>)

root.mainloop()
</code></pre>
<p>The file will be encrypted and you have to enter the password to access it
<img src="https://dev-to-uploads.s3.amazonaws.com/i/jltse5whkuumlb208cze.png" alt="Alt Text" /></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=Md61aBTZOWQ">https://www.youtube.com/watch?v=Md61aBTZOWQ</a></div>
<p>If you like my content, please consider supporting me</p>
<div class="hn-embed-widget" id="buymeacoffee"></div><p>Hope it's useful</p>
<p>A ❤️ would be Awesome 😊</p>
]]></content:encoded></item><item><title><![CDATA[What is Dimensionality Reduction?]]></title><description><![CDATA[In Machine Learning classification problems, there are often too many factors on the basis of which the final classification is done. These factors are basically variables called features. The higher the number of features, the harder it gets to visu...]]></description><link>https://blog.sunilaleti.dev/what-is-dimensionality-reduction</link><guid isPermaLink="true">https://blog.sunilaleti.dev/what-is-dimensionality-reduction</guid><category><![CDATA[Machine Learning]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Fri, 04 Dec 2020 07:42:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1607067498772/QBpYrY9LN.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In Machine Learning classification problems, there are often too many factors on the basis of which the final classification is done. These factors are basically variables called features. The higher the number of features, the harder it gets to visualize the training set and then work on it. Sometimes, most of these features are correlated, and hence redundant. </p>
<p>Few algorithms do not  perform well when you have huge amounts of data like KNN, Decision trees etc.. So by reducing them it will help the algorithms to perform well. And we cannot visualize data more than 3D so by reducing data to 2D or 3D will allow us to plot and observe patterns more clearly.</p>
<p>This technique also removes multicollinearity by removing redundant features. Let's see we have N variables in the dataset where we reduce it to K variables (K&lt;&lt;N)</p>
<p><strong>There are two components of dimensionality reduction:</strong></p>
<ul>
<li><strong>Feature selection:</strong> In this, we try to find a subset of the original set of variables, or features, to get a smaller subset which can be used to model the problem. It usually involves three ways:<ol>
<li>Filter</li>
<li>Wrapper</li>
<li>Embedded</li>
</ol>
</li>
<li><strong>Feature extraction:</strong> This reduces the data in a high dimensional space to a lower dimension space, i.e. a space with lesser no. of dimensions.</li>
</ul>
<p><strong>Advantages of Dimensionality Reduction</strong></p>
<ul>
<li>It helps in data compression, and hence reduced storage space.</li>
<li>It reduces computation time.</li>
<li>Helps to remove noise so that we can improve the performance of models</li>
<li>It also helps remove redundant features, if any.</li>
</ul>
<p><strong>Disadvantages of Dimensionality Reduction</strong></p>
<ul>
<li>It may lead to some amount of data loss.</li>
<li>PCA tends to find linear correlations between variables, which is sometimes undesirable.</li>
<li>PCA fails in cases where mean and covariance are not enough to define datasets.</li>
</ul>
<p><strong>Different Dimensionality Reduction Techniques</strong></p>
<p><strong><em>Linear Dimensionality Reduction Methods</em></strong></p>
<ul>
<li>PCA</li>
<li>Factor Analysis</li>
<li>LDA</li>
</ul>
<p><strong><em>Non Linear Dimensionality Reduction Methods</em></strong></p>
<ul>
<li>MDS</li>
<li>t-SNE</li>
<li>HLLE</li>
<li>Spectral Embedding</li>
</ul>
<p><strong><em>Other techniques like</em></strong></p>
<ul>
<li>Auto encoders</li>
<li>Missing value ratio</li>
<li>Low variance filter</li>
</ul>
<div class="hn-embed-widget" id="links"></div><div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[How to Change Background of an image using PixelLib]]></title><description><![CDATA[Before talking about "What is Pixellib and what does it do?", let's talk about Image Segmentation
Image Segmentation
 It is the process of partitioning a digital image into multiple segments. The goal of segmentation is to simplify and/or change the ...]]></description><link>https://blog.sunilaleti.dev/how-to-change-background-of-an-image-using-pixellib</link><guid isPermaLink="true">https://blog.sunilaleti.dev/how-to-change-background-of-an-image-using-pixellib</guid><category><![CDATA[Python]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[Computer Vision]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Sat, 14 Nov 2020 20:42:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1605386295377/S_CrLoJGI.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before talking about "<strong>What is Pixellib</strong> and <strong>what does it do?</strong>", let's talk about Image Segmentation</p>
<h3 id="image-segmentation">Image Segmentation</h3>
<p> It is the process of partitioning a digital image into multiple segments. The goal of segmentation is to simplify and/or change the representation of an image into something that is more meaningful and easier to analyze. Image segmentation is typically used to locate objects and boundaries (lines, curves, etc.) in images. It has a lot of amazing applications that solve different computer vision problems.</p>
<p><strong>PixelLib</strong> is a library created to ensure easy integration of image segmentation in real-life applications. PixelLib now supports a feature known as image tuning.</p>
<h3 id="what-is-image-tuning">What is Image tuning?</h3>
<p>Nothing but changing the background of an image with a custom background or adding a distinct color to the background or converting a background to grayscale. And we make use of <strong>deeplabv3+</strong> model trained on <strong>pascalvoc</strong> dataset. The model supports 20 common object categories, which means you can change the background of these objects in images.</p>
<p>The model supports the following objects:
person, bus, car, aeroplane, bicycle, motorbike, bird, boat, bottle,  cat, chair, cow, dinning table, dog, horse, sheep, sofa, train, tv</p>
<p>We should install pixellib and its dependencies
 </p><ul><p></p>
<p><li>pip3 install pixellib</li>
 <li>pip3 install tensorflow</li>
</p></ul><p></p>
<p>For demonstration purposes, let me select one of my pictures and also a custom image   </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605384056996/gm9nCnMoq.png" alt="20201115_012958_0000.png" /></p>
<p><strong>Code to change the background of an image with a picture</strong></p>
<p>Now we changing the background of the 1st image with the 2nd image</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pixellib
<span class="hljs-keyword">from</span> pixellib.tune_bg <span class="hljs-keyword">import</span> alter_bg

change_bg = alter_bg()
change_bg.load_pascalvoc_model(<span class="hljs-string">"deeplabv3_xception_tf_dim_ordering_tf_kernels.h5"</span>)
change_bg.change_bg_img(f_image_path = <span class="hljs-string">"me.jpg"</span>,b_image_path = <span class="hljs-string">"bg.jpg"</span>, output_image_name=<span class="hljs-string">"new_img.jpg"</span>)
Image(filename=<span class="hljs-string">'new_img.jpg'</span>,width=<span class="hljs-number">300</span>,height=<span class="hljs-number">350</span>)
</code></pre>
<p>We imported pixellib, and from pixellib, we imported in the class alter_bg </p>
<p>We loaded deeplabv3+ model.</p>
<p>The function takes the following parameters:</p>
<p><strong>f_image_path</strong>: This is the foreground image, the image which background would be changed.</p>
<p><strong>b_image_path</strong>: This is the image that will be used to change the background of the foreground image.</p>
<p><strong>output_image_name</strong>: The new image with a changed background.</p>
<p>And this is the "new_img"</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605385216629/S2aIBmNWi.png" alt="20201115_014635_0000.png" /></p>
<p><strong>To blur the background of an image</strong></p>
<p>It is also possible to control how blur the background should be.</p>
<ol>
<li>low=True</li>
<li>moderate=True</li>
<li>extreme=True</li>
</ol>

<pre><code class="lang-python">change_bg.blur_bg(<span class="hljs-string">"me.jpg"</span>,extreme=<span class="hljs-literal">True</span>, output_image_name=<span class="hljs-string">"blur_img.jpg"</span>)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605384671039/YXgFe_PUO.png" alt="20201115_013810_0000.png" /></p>
<p><strong>To Grayscale the background of an image</strong></p>
<p>Grayscale the background of any image using the same lines of code with PixelLib.</p>
<pre><code class="lang-python">change_bg.gray_bg(<span class="hljs-string">"me.jpg"</span>,output_image_name=<span class="hljs-string">"gray_img.jpg"</span>)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1605385345524/dUv3gMNqE.png" alt="20201115_014855_0000.png" /></p>
<p>You can also apply these background effects on videos too</p>
<p>Refer to these resources:</p>
<p><a target="_blank" href="https://pixellib.readthedocs.io/en/latest/">https://pixellib.readthedocs.io/en/latest/</a> 
 <a target="_blank" href="https://github.com/ayoolaolafenwa/PixelLib">https://github.com/ayoolaolafenwa/PixelLib</a> </p>
<p>Hope it's useful</p>
<p>A ❤️ would be Awesome 😊</p>
<div class="hn-embed-widget" id="buymeacoffee"></div><div class="hn-embed-widget" id="links"></div>]]></content:encoded></item><item><title><![CDATA[Python Script to Sort Files based on Filetype Extensions]]></title><description><![CDATA[We download many files from the internet and whatever file type it may be, all files will be downloaded and located in the 'Downloads' folder. And it looks like clutter.
      So today we will see, how to sort files with respect to filetype extension...]]></description><link>https://blog.sunilaleti.dev/python-script-to-sort-files-based-on-filetype-extensions</link><guid isPermaLink="true">https://blog.sunilaleti.dev/python-script-to-sort-files-based-on-filetype-extensions</guid><category><![CDATA[Python]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Tue, 10 Nov 2020 11:12:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1605017422101/Fsd86Uvdk.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We download many files from the internet and whatever file type it may be, all files will be downloaded and located in the 'Downloads' folder. And it looks like clutter.
      So today we will see, how to sort files with respect to filetype extension i.e mp4, docx, pdf, exe etc
And we can use a python script to sort files with respect to filetype extension</p>
<p><b>Step 1:</b>
  In order to workaround we need some modules, and we can import them using <b>'import'</b> keyword</p>
<ul>
<li>os     - allows you to interface with the underlying operating system</li>
<li>shutil - responsible for copying and moving files respectively</li>
<li>glob   - used to retrieve files/pathnames matching a specified pattern</li>
</ul>
<p><b>Step 2:</b>
  so with the help of glob module, we retrive all files present in that path location</p>
<pre><code class="lang-python">ex: filename=glob.glob(<span class="hljs-string">"C:/Users/Aleti Sunil/Downloads/*"</span>)
</code></pre>
<p><b>Step 3:</b>
we will create lists with respect to filetype extensions</p>
<pre><code class="lang-python">documents=[<span class="hljs-string">'.pdf'</span>,<span class="hljs-string">'.docx'</span>,<span class="hljs-string">'.doc'</span>,<span class="hljs-string">'.txt'</span>]
media=[<span class="hljs-string">'.jpeg'</span>,<span class="hljs-string">'.jpg'</span>,<span class="hljs-string">'.svg'</span>,<span class="hljs-string">'.png'</span>,<span class="hljs-string">'.PNG'</span>,<span class="hljs-string">'.mp4'</span>,<span class="hljs-string">'.mp3'</span>]
setupFiles=[<span class="hljs-string">'.exe'</span>,<span class="hljs-string">'.msi'</span>]
compressedFiles=[<span class="hljs-string">'.zip'</span>]
files=[<span class="hljs-string">'.apk'</span>]
</code></pre>
<p>And specify the path locations of documents,media and setupfiles respectively</p>
<pre><code class="lang-python">DocumentsLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/documents'</span>
mediaLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/media'</span>
setupFilesLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/setupFiles'</span>
compressedFilesLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/compressedFiles'</span>
FilesLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/Files'</span>
</code></pre>
<p><b>Step 4:</b>
And this is the final step, we will extract the filetype extension using 'os.path.splitext' and moves the files with respect to filetype extension to specified location</p>
<p>And this is final code</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> glob
<span class="hljs-keyword">import</span> shutil
<span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> path
filename=glob.glob(<span class="hljs-string">"C:/Users/Aleti Sunil/Downloads/*"</span>)
documents=[<span class="hljs-string">'.pdf'</span>,<span class="hljs-string">'.docx'</span>,<span class="hljs-string">'.doc'</span>,<span class="hljs-string">'.txt'</span>]
media=[<span class="hljs-string">'.jpeg'</span>,<span class="hljs-string">'.jpg'</span>,<span class="hljs-string">'.svg'</span>,<span class="hljs-string">'.png'</span>,<span class="hljs-string">'.PNG'</span>,<span class="hljs-string">'.mp4'</span>,<span class="hljs-string">'.mp3'</span>]
setupFiles=[<span class="hljs-string">'.exe'</span>,<span class="hljs-string">'.msi'</span>]
compressedFiles=[<span class="hljs-string">'.zip'</span>]
files=[<span class="hljs-string">'.apk'</span>]
DocumentsLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/documents'</span>
mediaLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/media'</span>
setupFilesLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/setupFiles'</span>
compressedFilesLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/compressedFiles'</span>
FilesLocation=<span class="hljs-string">'C:/Users/Aleti Sunil/Downloads/Files'</span>
<span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> filename:
    <span class="hljs-keyword">if</span> os.path.splitext(file)[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> documents:
        <span class="hljs-keyword">if</span>(path.exists(DocumentsLocation)):
            shutil.move(file,DocumentsLocation)
        <span class="hljs-keyword">else</span>:
            os.mkdir(DocumentsLocation)
            shutil.move(file,DocumentsLocation)
    <span class="hljs-keyword">if</span> os.path.splitext(file)[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> media:
        <span class="hljs-keyword">if</span>(path.exists(mediaLocation)):
            shutil.move(file,mediaLocation)
        <span class="hljs-keyword">else</span>:
            os.mkdir(mediaLocation)
            shutil.move(file,mediaLocation)
    <span class="hljs-keyword">if</span> os.path.splitext(file)[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> setupFiles:
        <span class="hljs-keyword">if</span>(path.exists(setupFilesLocation)):
            shutil.move(file,setupFilesLocation)
        <span class="hljs-keyword">else</span>:
            os.mkdir(setupFilesLocation)
            shutil.move(file,setupFilesLocation)
    <span class="hljs-keyword">if</span> os.path.splitext(file)[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> compressedFiles:
        <span class="hljs-keyword">if</span>(path.exists(compressedFilesLocation)):
            shutil.move(file,compressedFilesLocation)
        <span class="hljs-keyword">else</span>:
            os.mkdir(compressedFilesLocation)
            shutil.move(file,compressedFilesLocation)
    <span class="hljs-keyword">if</span> os.path.splitext(file)[<span class="hljs-number">1</span>] <span class="hljs-keyword">in</span> files:
        <span class="hljs-keyword">if</span>(path.exists(FilesLocation)):
            shutil.move(file,FilesLocation)
        <span class="hljs-keyword">else</span>:
            os.mkdir(FilesLocation)
            shutil.move(file,FilesLocation)
</code></pre>
<p>Check out the video on how it works</p>
<iframe src="https://player.vimeo.com/video/411362595" width="640" height="361"></iframe>

<p>You can also schedule this script for every regular interval</p>
<p>Let me know if any queries</p>
<p>Happy Coding ❤️</p>
<div class="hn-embed-widget" id="buymeacoffee"></div><div class="hn-embed-widget" id="links"></div>]]></content:encoded></item><item><title><![CDATA[Web Scraping with Python]]></title><description><![CDATA[You don't need to be a guru in python, just a basics of HTML and python is sufficient for this web scraping tutorial.
Let's dive in..
The tools we're going to use are:

Request will allow us to send HTTP requests to get HTML files
BeautifulSoup will ...]]></description><link>https://blog.sunilaleti.dev/webscraping</link><guid isPermaLink="true">https://blog.sunilaleti.dev/webscraping</guid><category><![CDATA[web scraping]]></category><category><![CDATA[Python]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Sun, 08 Nov 2020 09:46:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604829152567/58RTIIB_u.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You don't need to be a guru in python, just a basics of HTML and python is sufficient for this <b>web scraping</b> tutorial.</p>
<h4 id="lets-dive-in">Let's dive in..</h4>
<p>The tools we're going to use are:</p>
<ul>
<li><b>Request</b> will allow us to send HTTP requests to get HTML files</li>
<li><b>BeautifulSoup</b> will help us parse the HTML files</li>
<li><b>Pandas</b> will help us assemble the data into a DataFrame to clean and analyze it</li>
<li><b>csv</b>(optional)- If you want to share data in csv file format</li>
</ul>

<h4 id="lets-begin">Let's Begin..</h4>
<p>In this tutorial, we're going to scrape <b><a href="https://www.imdb.com/search/title/?groups=top_1000">IMDB</a></b> website, which we can get title, year, ratings, genre etc..</p>
<p>First, we'll import the tools to build our scraper</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">import</span> csv
</code></pre>
<p>Getting the contents of webpage into <b>results</b> variable</p>
<pre><code class="lang-python">url = <span class="hljs-string">"https://www.imdb.com/search/title/?groups=top_1000"</span>
results = requests.get(url)
</code></pre>
<p>In order to make content easy to understand, we are using <b>BeautifulSoup</b> and the content is stored in <b>soup</b> variable</p>
<pre><code class="lang-python">soup = BeautifulSoup(results.text, <span class="hljs-string">"html.parser"</span>)
</code></pre>
<p>And now initializing the lists to store data</p>
<pre><code class="lang-python">titles = []        <span class="hljs-comment">#Stores the title of movie</span>
years = []         <span class="hljs-comment">#Stores the launch year of the movie</span>
time = []          <span class="hljs-comment">#Stores movie duration</span>
imdb_ratings = []  <span class="hljs-comment">#Stores the rating of the movie</span>
genre = []         <span class="hljs-comment">#Stores details regarding the genre of the movie</span>
votes = []         <span class="hljs-comment">#Store the no.of votes for the movie</span>
</code></pre>
<p>Now find the right movie container by inspecting it, and hover over the movie div, which looks like below image</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/z2p7b4j24xlggm3sk8sr.png" alt="Alt Text" /></p>
<p>And we can see 50 div with class names:<code>lister-item mode-advanced</code>
So, find all div's with that classname by</p>
<pre><code class="lang-python">movie_div = soup.find_all(<span class="hljs-string">"div"</span>, class_=<span class="hljs-string">"lister-item mode-advanced"</span>)
</code></pre>
<p><b>find_all</b> attribute extracts all the div's which has class 
name:"lister-item mode-advanced"</p>
<p>Now get into each <code>lister-item mode-advanced</code> div and get the title, year, ratings, genre, movie duration</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/a0gyg59chadij4tj86wp.png" alt="Alt Text" /></p>
<p>So we iterate every div to get title, year, ratings etc..</p>
<pre><code class="lang-python"><span class="hljs-keyword">for</span> movieSection <span class="hljs-keyword">in</span> movie_div:
</code></pre>
<h4 id="extracting-the-title">Extracting the title</h4>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/dh2m0s3o9verzg5lu54h.png" alt="Alt Text" /></p>
<p>From image, we can see that the movie name is placed under <b>div&gt;h3&gt;a</b></p>
<pre><code class="lang-python">name = movieSection.h3.a.text  <span class="hljs-comment">#we're iterating those divs using &lt;b&gt;movieSection&lt;b&gt; variable</span>
titles.append(name) <span class="hljs-comment">#appending the movie names into &lt;b&gt;titles&lt;/b&gt; list</span>
</code></pre>
<h4 id="extracting-year">Extracting Year</h4>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/y8yfx5mdglbqqv8xgpsy.png" alt="Alt Text" /></p>
<p>From image, we can see that the movie launch year is placed under div&gt;h3&gt;span(class name="lister-item-year") and we extract it using <b>text</b> keyword</p>
<pre><code class="lang-python">year = movieSection.h3.find(<span class="hljs-string">"span"</span>, class_=<span class="hljs-string">"lister-item-year"</span>).text
years.append(year)   <span class="hljs-comment">#appending into years list</span>
</code></pre>
<p>Similarly, we can get ratings, genre, movieDuration w.r.t classname</p>
<pre><code class="lang-python">ratings = movieSection.strong.text
imdb_ratings.append(ratings)   <span class="hljs-comment">#appending ratings into list</span>
category = movieSection.find(<span class="hljs-string">"span"</span>, class_=<span class="hljs-string">"genre"</span>).text.strip()
genre.append(category)         <span class="hljs-comment">#appending category into Genre list</span>
runTime = movieSection.find(<span class="hljs-string">"span"</span>, class_=<span class="hljs-string">"runtime"</span>).text
time.append(runTime)           <span class="hljs-comment">#appending runTime into time list</span>
</code></pre>
<h4 id="extracting-votes">Extracting votes</h4>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/59fniprg1lixxk2geu64.png" alt="Alt Text" /></p>
<p>As from the image, we can see that we have two span tags with classname="nv". So, for votings we need to consider <b>nv[0]</b> and for gross collections <b>nv[1]</b></p>
<pre><code class="lang-python">nv = movieSection.find_all(<span class="hljs-string">"span"</span>, attrs={<span class="hljs-string">"name"</span>: <span class="hljs-string">"nv"</span>})
vote = nv[<span class="hljs-number">0</span>].text
votes.append(vote)
</code></pre>
<p><b>Now we will build a DataFrame with pandas</b>
To store the data we have to create nicely into a table, so that we can really understand
And we can do it..</p>
<pre><code class="lang-python">movies = pd.DataFrame(
    {
        <span class="hljs-string">"Movie"</span>: titles,
        <span class="hljs-string">"Year"</span>: years,
        <span class="hljs-string">"RunTime"</span>: time,
        <span class="hljs-string">"imdb"</span>: imdb_ratings,
        <span class="hljs-string">"Genre"</span>: genre,
        <span class="hljs-string">"votes"</span>: votes,
    }
)
</code></pre>
<p>And now let's print the dataframe</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/w9cos6fh7kghxzqe7w3n.png" alt="Alt Text" /></p>
<p>As we can see on row 16 and 25, there is some inconsistent of data. So we need to clean</p>
<pre><code class="lang-python"> movies[<span class="hljs-string">"Year"</span>] = movies[<span class="hljs-string">"Year"</span>].str.extract(<span class="hljs-string">"(\\d+)"</span>).astype(int) <span class="hljs-comment">#Extracting only numerical values. so we can commit "I"</span>
 movies[<span class="hljs-string">"RunTime"</span>] = movies[<span class="hljs-string">"RunTime"</span>].str.replace(<span class="hljs-string">"min"</span>, <span class="hljs-string">"minutes"</span>) <span class="hljs-comment">#replacing &lt;b&gt;min&lt;/b&gt; with &lt;b&gt;minutes&lt;/b&gt;</span>
 movies[<span class="hljs-string">"votes"</span>] = movies[<span class="hljs-string">"votes"</span>].str.replace(<span class="hljs-string">","</span>, <span class="hljs-string">""</span>).astype(int) <span class="hljs-comment">#removing "," to make it more clear</span>
</code></pre>
<p>And now after cleaning we will see, how it looks</p>
<pre><code class="lang-python">print(movies)
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/j81csuuq2iuujmugtr21.png" alt="Alt Text" /></p>
<p>You can also export the data in <b>.csv</b> file format.
In order to export, 
Create a file with <b>.csv</b> file extension</p>
<pre><code class="lang-python">movies.to_csv(<span class="hljs-string">r"C:\Users\Aleti Sunil\Downloads\movies.csv"</span>, index=<span class="hljs-literal">False</span>, header=<span class="hljs-literal">True</span>)
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/tw1e7uwf8m60pzcahe8e.png" alt="Alt Text" /></p>
<p>You can get Final code from my <a href="https://github.com/aletisunil/Scraping_IMDB/blob/master/IMDB.py">Github repo</a></p>
<p>Hope it's useful</p>
<div class="hn-embed-widget" id="buymeacoffee"></div><div class="hn-embed-widget" id="links"></div>]]></content:encoded></item><item><title><![CDATA[How to Build a Chrome Extension]]></title><description><![CDATA[Chrome extensions are small HTML, CSS and JavaScript apps that we can install in the chrome browser.
In this tutorial, We are going to build an extension that allows users to get covid19 case details based on the country selected.


Step 1: Create a ...]]></description><link>https://blog.sunilaleti.dev/chromeextension</link><guid isPermaLink="true">https://blog.sunilaleti.dev/chromeextension</guid><category><![CDATA[2Articles1Week]]></category><category><![CDATA[chrome extension]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Fri, 30 Oct 2020 23:16:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604099156722/HBdynU6fs.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Chrome extensions are small HTML, CSS and JavaScript apps that we can install in the chrome browser.</p>
<p>In this tutorial, We are going to build an extension that allows users to get covid19 case details based on the <strong>country</strong> selected.</p>
<p></p><hr />
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604098476709/ut847kghI.jpeg" alt="h8znwg5mm0a1ax96ge0p.jpg" /><p></p>
<p><b>Step 1:</b> Create a new directory "dist" and create files under that directory as shown in the picture</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604097741972/GO8z6Z3dR.png" alt="screely-1604097689947.png" /></p>
<p><b>Step 2:</b> Create an HTML file</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Covid 19<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"./style.css"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://unpkg.com/axios/dist/axios.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span> <span class="hljs-attr">defer</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"header"</span>&gt;</span>Covid 19<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-data"</span> <span class="hljs-attr">autocomplete</span>=<span class="hljs-string">"on"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"enter-country"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span>Enter a country name:<span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"country-name"</span> /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"search-btn"</span>&gt;</span>Search<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"result"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"loading"</span>&gt;</span>loading...<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"errors"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"data"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"result-container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>New cases: <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"todayCases"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>New deaths: <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"todayDeaths"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>Total cases: <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cases"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>Total recovered: <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"recovered"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>Total deaths: <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"deaths"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>Total tests: <span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"tests"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">center</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"safe"</span>&gt;</span>Stay Safe and Healthy<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">center</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><b>Step 3:</b> Create a js file to handle API calls</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> api = <span class="hljs-string">"https://coronavirus-19-api.herokuapp.com/countries"</span>;
<span class="hljs-keyword">const</span> errors = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".errors"</span>);
<span class="hljs-keyword">const</span> loading = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".loading"</span>);
<span class="hljs-keyword">const</span> cases = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".cases"</span>);
<span class="hljs-keyword">const</span> recovered = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".recovered"</span>);
<span class="hljs-keyword">const</span> deaths = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".deaths"</span>);
<span class="hljs-keyword">const</span> tests=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".tests"</span>);
<span class="hljs-keyword">const</span> todayCases=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".todayCases"</span>);
<span class="hljs-keyword">const</span> todayDeaths=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".todayDeaths"</span>);
<span class="hljs-keyword">const</span> results = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".result-container"</span>);
results.style.display = <span class="hljs-string">"none"</span>;
loading.style.display = <span class="hljs-string">"none"</span>;
errors.textContent = <span class="hljs-string">""</span>;
<span class="hljs-comment">// grab the form</span>
<span class="hljs-keyword">const</span> form = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".form-data"</span>);
<span class="hljs-comment">// grab the country name</span>
<span class="hljs-keyword">const</span> country = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".country-name"</span>);

<span class="hljs-comment">// declare a method to search by country name</span>
<span class="hljs-keyword">const</span> searchForCountry = <span class="hljs-keyword">async</span> countryName =&gt; {
  loading.style.display = <span class="hljs-string">"block"</span>;
  errors.textContent = <span class="hljs-string">""</span>;
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> axios.get(<span class="hljs-string">`<span class="hljs-subst">${api}</span>/<span class="hljs-subst">${countryName}</span>`</span>);
    <span class="hljs-keyword">if</span>(response.data ===<span class="hljs-string">"Country not found"</span>){ <span class="hljs-keyword">throw</span> error;  }
    loading.style.display = <span class="hljs-string">"none"</span>;
    todayCases.textContent = response.data.todayCases;
    todayDeaths.textContent = response.data.todayDeaths;
    cases.textContent = response.data.cases;
    recovered.textContent = response.data.recovered;
    deaths.textContent = response.data.deaths;
    tests.textContent =  response.data.totalTests;
    results.style.display = <span class="hljs-string">"block"</span>;
  } <span class="hljs-keyword">catch</span> (error) {
    loading.style.display = <span class="hljs-string">"none"</span>;
    results.style.display = <span class="hljs-string">"none"</span>;
    errors.textContent = <span class="hljs-string">"We have no data for the country you have requested."</span>;
  }
};

<span class="hljs-comment">// declare a function to handle form submission</span>
<span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-keyword">async</span> e =&gt; {
  e.preventDefault();
  searchForCountry(country.value);
  <span class="hljs-built_in">console</span>.log(country.value);
};

form.addEventListener(<span class="hljs-string">"submit"</span>, <span class="hljs-function"><span class="hljs-params">e</span> =&gt;</span> handleSubmit(e));
</code></pre>
<p>We have an asynchronous function called searchForCountry and within that function, we can use async-await. Async await allows us to stop executing code that is dependent, while we wait for the response from a server. By using the await keyword in front of a piece of code we can get the rest of our code to stop executing while that piece of code executes.</p>
<p>In this example, we await a response from our GET request before setting that response to our articles variable.</p>
<p>Axios is a very popular JavaScript library you can use to perform HTTP requests, that works in both Browser and Node.js platforms. It supports all modern browsers, including support for IE8 and higher. It is promise-based, and this lets us write async/await code to perform XHR requests very easily.</p>
<p></p><h4>Here are some endpoints to access data via API</h4><p></p>
<ul>
<li><a href="https://coronavirus-19-api.herokuapp.com/countries">https://coronavirus-19-api.herokuapp.com/countries</a> - To get details about all countries</li>
<li><a href="https://coronavirus-19-api.herokuapp.com/countries/india">https://coronavirus-19-api.herokuapp.com/countries/india</a> - To get covid19 cases details specific to <strong>India</strong></li>
</ul>

<p><b>Step 4:</b> You can also add css to your HTML file</p>
<p><b>Step 5:</b> Create manifest.json and add following code. This is the file that contains information on how Chrome should handle the extension.</p>
<pre><code class="lang-javascript">{
    <span class="hljs-string">"manifest_version"</span>: <span class="hljs-number">2</span>,
    <span class="hljs-string">"name"</span>: <span class="hljs-string">"Covid19"</span>,
    <span class="hljs-string">"version"</span>: <span class="hljs-string">"1.0.0"</span>,
    <span class="hljs-string">"description"</span>: <span class="hljs-string">"Provides the cases details regarding Covid19 with respective to any Country"</span>,
    <span class="hljs-string">"browser_action"</span>: {
      <span class="hljs-string">"default_popup"</span>: <span class="hljs-string">"index.html"</span>
    },
    <span class="hljs-string">"icons"</span>:{
      <span class="hljs-string">"16"</span>: <span class="hljs-string">"./icons/16covid-19.png"</span>,
      <span class="hljs-string">"64"</span>: <span class="hljs-string">"./icons/64covid-19.png"</span>,
     <span class="hljs-string">"128"</span>: <span class="hljs-string">"./icons/128covid-19.png"</span>
    },

    <span class="hljs-string">"content_security_policy"</span>: <span class="hljs-string">"script-src 'self' https://unpkg.com ; object-src 'self'"</span>
  }
</code></pre>
<p><b>manifest_version, name and version</b> are important and MUST be declared. The extension must have a manifest_version of 2 to work with the latest Chrome browsers, you can give it whatever name/version you wish.</p>
<p><img src="https://media.giphy.com/media/mo2WzZzncObfXfc49n/giphy.gif" alt="alt-txt" /></p>
<p></p><hr /><p></p>
<p></p><h2><b>Adding Extension to Chrome:</b></h2>
Go the Chrome Extensions or you can click on this <a>chrome://extensions</a> to navigate to the extension page.
Once the page is opened, click on <strong>load unpacked</strong> and locate extension package.<p></p>
<p>I recently submitted this extension for review and it's pending for approval.</p>
<p><em>Hope Google approves it</em> :) </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1604098909730/cYGYLMY8I.png" alt="2.PNG" /></p>
<p><strong>Here is the working video of Covid19 Extension</strong></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=ppFkyHGS1ys">https://www.youtube.com/watch?v=ppFkyHGS1ys</a></div>
<p><strong>Hope it's useful</strong></p>
<p><em>If you like my content, please consider supporting me</em></p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[How I texted whole movie script word by word using Selenium in Python]]></title><description><![CDATA[In this post, I will share how I texted a whole movie script word by word in Python.
Let's start by watching small demo, how its going to look at end 😅


Now lets talk,
Prerequisites:

Python
Selenium
webdriver (I used Chrome webdriver)


Step 1 :
n...]]></description><link>https://blog.sunilaleti.dev/whatsappspam</link><guid isPermaLink="true">https://blog.sunilaleti.dev/whatsappspam</guid><category><![CDATA[Python]]></category><category><![CDATA[selenium]]></category><category><![CDATA[automation]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Fri, 30 Oct 2020 16:01:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1604073257704/c67piNux7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this post, I will share how I texted a whole movie script word by word in Python.</p>
<p>Let's start by watching small demo, how its going to look at end 😅</p>
<p><a href="https://media.giphy.com/media/mCxzDkVV84GelbYdnn/giphy.gif" class="article-body-image-wrapper"><img src="https://media.giphy.com/media/mCxzDkVV84GelbYdnn/giphy.gif" alt="run the script" /></a></p>

<p>Now lets talk,
<b>Prerequisites:</b></p>
<ul>
<li>Python</li>
<li>Selenium</li>
<li>webdriver (I used Chrome webdriver)</li>
</ul>

<p><b>Step 1 :</b>
need to import webdriver, keys and sleep</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> selenium <span class="hljs-keyword">import</span> webdriver
<span class="hljs-keyword">from</span> selenium.webdriver.common.keys <span class="hljs-keyword">import</span> Keys
<span class="hljs-keyword">from</span> time <span class="hljs-keyword">import</span> sleep
</code></pre>
<p><b>Step 2 :</b>
Enter the location of Chrome Webdriver and assign it to driver variable</p>
<pre><code class="lang-python">driver=webdriver.Chrome(<span class="hljs-string">""</span>) <span class="hljs-comment"># Enter Location of Chrome driver</span>
</code></pre>
<p><b>Step 3 :</b>
I used whatsapp to send messages and I pinned the person to whom we need to send messages, so that there will not be any hustles.</p>
<pre><code class="lang-python">driver.get(<span class="hljs-string">"https://web.whatsapp.com/"</span>)
sleep(<span class="hljs-number">15</span>)
driver.find_element_by_xpath(<span class="hljs-string">"/html/body/div/div/div/div/div/div/div[1]/div/div/div[1]/div/div/div"</span>).click()
sleep(<span class="hljs-number">5</span>)
</code></pre>
<p>There should be some time where we can scan the QRcode to login, so I gave sleep(15) and that XPath is to open the chat window of that respective person</p>
<p><b>Step 4 :</b>
Now locate the movie script file, assign it to fileLocation variable and open it in reading mode</p>
<pre><code class="lang-python">fileLocation= <span class="hljs-string">""</span>  <span class="hljs-comment"># Enter location of movie script file</span>
</code></pre>
<p><b>Step 5 :</b>
Now use "for loop" to send msg word by word</p>
<p>Xpath for entering a message </p>
<pre><code class="lang-python">driver.find_element_by_xpath(<span class="hljs-string">"//*/footer/div[1]/div[2]/div/div[2]"</span>).send_keys(word)
</code></pre>
<h3 id="source-code">Source Code</h3>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> selenium <span class="hljs-keyword">import</span> webdriver
<span class="hljs-keyword">from</span> selenium.webdriver.common.keys <span class="hljs-keyword">import</span> Keys
<span class="hljs-keyword">from</span> time <span class="hljs-keyword">import</span> sleep


driver=webdriver.Chrome(<span class="hljs-string">""</span>) <span class="hljs-comment"># Enter Location of Chrome driver</span>
driver.maximize_window()
driver.get(<span class="hljs-string">"https://web.whatsapp.com/"</span>)
sleep(<span class="hljs-number">15</span>)
driver.find_element_by_xpath(<span class="hljs-string">"/html/body/div/div/div/div/div/div/div[1]/div/div/div[1]/div/div/div"</span>).click()
sleep(<span class="hljs-number">5</span>)
fileLocation= <span class="hljs-string">""</span>  <span class="hljs-comment"># Enter location of movie script file</span>
<span class="hljs-keyword">with</span> open(fileLocation,<span class="hljs-string">"r"</span>) <span class="hljs-keyword">as</span> file:
    <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> file:
        <span class="hljs-keyword">for</span> word <span class="hljs-keyword">in</span> line.split(<span class="hljs-string">" "</span>):
            driver.find_element_by_xpath(<span class="hljs-string">"//*/footer/div[1]/div[2]/div/div[2]"</span>).send_keys(word)
            driver.find_element_by_xpath(<span class="hljs-string">"//*/footer/div[1]/div[2]/div/div[2]"</span>).send_keys(Keys.ENTER)
</code></pre>
<p><strong>Hope it's useful</strong></p>
<p><em>If you like my content, please consider supporting me</em></p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[Overview of Deno JS - Installation and Building an API]]></title><description><![CDATA[Overview of DENO JS
Deno is a JavaScript/TypeScript runtime created by Ryan Dahl the same developer who created Node js
It uses URLs for loading local or remote dependencies, similar to browsers.
And it includes a built-in package manager for resourc...]]></description><link>https://blog.sunilaleti.dev/overview-of-deno-js-installation-and-building-an-api</link><guid isPermaLink="true">https://blog.sunilaleti.dev/overview-of-deno-js-installation-and-building-an-api</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Deno]]></category><category><![CDATA[api]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Thu, 22 Oct 2020 10:10:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1603015816548/dnY7NVbQa.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><h3><b>Overview of DENO JS</b></h3>
Deno is a JavaScript/TypeScript runtime created by <b>Ryan Dahl</b> the same developer who created <b>Node js</b>
It uses URLs for loading local or remote dependencies, similar to browsers.
And it includes a built-in package manager for resource fetching, thus no need for NPM.<p></p>
<p></p><h3><b>Advantages of using Deno JS</b></h3><p></p>
<ul>
<li>Built in TypeScript Support</li>
<li>More Secure</li>
<li>ES6+ Syntax</li>
<li>No package.json or Node modules</li>
</ul>


<p></p><h3><b>Installation</b></h3>
For MAC, simply execute this command<p></p>
<pre><code class="lang-javascript">brew install deno
</code></pre>
<p>For Windows, execute this command (Hope chocolatey is already installed)</p>
<pre><code class="lang-javascript">choco install deno
</code></pre>
<p></p><h3><b>Building an API</b></h3> 
We will build a API to operate crud operations required for our TODO Application<p></p>
<p>And these are End points</p>
<p></p><table><p></p>
<p><tr><td><b>GET</b> - /todos</td>  <td>Used to read all the data</td></tr></p>
<p><tr><td><b>POST</b> - /todos (form data)</td><td>  Used to insert the data</td></tr></p>
<p><tr><td><b>PUT</b> - /todos/:id</td><td> Used to update an existing data</td></tr></p>
<p><tr><td><b>DELETE</b> - /todos/:id</td><td> Used to delete an record</td></tr>
</p></table>
<b>Step 1:</b> <p></p>
<p>Well, we will start with index.js
Normally, in NodeJs we use express for routings and we import it using <b>require</b> keyword but in DENO Js we import from <a>oak</a> (As you can see in below code)</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { Application } <span class="hljs-keyword">from</span> <span class="hljs-string">"https://deno.land/x/oak/mod.ts"</span>;
<span class="hljs-keyword">import</span> { PORT } <span class="hljs-keyword">from</span> <span class="hljs-string">"./config.js"</span>;
<span class="hljs-keyword">import</span> router <span class="hljs-keyword">from</span> <span class="hljs-string">"./router.js"</span>;

<span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> Application();
app.use(router.routes());
app.use(router.allowedMethods());

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Server is running. Open http://localhost:<span class="hljs-subst">${PORT}</span>`</span>);

<span class="hljs-keyword">await</span> app.listen({ <span class="hljs-attr">port</span>: PORT });
</code></pre>
<p><b>Step 2:</b></p>
<p>Setup configuration file i.e PORT and FilePath required to store JSON data</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> PORT = <span class="hljs-number">5000</span>;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> FilePath = <span class="hljs-string">"./data/todos.json"</span>;
</code></pre>
<p><b>Step 3:</b></p>
<p>Now create get.js, post.js, delete.js, put.js and place it in the controller.
For clear code view, you can check my <a href="https://github.com/aletisunil/TODO-Application-using-DENO">GitHub repository.</a></p>
<p><b>Step 4:</b> </p>
<p>Now create a router.js file which handles all the routings that are required for the application</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { Router } <span class="hljs-keyword">from</span> <span class="hljs-string">"https://deno.land/x/oak/mod.ts"</span>;
<span class="hljs-keyword">import</span> getTodos <span class="hljs-keyword">from</span> <span class="hljs-string">"./Controllers/todos/get.js"</span>;
<span class="hljs-keyword">import</span> postTodo <span class="hljs-keyword">from</span> <span class="hljs-string">"./Controllers/todos/post.js"</span>;
<span class="hljs-keyword">import</span> deleteTodo <span class="hljs-keyword">from</span> <span class="hljs-string">"./Controllers/todos/delete.js"</span>;
<span class="hljs-keyword">import</span> putTodo <span class="hljs-keyword">from</span> <span class="hljs-string">"./Controllers/todos/put.js"</span>;

<span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> Router();

router.get(<span class="hljs-string">"/"</span>, <span class="hljs-function">(<span class="hljs-params">{ response }</span>) =&gt;</span> {
  response.body = <span class="hljs-string">"Todo Application using Deno"</span>;
});

router
  .get(<span class="hljs-string">"/todos"</span>, getTodos)
  .post(<span class="hljs-string">"/todos"</span>, postTodo)
  .delete(<span class="hljs-string">"/todos/:id"</span>, deleteTodo)
  .put(<span class="hljs-string">"/todos/:id"</span>, putTodo);

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> router;
</code></pre>
<p><b>Step 5:</b></p>
<p>The main difference in Deno to NodeJs is the flags which need to be passed while executing the application for read, write permissions
And this is one of the reason Deno make more secure.</p>
<pre><code class="lang-javascript"> deno run --allow-net=:<span class="hljs-number">5000</span> --allow-read=./data/todos.json --allow-write=./data/todos.json ./index.js
</code></pre>
<p>Deno loads the modules once from the URL and cache it in your system. To reload the modules again, you need to provide --reload flag before running the program.</p>
<pre><code class="lang-javascript">deno run --reload --allow-net ./index.js
</code></pre>
<p><b>Step 6:</b></p>
<p>Now we can test our application in postman</p>
<p></p><h4>Get</h4>
<img src="https://dev-to-uploads.s3.amazonaws.com/i/mnkomyq81bx3of0ng3gf.png" alt="Alt Text" /><p></p>
<p></p><h4>Post</h4>
<img src="https://dev-to-uploads.s3.amazonaws.com/i/6mz623qlctsv7353etqg.png" alt="Alt Text" /><p></p>
<p></p><h4>Delete</h4>
<img src="https://dev-to-uploads.s3.amazonaws.com/i/7pipa2rvk8c5g4k22guf.png" alt="Alt Text" /><p></p>
<p></p><h4>Put</h4>
<img src="https://dev-to-uploads.s3.amazonaws.com/i/yrhvz0136grg1q3777i4.png" alt="Alt Text" /><p></p>
<p></p><h3><b>Conclusion:</b></h3>
Well, Deno is still in early stages and it still needs to be crafted.
So the answer for <b>Whether Deno kills Node ?</b> is totally unclear.<p></p>
<p>Hope it's useful
A ❤️ would-be Awesome 😊</p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[Automating Twitter Followers Count]]></title><description><![CDATA[I've seen many people on Twitter where they append followers count to their name and the counter increments or decrements based on followers count.
This is how it looks -
To test more on this implementation, check my profile😉

  
As there are many w...]]></description><link>https://blog.sunilaleti.dev/automating-twitter-followers-count-1</link><guid isPermaLink="true">https://blog.sunilaleti.dev/automating-twitter-followers-count-1</guid><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Python]]></category><category><![CDATA[Twitter]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Thu, 22 Oct 2020 02:09:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1602986932335/fyZDMF7X2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I've seen many people on Twitter where they append followers count to their name and the counter increments or decrements based on followers count.</p>
<p>This is how it looks -
To test more on this implementation, check my profile😉
<a href="https://twitter.com/aleti_sunil" target="_blank">
  <img src="https://dev-to-uploads.s3.amazonaws.com/i/qd69pzb1wak64x86xu5l.PNG" /></a></p>
<p>As there are many ways of achieving this, I chose python</p>
<p><b>Pre-requisites:</b></p>
<p>First, we need to have a Twitter developer account, if you don't have.</p>
<p><b>1) </b>Just navigate to <a target="_blank" href="https://developer.twitter.com/en/apply-for-access">Twitter Developer website</a>
<b>2) </b>Just fill out the form with details about ‘what you want to do with their API’.  You will be redirected to four forms, one form after another, complete them and agree to the developer terms and conditions and submit the application. 
This process may take like 10 minutes and you will get a verification email instantly once you submitted the form.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/sj0h0s810wga0ov1439q.PNG" alt="Alt Text" /></p>
<p>After getting approval from Twitter. Now we can create an app</p>
<p><b>1) </b>Open this <a target="_blank" href="https://developer.twitter.com/en/portal/projects-and-apps">link</a> and click on "create app"</p>
<p><b>2) </b>Give your app a name. And you can't name an app which is already present.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/agft9om1foaemjvxfcw4.PNG" alt="Alt Text" /></p>
<p><b>3) </b>Next, you will be redirected to API keys, tokens and click on "App Settings"</p>
<p><b>4) </b>Now scroll down to the App permissions section and change the option from “Read” to “Read and Write” and click on Save.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/te0oemuh0ozprcggwdde.PNG" alt="Alt Text" /></p>
<p><b>5) </b>Now scroll to the top, and click on the option called <b>” Keys and Tokens”</b>. Click on it and there you can see your Twitter API keys and Access Tokens by click on the <b>“view keys”</b> button and <b>“generate”</b> button respectively.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/jj18bv9lyddew6rzpudd.png" alt="Alt Text" /></p>
<p>Here comes our logic part...</p>
<p>we should create two files,</p>
<ol>
<li>config.py</li>
<li>counter.py</li>
</ol>

<p>This <b>config.py</b> is responsible for creating an authenticated API using tweepy module and API Keys</p>
<p></p><h3>config.py</h3><p></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> tweepy
<span class="hljs-keyword">import</span> logging
<span class="hljs-keyword">from</span> os <span class="hljs-keyword">import</span> environ

logger = logging.getLogger()

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_api</span>():</span>
    consumer_key = environ[<span class="hljs-string">'CONSUMER_KEY'</span>]
    consumer_secret =  environ[<span class="hljs-string">'CONSUMER_SECRET'</span>]
    access_token =  environ[<span class="hljs-string">"ACCESS_TOKEN"</span>]
    access_token_secret =environ[<span class="hljs-string">"ACCESS_TOKEN_SECRET"</span>]

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=<span class="hljs-literal">True</span>,
                     wait_on_rate_limit_notify=<span class="hljs-literal">True</span>)
    <span class="hljs-keyword">try</span>:
        api.verify_credentials()
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        logger.error(<span class="hljs-string">'Error creating API'</span>, exc_info=<span class="hljs-literal">True</span>)
        <span class="hljs-keyword">raise</span> e
    logger.info(<span class="hljs-string">'API created'</span>)
    <span class="hljs-keyword">return</span> api
</code></pre>
<p>Don't forget to add environmental variables when deploying</p>
<p>This <b>counter.py</b> runs every minute and checks the followers count if there is a change then it updates the name and followers count.
We can use emoji's as well instead of numbers</p>
<p></p><h3>counter.py</h3><p></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> tweepy
<span class="hljs-keyword">import</span> logging
<span class="hljs-keyword">from</span> config <span class="hljs-keyword">import</span> create_api
<span class="hljs-keyword">import</span> time

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate_follower_count</span>(<span class="hljs-params">user</span>):</span>
    <span class="hljs-comment"># update string split if you don't use this naming format for twitter profile:</span>
    <span class="hljs-comment"># 'insert_your_name|{emoji_follower_count(user)} Followers'</span>
    current_follower_count = user.name.replace(<span class="hljs-string">'|'</span>, <span class="hljs-string">' '</span>).split()
    <span class="hljs-keyword">return</span> current_follower_count


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">emoji_follower_count</span>(<span class="hljs-params">user</span>):</span>
    emoji_numbers = {<span class="hljs-number">0</span>: <span class="hljs-string">"0️⃣"</span>, <span class="hljs-number">1</span>: <span class="hljs-string">"1️⃣"</span>, <span class="hljs-number">2</span>: <span class="hljs-string">"2️⃣"</span>, <span class="hljs-number">3</span>: <span class="hljs-string">"3️⃣"</span>,
                     <span class="hljs-number">4</span>: <span class="hljs-string">"4️⃣"</span>, <span class="hljs-number">5</span>: <span class="hljs-string">"5️⃣"</span>, <span class="hljs-number">6</span>: <span class="hljs-string">"6️⃣"</span>, <span class="hljs-number">7</span>: <span class="hljs-string">"7️⃣"</span>, <span class="hljs-number">8</span>: <span class="hljs-string">"8️⃣"</span>, <span class="hljs-number">9</span>: <span class="hljs-string">"9️⃣"</span>}

    follower_count_list = [int(i) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> str(user.followers_count)]

    emoji_followers = <span class="hljs-string">''</span>.join([emoji_numbers[k]
                               <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> follower_count_list <span class="hljs-keyword">if</span> k <span class="hljs-keyword">in</span> emoji_numbers.keys()])

    <span class="hljs-keyword">return</span> emoji_followers


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span>():</span>
    api = create_api()

    <span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:
        <span class="hljs-comment"># change to your own twitter_handle</span>
        user = api.get_user(<span class="hljs-string">'aleti_sunil'</span>)


        <span class="hljs-keyword">if</span> validate_follower_count(user) == emoji_follower_count(user):
            logger.info(
                <span class="hljs-string">f'You still have the same amount of followers, no update neccesary: <span class="hljs-subst">{validate_follower_count(user)}</span> -&gt; <span class="hljs-subst">{emoji_follower_count(user)}</span>'</span>)
        <span class="hljs-keyword">else</span>:
            logger.info(
                <span class="hljs-string">f'Your amount of followers has changed, updating twitter profile: <span class="hljs-subst">{validate_follower_count(user)}</span> -&gt; <span class="hljs-subst">{emoji_follower_count(user)}</span>'</span>)
            <span class="hljs-comment"># Updating your twitterprofile with your name including the amount of followers in emoji style</span>
            api.update_profile(
                name=<span class="hljs-string">f'Sunil Aleti |  <span class="hljs-subst">{emoji_follower_count(user)}</span>'</span>)

        logger.info(<span class="hljs-string">"Waiting to refresh.."</span>)
        time.sleep(<span class="hljs-number">60</span>)


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
    main()
</code></pre>
<p>Now push the code to github and you can get files <a href="https://github.com/aletisunil/TwitterFollowerCounter">here</a></p>
<p>You can deploy this in AWS too but it is not my cup of tea.
So, As we are deploying it to <a href="heroku.com">Heroku</a>
we need to add few more files</p>
<ul>
<li><b>requirements.txt</b> - As we are using tweepy module, we need to specify tweepy in requirements.txt</li>
<li><b>Procfile</b> - This file specifies heroku to execute counter.py file</li>
<li><b>runtime.txt</b> - In our case, we are using python, so mention python-3.6.9</li>
</ul>

<p><b>Follow this video for further deployment in Heroku</b></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=PUA0fyraRmY">https://www.youtube.com/watch?v=PUA0fyraRmY</a></div>
<p><br /></p>
<p><b>If you like my content, please consider supporting me</b><br /></p>
<div class="hn-embed-widget" id="buymeacoffee"></div><p>Hope it's useful</p>
<p>A ❤️ would-be Awesome 😊</p>
]]></content:encoded></item><item><title><![CDATA[Automating Zoom]]></title><description><![CDATA[Hi,
Well, we all know Zoom is a video conferencing app which allows us to attend/conduct meetings. And because of this pandemic situation, the usage of these video conferencing apps also increased drastically and even for school kids this became a ne...]]></description><link>https://blog.sunilaleti.dev/automating-zoom</link><guid isPermaLink="true">https://blog.sunilaleti.dev/automating-zoom</guid><category><![CDATA[Python]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[automation]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Wed, 14 Oct 2020 16:30:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1602692683248/LUf4ApWhy.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><h4>Hi,</h4><p></p>
<p>Well, we all know <b>Zoom</b> is a video conferencing app which allows us to attend/conduct meetings. And because of this pandemic situation, the usage of these video conferencing apps also increased drastically and even for school kids this became a new normal and sometimes these continuous online classes becomes cumbersome.</p>
<p>      And today we gonna learn how to automate <b>zoom</b> such that it automatically logs into one's meetings/classes on time.</p>

<p>For this, we need </p>
<ul>
<li>python</li>
<li>pyautogui</li>
<li>pandas</li>
</ul>

<p></p><h2>Behind the scenes:</h2><p></p>
<ul>
<li>An infinite loop keeps checking the current time of the system using "datetime.now" funtion.</li>
<li>The zoom app is opened using "os.startfile()" funtion as soon as current time matches the time mentioned in "timings.xlsx".</li>
<li>"pyautogui.locateOnScreen()" function locates the image of join button on the screen and returns the position.</li>
<li>"pyautogui.locateCenterOnScreen()" function locates the center of the first found instance of the image on the screen. </li>
<li>"pyautogui.moveTo()" moves the cursor to that location.</li>
<li>"pyautogui.click()" performs a click operation.</li>
<li>The meeting Id and Passcode are entered using the "pyautogui.write()" command.</li>
</ul>

<p></p><h2>Steps for Automating:</h2>
<b>1.</b> import necessary modules<p></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> os              
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd    
<span class="hljs-keyword">import</span> pyautogui
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime
</code></pre>
<p><b>os</b> -  Provides a way of using operating system dependent functionality.</p>
<p><b>pandas</b> - Allows us to store and manipulate tabular data in rows and columns of variables. </p>
<p><b>pyautogui</b> - A module which helps to control the mouse and keyboard, and other GUI automation tasks.</p>
<p><b>2.</b> Open's zoom application from the specified location</p>
<pre><code class="lang-python">os.startfile(<span class="hljs-string">" "</span>)
</code></pre>
<p><b>3.</b> To click join button</p>
<pre><code class="lang-python"><span class="hljs-comment">#place the pic location inside quotes</span>
joinbtn=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
pyautogui.moveTo(joinbtn)
pyautogui.click()
</code></pre>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/0e5g0tgt7ypz9s469b55.gif" alt="Alt Text" /></p>
<p><b>4.</b> Similarly, like join button we have to take screenshot of every button to click or to locate</p>
<pre><code class="lang-python"><span class="hljs-comment">#To type the meeting id</span>
<span class="hljs-comment">#place the picture location inside quotes</span>
meetingidbtn=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
pyautogui.moveTo(meetingidbtn)
pyautogui.write(meeting_id)
</code></pre>
<p><b>5.</b> To enter passcode</p>
<pre><code class="lang-python"><span class="hljs-comment">#Enter the passcode to join meeting</span>
passcode=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
pyautogui.moveTo(passcode)
pyautogui.write(password)
</code></pre>
<p><b>6.</b> Create an excel file and add all meeting details like "Timings", "Meeting id" and "Password"</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/e2vn1lw203m1ddbmcab1.png" alt="Alt Text" /></p>
<p><b>7.</b> Now import that excel file using pandas</p>
<pre><code class="lang-python"><span class="hljs-comment">#place excel file location inside quotes</span>
df = pd.read_excel(<span class="hljs-string">''</span>,index=<span class="hljs-literal">False</span>)
</code></pre>
<p><b>8.</b> Now we will write while loop to constantly check for the current time and compare the timings in <b>excel file</b></p>
<pre><code class="lang-python"><span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:
    <span class="hljs-comment">#To get current time</span>
    now = datetime.now().strftime(<span class="hljs-string">"%H:%M"</span>)
    <span class="hljs-keyword">if</span> now <span class="hljs-keyword">in</span> str(df[<span class="hljs-string">'Timings'</span>]):

        mylist=df[<span class="hljs-string">"Timings"</span>]
        mylist=[i.strftime(<span class="hljs-string">"%H:%M"</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> mylist]
        c= [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(mylist)) <span class="hljs-keyword">if</span> mylist[i]==now]
        row = df.loc[c] 
        meeting_id = str(row.iloc[<span class="hljs-number">0</span>,<span class="hljs-number">1</span>])  
        password= str(row.iloc[<span class="hljs-number">0</span>,<span class="hljs-number">2</span>])  
        time.sleep(<span class="hljs-number">5</span>)
        signIn(meeting_id, password)
        time.sleep(<span class="hljs-number">2</span>)
        print(<span class="hljs-string">'signed in'</span>)
        <span class="hljs-keyword">break</span>
</code></pre>
<p>Check out my <a target="_blank" href="https://github.com/aletisunil/Automating_Zoom">GitHub repo</a> to get code and assets for buttons</p>
<h3 id="source-code-for-automation">Source code for Automation</h3>
<pre><code class="lang-python"> <span class="hljs-keyword">import</span> os
 <span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
 <span class="hljs-keyword">import</span> pyautogui
 <span class="hljs-keyword">import</span> time
 <span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime


 <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">signIn</span>(<span class="hljs-params">meeting_id,password</span>):</span>

     <span class="hljs-comment">#Open's Zoom Application from the specified location</span>
     os.startfile(<span class="hljs-string">""</span>)
     time.sleep(<span class="hljs-number">3</span>)

     <span class="hljs-comment">#Click's join button</span>
     joinbtn=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
     pyautogui.moveTo(joinbtn)
     pyautogui.click()
     time.sleep(<span class="hljs-number">1</span>)

     <span class="hljs-comment">#Type the meeting id</span>
     meetingidbtn=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
     pyautogui.moveTo(meetingidbtn)
     pyautogui.write(meeting_id)
     time.sleep(<span class="hljs-number">2</span>)

     <span class="hljs-comment">#To turn of video and audio</span>
     mediaBtn=pyautogui.locateAllOnScreen(<span class="hljs-string">""</span>)
     <span class="hljs-keyword">for</span> btn <span class="hljs-keyword">in</span> mediaBtn:
         pyautogui.moveTo(btn)
         pyautogui.click()
         time.sleep(<span class="hljs-number">1</span>)

     <span class="hljs-comment">#To join</span>
     join=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
     pyautogui.moveTo(join)
     pyautogui.click()
     time.sleep(<span class="hljs-number">2</span>)

     <span class="hljs-comment">#Enter's passcode to join meeting</span>
     passcode=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
     pyautogui.moveTo(passcode)
     pyautogui.write(password)
     time.sleep(<span class="hljs-number">1</span>)

     <span class="hljs-comment">#Click's on join button</span>
     joinmeeting=pyautogui.locateCenterOnScreen(<span class="hljs-string">""</span>)
     pyautogui.moveTo(joinmeeting)
     pyautogui.click()
     time.sleep(<span class="hljs-number">1</span>)

 df = pd.read_excel(<span class="hljs-string">''</span>,index=<span class="hljs-literal">False</span>)

 <span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:
     <span class="hljs-comment">#To get current time</span>
     now = datetime.now().strftime(<span class="hljs-string">"%H:%M"</span>)
     <span class="hljs-keyword">if</span> now <span class="hljs-keyword">in</span> str(df[<span class="hljs-string">'Timings'</span>]):

         mylist=df[<span class="hljs-string">"Timings"</span>]
         mylist=[i.strftime(<span class="hljs-string">"%H:%M"</span>) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> mylist]
         c= [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(mylist)) <span class="hljs-keyword">if</span> mylist[i]==now]
         row = df.loc[c] 
         meeting_id = str(row.iloc[<span class="hljs-number">0</span>,<span class="hljs-number">1</span>])  
         password= str(row.iloc[<span class="hljs-number">0</span>,<span class="hljs-number">2</span>])  
         time.sleep(<span class="hljs-number">5</span>)
         signIn(meeting_id, password)
         time.sleep(<span class="hljs-number">2</span>)
         print(<span class="hljs-string">'signed in'</span>)
         <span class="hljs-keyword">break</span>
</code></pre>
<h5>Demo video:</h5>

<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/c2IlvlirKh4">https://www.youtube.com/c2IlvlirKh4</a></div>
<p><br /></p>
<p><b>If you like my content, please consider supporting me</b><br /></p>
<div class="hn-embed-widget" id="buymeacoffee"></div>]]></content:encoded></item><item><title><![CDATA[Building an Amazon Price Tracker with Python and WayScript]]></title><description><![CDATA[Hi
      Well, Today we will discuss How to built Amazon Price Tracker by scraping the price details and scheduling with WayScript
Lemme tell you the real reason to build this ;)
I'm a foodie I love Nutella 🤤 but due to this pandemic, I couldn't fin...]]></description><link>https://blog.sunilaleti.dev/building-an-amazon-price-tracker-with-python-and-wayscript</link><guid isPermaLink="true">https://blog.sunilaleti.dev/building-an-amazon-price-tracker-with-python-and-wayscript</guid><category><![CDATA[Python]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[2Articles1Week]]></category><dc:creator><![CDATA[Sunil Aleti]]></dc:creator><pubDate>Wed, 14 Oct 2020 16:21:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1602692464265/EVnBXv5sV.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi
      Well, Today we will discuss <b>How to built Amazon Price Tracker</b> by scraping the price details and scheduling with <b>WayScript</b></p>
<p>Lemme tell you the real reason to build this ;)
I'm a foodie I love Nutella 🤤 but due to this pandemic, I couldn't find Nutella near me in any local stores. So I thought to order it in Amazon but the prices are damn high and prices are fluctuating too... then I started to build a tracker which notifies me whenever the price goes down the tracking price.</p>
<p></p><h2><b>Let's get started..</b></h2><p></p>
<p>We gonna create a python script which uses request and beautifulSoup module to scrape the data and scheduling the script to run every hour either with <b>Serverless AWS Lambda</b> or <b>WayScript</b> but AWS Lambda is not my cup of tea. So I built using WayScript.</p> 

<p>We will discuss this process in 2 phases.
Phase I  : Scraping the product details
Phase II : Scheduling the script to run every hour</p>
<h3><b>Phase I:</b></h3>

<p><b>Step 1:</b> Create an excel sheet with urls and Tracking Price<br />
<img src="https://dev-to-uploads.s3.amazonaws.com/i/5nyu2o51b4r81qpp1r3i.png" alt="Alt Text" /></p>
<p><b>Step 2:</b> import necessary packages/module </p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> bs4
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
</code></pre>
<p><b>Request</b> - The requests module allows you to send HTTP requests using Python
<b>bs4</b> - Beautiful Soup is a library that makes it easy to scrape information from web
<b>pandas</b> - pandas is a fast and powerful used for data analysis.
we are faking ourselves as a Firefox user to avoid restrictions.</p>
<pre><code class="lang-python">HEADERS = ({<span class="hljs-string">'User-Agent'</span>:
            <span class="hljs-string">'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'</span>,
            <span class="hljs-string">'Accept-Language'</span>: <span class="hljs-string">'en-US, en;q=0.5'</span>})
</code></pre>
<p><b>Step 3:</b> Building Python Script
Here is the tracker function which takes parameters URL and TrackingPrice and adds the details of the product when it is less or than equal to TrackingPrice</p>
<pre><code class="lang-python">
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">tracker</span>(<span class="hljs-params">url,TrackingPrice</span>):</span>
    res = requests.get(url,headers=HEADERS)
    soup = bs4.BeautifulSoup(res.content, features=<span class="hljs-string">'lxml'</span>)

    <span class="hljs-comment"># to prevent script from crashing when there isn't a price for the product</span>
    <span class="hljs-keyword">try</span>:
        title = soup.find(id=<span class="hljs-string">"productTitle"</span>).get_text().strip()
        amount = float(soup.find(id=<span class="hljs-string">'priceblock_ourprice'</span>).get_text().replace(<span class="hljs-string">"₹"</span>,<span class="hljs-string">""</span>).replace(<span class="hljs-string">"$"</span>,<span class="hljs-string">""</span>).strip())
        <span class="hljs-keyword">if</span> amount&lt;=TrackingPrice:
            offer.append(<span class="hljs-string">"You got a offer on the {0} for {1}. Check out the product {2}"</span>.format(title,amount,url))


    <span class="hljs-keyword">except</span>:
        offer.append(<span class="hljs-string">"Couldn't get details about product"</span>)
</code></pre>
<p><br />
<b>Source Code:</b></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> bs4
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd


HEADERS = ({<span class="hljs-string">'User-Agent'</span>:
            <span class="hljs-string">'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'</span>,
            <span class="hljs-string">'Accept-Language'</span>: <span class="hljs-string">'en-US, en;q=0.5'</span>})
offer=[]
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">tracker</span>(<span class="hljs-params">url,TrackingPrice</span>):</span>
    res = requests.get(url,headers=HEADERS)
    soup = bs4.BeautifulSoup(res.content, features=<span class="hljs-string">'lxml'</span>)

    <span class="hljs-comment"># to prevent script from crashing when there isn't a price for the product</span>
    <span class="hljs-keyword">try</span>:
        title = soup.find(id=<span class="hljs-string">"productTitle"</span>).get_text().strip()
        amount = float(soup.find(id=<span class="hljs-string">'priceblock_ourprice'</span>).get_text().replace(<span class="hljs-string">"₹"</span>,<span class="hljs-string">""</span>).replace(<span class="hljs-string">"$"</span>,<span class="hljs-string">""</span>).strip())
        <span class="hljs-keyword">if</span> amount&lt;=TrackingPrice:
            offer.append(<span class="hljs-string">"You got a offer on the {0} for {1}. Check out the product {2}"</span>.format(title,amount,url))


    <span class="hljs-keyword">except</span>:
        offer.append(<span class="hljs-string">"Couldn't get details about product"</span>)



df=pd.read_csv(<span class="hljs-string">"https://docs.google.com/spreadsheets/d/1AzJ93zR6--4vwl81W3v0FHyZ_bFMkFYRxOSjodJu_Qw/export?format=csv"</span>)
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>,len(df[<span class="hljs-string">"URL"</span>])):
    tracker(df[<span class="hljs-string">"URL"</span>][i],df[<span class="hljs-string">"TrackingPrice"</span>][i])
outputs[<span class="hljs-string">"message"</span>]=offer
</code></pre>
<p><b>Output:</b></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/cgp892ev5rtoflitf2vm.PNG" alt="Alt Text" /></p>
<p><br /></p>
<p>we're done with our python script <br />
Now let's move to Phase II</p>
<p><b>Phase II:</b><br />
I already told you can schedule this script either by using AWS Lambda or any other cloud computing services as I'm not familar with AWS. I'm going with WayScript</p>
<p>And this WayScript provide wide range of packages to interact with services
<b>Ex:</b></p>
<p></p><ul><p></p>
<p><li>Gmail</li></p>
<p><li>Text Message</li></p>
<p><li>Charts</li></p>
<p><li>Figma</li></p>
<p><li>Slack</li></p>
<p><li>Trello</li></p>
<p><li>Twitter</li>
</p></ul>
<br /><p></p>
<p><b>Step 1: </b>Open <a href="https://wayscript.com/">WayScript</a><br />
<b>Packages used for this scheduling:</b></p>
<p></p><ul><p></p>
<p><li>Time Trigger</li></p>
<p><li>Python</li></p>
<p><li>Loop</li></p>
<p><li>Text Message</li>
</p></ul>
<b>Step 2: </b>Explaining everything in blog is not possible and people get cumbersome. So I made video of "How to configure the Python Script in WayScript.
Kindly Follow the video<p></p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=J09RSQVV5xY">https://www.youtube.com/watch?v=J09RSQVV5xY</a></div>
<p><a target="_blank" href="https://wayscript.com/shared/l4KwC5XY">Click here to check my configuration in WayScript</a></p>
<p></p><h4>On one lucky day..</h4>
The price got reduced and this script notified me by sending a text message and I ordered it 😁<br />
<img src="https://dev-to-uploads.s3.amazonaws.com/i/riyf4wqcq35ny4sehh86.jpg" alt="Alt Text" />
<br />
<b>If you like my content, please consider supporting me</b><p></p>
<div class="hn-embed-widget" id="buymeacoffee"></div><p><br /></p>
]]></content:encoded></item></channel></rss>