<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by WasiUllah Khan on Medium]]></title>
        <description><![CDATA[Stories by WasiUllah Khan on Medium]]></description>
        <link>https://medium.com/@wasiullah-khan21?source=rss-5ae054cb4084------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-AWlgjICXSSO0fi0lym4SA.jpeg</url>
            <title>Stories by WasiUllah Khan on Medium</title>
            <link>https://medium.com/@wasiullah-khan21?source=rss-5ae054cb4084------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:32:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wasiullah-khan21/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Advanced Web Scraping with Scrapy]]></title>
            <link>https://python.plainenglish.io/advance-web-scraping-using-scrapy-fd6171ef96b4?source=rss-5ae054cb4084------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd6171ef96b4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scrapy]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-scraping]]></category>
            <dc:creator><![CDATA[WasiUllah Khan]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 20:34:28 GMT</pubDate>
            <atom:updated>2023-08-09T13:16:33.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*hjn5ES8oTpqFYZ8W.png" /></figure><p>Web Scraping has been a very hot topic for quite some time now, so let’s talk about what it actually is. <strong>Web Scraping</strong> is the process of extracting text from webpages in an automated way. Have you ever wondered how Google fetches data and indexes it into its search engine? Well they do web scraping and crawling. There are a number of use cases where web scraping is required such as gathering datasets to train machine learning models, gathering prices of products, gathering emails for lead generation and much more…</p><h4>What is the difference between web crawling and web scraping?</h4><p>A lot of people confuse web crawling with web scraping and vice versa. Well as I mentioned above <strong>Web Scraping</strong> is the process of extracting text from webpages in an automated way and <strong>Web Crawling</strong> is the process of following up links of your desired choice. <strong>Web Scraping</strong> and <strong>Web Crawling</strong> go hand in hand when you want to scrape <strong><em>X</em></strong> number of pages. For example, if you want to scrape search results off of Amazon and there is pagination so in order to do that, you’ll need to follow up on the pagination links to do that.</p><h4>What is scrapy?</h4><p>Scrapy is a web scraping framework built in python that follow’s the <strong><em>batteries included</em></strong> approach same as Django. It’s an asynchronous framework that comes with a lot of functionality right from the get go as soon as you start the project.</p><h4>Scrapy Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kk6WZgi1Wo6L5y5S2vqoHg.png" /></figure><ol><li>The <strong>Spider</strong> throws the initial request to the <strong>Engine</strong> to start crawling.</li><li>The <strong>Engine</strong> schedules the request in the <strong>Scheduler </strong>and asks for the next request to crawl.</li><li>The <strong>Scheduler</strong> throws back the request to the <strong>Engine</strong>.</li><li>The <strong>Engine</strong> sends the request off to the <strong>Downloader</strong>, where the request passes through the <strong>Downloader Middleware</strong>.</li><li>After the request finishes downloading, the <strong>Downloader</strong> generates a response, it sends it back to the <strong>Engine</strong> through the <strong>Downloader Middleware</strong></li><li>After getting the response from the <strong>Downloader</strong>, the <strong>Engine</strong> returns the response to the <strong>Spider</strong> through the <strong>Spider Middleware</strong>.</li><li>The <strong>Spider </strong>processes the response and scrapes the required items and the new request for crawling back to the <strong>Engine</strong>, again passing through the <strong>Spider Middleware</strong>.</li><li>The <strong>Engine </strong>sends the scraped items to the <strong>Items</strong> (also known as <strong>Item Pipeline</strong>) and then sends the processed requests to the <strong>Scheduler</strong> and asks for the next request to crawl.</li><li>This processes (step-1 to step-8) repeats until no requests are left in the <strong>Scheduler</strong> for crawling.</li></ol><p>I like to think of the <strong>Engine</strong> as the <em>spine</em> and the <strong>Middleware </strong>as the <em>limbs</em> of the scrapy architecture.</p><h3>Scraping Google Reviews</h3><p>Today I’ll show you how to scrape business reviews off of Google. Let’s get started.</p><h4>Prerequisites</h4><ul><li>python3</li><li>pip</li><li>virtualenv (not necessary but we will use it here)</li><li>Postman (we’ll be directly scraping from google’s backend by intercepting the API that they hit)</li></ul><p><strong>Note: </strong>I won’t be going through how xpath and css selectors actually work so you need to have a basic understanding of them.</p><p>I’ll be using the <em>bash </em>terminal here.</p><p>Make sure that you have python3, pip and virtualenv installed on your machine. To install virtualenv:</p><pre>$ pip install virtualenv</pre><p>Now make a directory called <em>review_scraper</em>.</p><pre>$ mkdir review_scraper</pre><p>Now <em>cd</em> into the directory.</p><pre>$ cd review_scraper/</pre><p>Create a virtual environment and name it whatever you like. I’ll be naming it <strong><em>venv</em></strong><em>.</em></p><pre>$ virtualenv venv</pre><p>Now activate it.</p><pre>$ source venv/bin/activate</pre><p>Let’s install scrapy using pip.</p><pre>$ pip install scrapy</pre><p>So now that Scrapy is installed, let’s start the project.</p><p><strong>Note:</strong> The project structure of Scrapy is very similar to Django and even how to start project is the same, so if you’re familiar with Django then this will be very easy.</p><pre>$ scrapy startproject review_scraper</pre><p>If you see your directory, scrapy created a new directory called <em>review_scraper</em> as well as created all the necessary project files from the get-go just like Django’s <em>battery included approach</em>.</p><figure><img alt="Tree structure of the project" src="https://cdn-images-1.medium.com/max/788/1*3-9M_3UswC5WYFlbAjsMJw.png" /></figure><p>Now that we have started a project, let’s look at <a href="https://www.google.com/search?q=concord+honda&amp;oq=con&amp;aqs=chrome.0.69i59j69i60l3j69i57j69i59l2.1025j0j7&amp;sourceid=chrome&amp;ie=UTF-8"><strong>Concord Honda</strong></a><strong> </strong>on Google and check out the reviews.</p><h4>Reverse Engineering the AJAX/Fetch requests Performed by the Client Side.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COLLBVTJyOf6cI-a-IOiMg.png" /></figure><p>Before clicking on the reviews, open up the browser developer tools and switch over to the network tab with <strong>XHR</strong> as the applied filter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FKKA-Sp5Z0co_uuL_dOwQ.png" /><figcaption>Network Tab on the browser developer tools.</figcaption></figure><p>Now click on <a href="https://www.google.com/search?q=concord+honda&amp;oq=con&amp;aqs=chrome.0.69i59j69i60l3j69i57j69i59l2.1025j0j7&amp;sourceid=chrome&amp;ie=UTF-8#lrd=0x808566dd35d0d82b:0x3bca18b3f8745548,1,,,"><strong>Google reviews</strong></a>, a model with reviews will pop up with the reviews. Notice your network tab, there would me multiple requests that the browser made to some external API’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_joibfhrrNKF37fxxdWaQ.png" /></figure><p>The reason that I opened up the developer tools was to see which requests were being made, because if you disable your browser’s <strong>JavaScript</strong>, you’ll see that your browser can’t open up google reviews because it’s rendered by <strong>JavaScript </strong>over at the client side. So when <strong>JavaScript</strong> is enabled, <strong>Google</strong> makes a request to it’s backend to retrieve the reviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kl1CIHAmRpEwBrHd-eDK7Q.png" /></figure><p>The highlighted url is where Google hits to retrieve the review. Let’s copy this url and decode it to shorten the url and make a pattern for future requests. After copying the url, paste it into postman and hit <strong>GET</strong> request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EyyGnqLDdPVguedyuO4cEg.png" /></figure><p>Now let’s shorten the url query and see if the response size remains the same or see if we’re getting the required data or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5FWD97z-P8JcP7wiHsOQg.png" /></figure><p>After shortening the url, we’re left with this.</p><ul><li><strong>feature_id </strong>(this is the business review id which tells the backend which business reviews to get)</li><li><strong>start_index</strong> (which tells us from which review number to start)</li><li><strong>sort_by</strong> (the sorting of the reviews)</li></ul><p>The most important out of these three is the <strong>feature_id</strong> which I’ll show you how to get in-order to create the get request. The <strong>start_index</strong> number is the pagination and can be easily calculated. The first reviews that Google fetches are 10, after you scroll down, more reviews are added (also known as <strong>infinite scroll</strong>), so we can divide it into chunks of 10. The formula for this is: <strong>pagination = total number of reviews / number of chunks.</strong> The feature_id is available in the original url <a href="https://www.google.com/search?q=concord+honda&amp;oq=conc&amp;aqs=chrome.0.69i59j69i60l3j69i57j0l2.788j0j7&amp;sourceid=chrome&amp;ie=UTF-8#lrd=0x808566dd35d0d82b:0x3bca18b3f8745548,1,,,">https://www.google.com/search?q=concord+honda&amp;oq=conc&amp;aqs=chrome.0.69i59j69i60l3j69i57j0l2.788j0j7&amp;sourceid=chrome&amp;ie=UTF-8#lrd=0x808566dd35d0d82b:0x3bca18b3f8745548,1,,,</a></p><p>The <strong>lrd</strong> is the <strong>feature_id</strong> which can be retrieved from the original url. Now that we have reverse engineered it, let’s check the attributes that we’ll scrape.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KrsCfxyHp4wMhIVdzShI_Q.png" /></figure><p>We will extract:</p><ul><li>reviewer name</li><li>review rating</li><li>review date</li><li>review description</li></ul><p>Google checks for the <strong>user-agent</strong> to send out correct results, so in the headers section in <strong>postman</strong>, add a custom <strong>user-agent</strong>. For Example <strong><em>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.61</em></strong> and then hit send</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ba5N7XIytA60LHlanl6jmQ.png" /></figure><p>Now that we are done with our analysis, let’s create our spider and start coding.</p><p>Navigate to the <strong>spiders directory</strong> in your main project directory and create a python file with the name of <strong>google</strong>.</p><pre>$ cd spiders/</pre><pre>$ touch google.py</pre><p>Now open the file in your favourite code editor or IDE and let’s start coding!</p><p><strong>Spiders</strong> are classes that we define and <strong>Scrapy</strong> uses them to scrape data from a website or a number of websites. Let’s create a class called <strong>GoogleSpider</strong> that inherits from the <strong>Spider</strong>. We’ll have to give it a <strong>name</strong> attribute so that scrapy knows which spider to call once we call a spider to start crawling and scraping (This is a must attribute, otherwise scrapy will raise a ValueError).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b25a3e46c33901e6d91540d0aa22b56/href">https://medium.com/media/6b25a3e46c33901e6d91540d0aa22b56/href</a></iframe><p>I defined my headers directly into the class you can also define it in the <strong><em>settings.py</em></strong> file which will use those headers for all requests made by scrapy. I like to define individual headers for individual spiders. The <strong>start_requests</strong> method basically tells scrapy from where to start the initial request from and then it follows <strong><em>callbacks</em></strong> through out. All the review urls are defined in the urls list and from there we just parse the <strong>feature_id</strong> which we need to make the <strong>API/AJAX</strong> request to google. The callback that we added here is the <strong><em>get_total_iteration </em></strong>from which we’ll make our request pagination and then scrape all the reviews.</p><p><strong>Note: </strong>Scrapy has the capability to use <strong>css selectors</strong> and <strong>xpath</strong>. I’ll be using both interchangeably.</p><p>Initially we’ll want to extract the total number of reviews so that we can make out the pagination for further crawling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMiIbcB1w5bkvtFiMTG8Rg.png" /></figure><p>The total review number is in a span with the class of <strong>z5jxId yVc3Hc </strong>and if you check the tag and class of the <strong>total review number</strong> in the browser, you’ll see that it’s the same over there as well so I’ll be capturing tags over there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNq6F98tDwLB8Jk8P5I8CQ.png" /></figure><p>Now that we have located the tag with the total number of reviews, let’s make our pagination/number of requests that we’ll make.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11913d0372fbce3a000b214cfa69a501/href">https://medium.com/media/11913d0372fbce3a000b214cfa69a501/href</a></iframe><p>Scrapy’s <strong><em>Request</em></strong> returns a <strong><em>response</em></strong><em> </em>object. Since, in our <strong>start_requests</strong>, we added the <strong>get_total_iteration </strong>method to the callback so the Request method returned the response object the <strong>get_total_iteration </strong>method for our use.</p><p>If we check the reviews, at a time, google show’s us 10 reviews. We can simply divide the <strong>total_reviews</strong> by <strong>10</strong> which will give us the total pages that exist (since google has infinite scrolling which doesn’t tell us the total pages). Once we get our <strong>iteration_number</strong>, we can simply loop over it and replace the <strong>start_index:0</strong> with the <strong>start_index:j</strong>, where <strong><em>j</em></strong><em> </em>being the variable incrementing by 10, because the <strong>start_index</strong> argument increments by 10 each time the page changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZveY19OJYCyV4YTY75kvQ.png" /><figcaption><strong>Reviewer with the class of “TSUbDb”</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tx-6tpfWlVl89CFtZYSX4w.png" /><figcaption><strong>Rating with the class of “Fam1ne EBe2gf” and Date with the class of “dehysf lTi8oc”</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4KRxc7SpKthAaz2YSixdbQ.png" /><figcaption><strong>Description with the class of “Jtu6Td” or “review-full-text” (“more…” button contains the full length)</strong></figcaption></figure><p>After locating all the tags with the proper class names for our scraping attributes, it’s time to start scraping!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e81e2f388102d8ff0c6b5e624eab74d/href">https://medium.com/media/2e81e2f388102d8ff0c6b5e624eab74d/href</a></iframe><p>The <strong>all_reviews</strong> variable selects all 10 reviews for us to iterate over each review and scrape the required content i.e <strong>reviewer, description, review_rating </strong>and <strong>review_date</strong>.</p><p>Now to run the code via command line (<em>bash</em>)</p><pre>$ scrapy crawl google -o reviews.csv</pre><p>The <strong>-o</strong> is the output flag and after that just specify the filename and the format to save the scraped data in.</p><p><strong>Note:</strong> Instead of yielding out the scraped attributes with the hardcoded dictionary, we can define our attributes in the <strong><em>items.py</em></strong> file with <a href="https://docs.scrapy.org/en/latest/topics/items.html">scrapy items</a>.</p><p>The final output file should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*7wH6TXzXqNHoud4wKSbgzA.png" /><figcaption><strong>Reviews Data</strong></figcaption></figure><p>And this is how you scrape google reviews with only HTTP Requests. You can check the source code <a href="https://github.com/calmconquerer/scrapy_tutorial">here</a>.</p><h3>Further Reading</h3><ul><li><a href="https://plainenglish.io/blog/leveraging-web-scraping-for-dynamic-pricing-strategies-for-e-commerce">Leveraging Web Scraping for Dynamic Pricing Strategies for E-commerce</a></li><li><a href="https://javascript.plainenglish.io/top-5-instant-data-scraping-tools-for-easy-web-scraping-2f3d1c4b07f0">Top 5 Instant Data Scraping Tools for Easy Web Scraping</a></li><li><a href="https://javascript.plainenglish.io/5-use-cases-of-web-scraping-in-ecommerce-c40590450d46">5 Use Cases of Web Scraping in eCommerce</a></li><li><a href="https://javascript.plainenglish.io/best-tool-for-web-scraping-beautifulsoup-vs-regex-vs-advanced-web-scrapers-50b8fb92950d">Best Tool for Web Scraping: BeautifulSoup vs. Regex vs. Advanced Web Scrapers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd6171ef96b4" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/advance-web-scraping-using-scrapy-fd6171ef96b4">Advanced Web Scraping with Scrapy</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup a python script as a service through systemctl/systemd]]></title>
            <link>https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267?source=rss-5ae054cb4084------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0cc55a42267</guid>
            <category><![CDATA[systemctl]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[systemd]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[WasiUllah Khan]]></dc:creator>
            <pubDate>Mon, 24 Aug 2020 15:50:42 GMT</pubDate>
            <atom:updated>2021-01-07T16:58:45.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*biKHf9zt70XaAP2m" /><figcaption>Photo by <a href="https://unsplash.com/@isword?utm_source=medium&amp;utm_medium=referral">Muhannad Ajjan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are several ways you can run your program as a background service in Linux such as <strong>crontab, .bashrc, </strong>etc but today I’ll write about systemd. I was initially looking for a way to run my python script as a background service so even if the server restarts for some reason, my script will run in the background regardless and I found that systemd allows me to do that. Let’s get started</p><p>I’ll be setting this up on an <strong>Ubuntu 18.10 </strong>machine.</p><p>Almost all versions of Linux come with <strong>systemd</strong> out of the box, but if your’s didn’t come with it then you can simply run the following command:</p><pre>sudo apt-get install -y systemd</pre><p><strong>Note:</strong> The -y flag means to install the packages and dependencies quickly.</p><p>To check which version of systemd you have simply run the command:</p><pre>systemd --version</pre><p>Create a python file whatever you like. I’m going to call mine test.py.</p><p><strong>sudo nano test.py</strong></p><pre>import time<br>from datetime import datetime<br></pre><pre>while True:<br>    with open(&quot;timestamp.txt&quot;, &quot;a&quot;) as f:<br>        f.write(&quot;The current timestamp is: &quot; + str(datetime.now()))<br>        f.close()<br>    time.sleep(10)</pre><p>The above script will write the current timestamp in the file after every 10 seconds. Let’s write the service now.</p><p><strong>sudo nano /etc/systemd/system/test.service </strong><em>(name of the service which is test in this case)</em></p><pre>[Unit]<br>Description=My test service<br>After=multi-user.target</pre><pre>[Service]<br>Type=simple<br>Restart=always<br>ExecStart=/usr/bin/python3 /home/&lt;username&gt;/test.py</pre><pre>[Install]<br>WantedBy=multi-user.target</pre><p>Insert the username in your OS where <strong>&lt;username&gt;</strong> is written. The <strong>ExecStart </strong>flag takes in the command that you want to run. So basically the first argument is the python path (in my case it’s python3) and the second argument is the path to the script that needs to be executed. <strong>Restart</strong> flag is set to always because I want to restart my service if the server gets restarted. For more information on this, you can go to this <a href="https://www.freedesktop.org/software/systemd/man/systemd.service.html">link</a>. Now we need to reload the daemon.</p><pre>sudo systemctl daemon-reload</pre><p>Let’s enable our service so that it doesn’t get disabled if the server restarts.</p><pre>sudo systemctl enable test.service</pre><p>And now let’ start our service.</p><pre>sudo systemctl start test.service</pre><p>Now our service is up and running.</p><p><strong>Note:</strong> The file will be written in the root directory <em>(/)</em> because the program will write in the path from the perspective of systemd. To change that simply edit out the file path. For example:</p><pre>import time<br>from datetime import datetime</pre><pre>path_to_file = &quot;enter the desired path of the file&quot;</pre><pre>while True:<br>    with open(path_to_file, &quot;a&quot;) as f:<br>        f.write(&quot;The current timestamp is: &quot; + str(datetime.now()))<br>        f.close()<br>    time.sleep(10)</pre><p>There are several commands you can do to start, stop, restart, and check status.</p><p>To stop the service.</p><pre>sudo systemctl stop <em>name_of_your_service</em></pre><p>To restart.</p><pre>sudo systemctl restart <em>name_of_your_service</em></pre><p>To check status.</p><pre>sudo systemctl status <em>name_of_your_service</em></pre><p>This was a very basic introduction to systemd aimed at beginners who want to get started with writing their own systemd services for python. If you want a deep dive into systemd and systemctl, here is a <a href="https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units">detailed guide by the digital ocean</a>.</p><p><strong>NOTE:</strong> This doesn’t only apply to python scripts. You can basically run any program with this regardless of the programming language your program is written in.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0cc55a42267" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267">Setup a python script as a service through systemctl/systemd</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Browser Automation with Python]]></title>
            <link>https://wasiullah-khan21.medium.com/browser-automation-with-python-2bdaad629a99?source=rss-5ae054cb4084------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bdaad629a99</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[web-automation]]></category>
            <category><![CDATA[script]]></category>
            <dc:creator><![CDATA[WasiUllah Khan]]></dc:creator>
            <pubDate>Thu, 21 Mar 2019 17:19:26 GMT</pubDate>
            <atom:updated>2019-03-21T17:26:23.742Z</atom:updated>
            <content:encoded><![CDATA[<h3>Browser Controller, Python</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sB7eLKvQG1_DVlLJ" /><figcaption>Photo by <a href="https://unsplash.com/@cgower?utm_source=medium&amp;utm_medium=referral">Christopher Gower</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Everyone in the tech community knows that Python is very handy for automating almost anything! So <em>bored me</em> decided to write a 2 line script to open up the backing tracks(<em>I’m a guitarist as well)</em> that I need from YouTube without manually having to search for them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*bLI99x7MC30Xf6WEgVBlUg.png" /></figure><ol><li>Execute the Python script.</li><li>Links are opened in the browser</li></ol><h3><strong>To run:</strong></h3><h4>$ <em>python3 script.py</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*LqKbyFBXE-DB9ybv2LIw9w.png" /><figcaption><strong>Source Code</strong></figcaption></figure><p>Python has a built-in library called <strong>webbrowser</strong> which opens up links in the browser. In the above code, I’m iterating over a Python dictionary containing all the links and the script opens all the links in new tabs. I stored the dictionary in a separate Python file known as <em>config</em> so that I can easily add new links without having to hard code it again and again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*h-I2SX_wyfxftV5dZd6VAA.png" /><figcaption><strong>config file</strong></figcaption></figure><p>You can download the script from <a href="https://github.com/calmconquerer/browser-script">here</a>.</p><p>You can check out my <a href="https://github.com/calmconquerer">GitHub</a> for more projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bdaad629a99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DropBox File Uploader]]></title>
            <link>https://wasiullah-khan21.medium.com/dropbox-file-uploader-caf6345ac70a?source=rss-5ae054cb4084------2</link>
            <guid isPermaLink="false">https://medium.com/p/caf6345ac70a</guid>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[dropbox]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[WasiUllah Khan]]></dc:creator>
            <pubDate>Thu, 22 Nov 2018 08:35:38 GMT</pubDate>
            <atom:updated>2018-11-22T08:35:38.714Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s been several months since I’ve started learning programming and my go to language is Python. The first project I made was a snake game (which I’ll write about some other time) and the second one was a DropBox File Uploader.</p><p>So the App basically uploads files from a source folder from the computer to the target folder created in DropBox. The paths aren’t hard coded so they can be changed from the configuration file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*JuzXaaa394ovbgbV8yRV5A.png" /></figure><p>The first block basically goes through the source directory and uploads each file if the size of it is less than the max chunk size (DropBox API can upload a file in one shot if it’s up to 150 MB). I’ve set the max chunk size to 2 MB since I have a poor internet connection where I live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*XkSK9McSPZ0zKIdpS-va3g.png" /></figure><p>The second block creates an upload session if the file is larger than the max chunk size. It basically divides the file into smaller chunks of 1 MB (which can be changed from the configuration file) and then uploads the file in chunks. I’ve configured fluentd and all the errors are logged in a file (pretty messy but I’ll work on it) in the td-agent. I’ve also scheduled the App with CRONTAB so the app runs in the background</p><p>For you to use this app you will need to create a developer’s account in DropBox and then generate an access token for it. The access token can be pasted in the configuration file.</p><p><strong>Link for the App</strong></p><p><a href="https://github.com/calmconquerer/dropbox-file-uploader">https://github.com/calmconquerer/dropbox-file-uploader</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caf6345ac70a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>