<?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 Shivam Bansal on Medium]]></title>
        <description><![CDATA[Stories by Shivam Bansal on Medium]]></description>
        <link>https://medium.com/@shivam_softwareartist?source=rss-51cbc3f9bb77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UukjIqLm1zsO-Ugwz4jZbQ.jpeg</url>
            <title>Stories by Shivam Bansal on Medium</title>
            <link>https://medium.com/@shivam_softwareartist?source=rss-51cbc3f9bb77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:26:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivam_softwareartist/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[Deploy your static website on Netlify]]></title>
            <link>https://medium.com/@shivam_softwareartist/deploy-your-static-website-on-netlify-4c9c11dbaef9?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c9c11dbaef9</guid>
            <category><![CDATA[static-websites]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[netlify]]></category>
            <category><![CDATA[website-development]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Sun, 26 Apr 2020 22:15:17 GMT</pubDate>
            <atom:updated>2020-04-27T05:21:49.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORSQPdtQPYWiLziFnpq5rw.png" /><figcaption>netlify.com</figcaption></figure><p>In college days, I always wonder how to deploy my website and I used to think that it is a big and complicated process to deploy even for a simple static website. But now I can say Netlify solved this problem for most of the developers who are looking to deploy their static website.</p><p>First, go to <a href="https://www.netlify.com/">netlify.com</a> and Sign up there, Remember, to do the first login you have to verify your account from an email sent by netlify to your registered email address.</p><p>After logging in, you can see below image, I have already deployed 3 projects that’s why they are on display in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*cvvAUFXPYk0L-H-ggnjScg.png" /><figcaption>Netlify.com</figcaption></figure><p>There are three ways to deploy a site on netlify:</p><ol><li>By simply drag and drop your project folder here.</li><li>By adding your GitHub your account.</li><li>By adding your git to your netlify account(kind of automation).</li></ol><p>For a client perspective, I think drag and drop is a better choice as you don’t want to add your GitHub to a client’s netlify account. Also, drag and drop is quick and easy to understand for people who don’t know about git and GitHub.</p><p>So go to your project folder’s location, drag it here and wait for a few moments to see it deployed and tadaann the initial deployment is complete.</p><p>In the below screenshot you can see the name which is generated by netlify and just below that your website link(i have blurred it)in green colour would be activated.</p><p>Note: Your netlify subdomain can be in either form of mynetlify.com or mynetlify.app, as netlify updated it recently in April 2020.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*cyUnYDsgE5sqTGnDlOBl4Q.jpeg" /><figcaption>Netlify.com</figcaption></figure><p>If you are a college student and just want your website to deploy somewhere then this is done for you, you can share and show this link to your teachers/mentors or to the external invigilator in semester submissions.</p><p>Now if you want to deploy it on a custom domain then let’s start.</p><p>Hoping you have a registered domain, if not then you can buy it from <a href="https://www.hostinger.in/">Hostinger</a> at cheap price.</p><p>Now in the above image, you can see three steps:</p><ol><li>Your site is deployed with a right tick means we already completed the first step,</li><li>Set up a custom domain,</li><li>Secure your site with HTTPS.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*nV8zQnmyuibxhsrKaBUJyQ.png" /><figcaption>netlify.com</figcaption></figure><p>Now go to step two and click on it, you can see something shown in the image:</p><p>Type your domain here in the format of placeholder and click verify. It may ask you “if you are the owner of the domain” click yes and don’t bother if it may not ask you anything.</p><p>Now you can see a page similar to the below image. Here in domain management, you can see three domains:</p><ol><li>Default subdomain of netlify in green colour.</li><li>Then your Primary domain.</li><li>Then your subdomain which redirects to your Primary domain.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eYToE2wMG0CqbWS4EU2CXA.jpeg" /></figure><p>You can see an alert “Check DNS configuration” in the same line of your domains, which means you have to change your domain’s DNS settings and you have to add “A” record &amp; “CNAME” record.</p><p>Now go to the site from where you have purchased your domain and then go to the <strong>Domains</strong> tab in your team dashboard and select the domain you want to edit:</p><ol><li>At the bottom of the DNS records panel, select <strong>Add new record</strong>.</li><li>Choose the type of record to create from the dropdown menu and fill in the remaining options. The fields you need to fill out will depend on the type of record you select.</li><li>Select <strong>Save</strong> to create the record and make the changes live.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLhCfbAPyduV_ESba2xALA.png" /><figcaption>netlify.com</figcaption></figure><p>Your ‘A’ and ‘CNAME’ record would look like this and the value of CNAME will be subdomain generated by netlify for your website.</p><p>Check the <a href="https://docs.netlify.com/domains-https/netlify-dns/dns-records/#add-a-new-record">documentation</a> or comment if you have any confusion in setting records.</p><p>Note: it can take up to a few hours for record changes to publish.</p><p>Now go back to your netlify account and refresh and you can see those alert signs are not there anymore because the record changes are published.</p><p>Now you can run your site on your custom domain, remember it will run in non-secure mode(http://yourdomain.com) as you have still not verified the DNS configuration or not secure your site with HTTPS which is our third step mentioned in starting of this blog.</p><p>So now in the domain management, you can see “HTTPS” at the last and you need to click on “Verify DNS configuration” and after clicking you can see a message displaying there which is “DNS verification was successful”.</p><p>This will complete your deployment process and you can see your website is deployed on your custom domain in secure https.</p><p>Now if you want to update the changes on your website then:</p><ol><li>Login to your netlify account,</li><li>Select the project,</li><li>Go to ‘Deploys’ in breadcrumbs/navbar,</li><li>Drag &amp; drop your project folder,</li><li>Netlify will publish the changes in a few seconds.</li></ol><p>Okay, that’s it, go and deploy as many websites as you can.</p><p>For video tutorials, you can check out “Dev Ed” on youtube and his video <a href="https://www.youtube.com/watch?v=tTKnuVx5qWA&amp;t=440s">here</a>.</p><p>Remember we talked about that there are other two methods as well to deploy your website on netlify, so for that, you can check the youtube channel <a href="https://www.youtube.com/channel/UC29ju8bIPH5as8OGnQzwJyA">Traversy Media</a> and this channel has a video tutorial that explains how to add your Git and Github to netlify, check out the video <a href="https://www.youtube.com/watch?v=bjVUqvcCnxM">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c9c11dbaef9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git & Github(Doable & Understandable things for beginner)]]></title>
            <link>https://medium.datadriveninvestor.com/git-github-things-to-understand-for-a-beginner-425b4b3865bf?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/425b4b3865bf</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[remote-working]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Mon, 01 Jul 2019 12:38:44 GMT</pubDate>
            <atom:updated>2019-12-27T05:20:00.647Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://www.track.datadriveninvestor.com/1B9E"><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Ze_ffAiufMmq8paV" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xa9IgC_zxlXA-spfVCFEbQ.jpeg" /></figure><p>Git is a version control system that deals with all versions of a project and Github is a git repository hosting service.</p><p>Git is used locally on our computer and Github provides a Web-based graphical interface for it.</p><p>Understand that Git &amp; Github are two different things that can be used separately, but for our convenience, we use both together.</p><h3>What GIT &amp; GITHUB DO:</h3><p>It saves all edited history, files before editing and after editing of a project or repository so that you can see any file anytime.</p><p>It allows us to work remotely on a repository.</p><h3>What we do on Git &amp; Github:</h3><p>In general, we perform either of the 2 tasks on Git &amp; Github:</p><ol><li>Upload a new project on Github.</li><li>Make changes on a project that is already on Github.</li></ol><p><a href="https://www.datadriveninvestor.com/2019/01/23/which-is-more-promising-data-science-or-software-engineering/">Which is More Promising: Data Science or Software Engineering? | Data Driven Investor</a></p><h3>Upload a project:</h3><p>First of all, make sure you have properly installed git on your system.</p><p>Step 1: Go to your profile on Github and click on ‘New repository’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*Lj40mhQmv1bCESLf1HT1kw.png" /><figcaption>1. Create repository</figcaption></figure><ul><li>Add repository name and description then click on the green button ‘Create repository’.</li></ul><p>Note: Don’t initialize it with Readme directly from here(Github).</p><ul><li>As soon as you hit that green button you will come to :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*LUKdksS8nm89QbvDqgjOaQ.png" /><figcaption>2. Github</figcaption></figure><p>Now go to your folder where your project is present and add a README.md file.</p><p>Open your terminal where your project holds and do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*6PC_pkyJdx49Q2Zd2ZSDmw.png" /><figcaption>3. Terminal</figcaption></figure><p>Make sure your terminal is located in the project folder where all the files are present.</p><p>The whole process of uploading a project is generally about 6 steps:</p><ol><li><em>git init:</em> This command convert your project into a git repository.</li><li><em>git add -A:</em> This is used to add all the files of the project.</li><li><em>git status:</em> It will tell you which branch you are on and the changes to be done.</li><li><em>git commit -m “first commit”:</em> This command is to commit changes and <em>-m</em> is used to give commit message.</li><li><em>git remote add origin https://github.com/shivamsoftwareartist/blog.git :</em> This command sets the usual path of where the remote repo points to. The repo link will be different for every other repo.</li><li><em>git push -u origin master:</em> This will upload the content of local repo to your remote repo and as it first commits so it is set on the master branch. It will then ask you to enter the Username and Password of your GitHub profile.</li></ol><p>Note: Commit Message is important as it gives clue to others what &amp; where the changes are made.</p><h3>Make Changes or Contributing On Existing Projects on Github</h3><p>There are two types of contribution :</p><ol><li>Contributing to your own project.</li><li>Contributing to other’s project.</li></ol><p>There is not so much difference in their execution.</p><h4>Contribution:</h4><p><strong>Contributing to your own project:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*ApYJZqzZAhBcLCZbcnym8A.png" /><figcaption>4. Terminal</figcaption></figure><ol><li><em>git clone https://github.com/shivamsoftwareartist/blog.git:</em> This command is used to get the project to your local computer and link would be different for the different repository.</li><li><em>git checkout -b branch1:</em> Now go to the repository and create a branch(branch1 is the name of the branch).</li><li><em>git status:</em> It will tell you which branch you are on.</li><li><em>git remote -v:</em> It will tell you about your origin.</li><li>Now make changes you want to make in the project i.e. adding files or edit files you want to change.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*GfnxO4nod6GuIV7yUlr8Ow.png" /><figcaption>5. Terminal</figcaption></figure><p>6. <em>git add -A:</em> This will add all the changes made in the project.</p><p>7. Do git status again to check what are the changes to be committed.</p><p>8. <em>git commit -m “first contribution”:</em> This command will commit all your changes and commit message is equally important.</p><p>9. <em>git push -u origin branch1:</em> This will push your changes but don’t push directly onto the master branch.</p><p>Now go to GitHub profile and you will see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*SiXkr3G1L7CXH8G9e3XjeA.png" /><figcaption>6. Github</figcaption></figure><p>10. You would see the ‘Compare &amp; pull request’ button to create a pull request. As soon as you created that pull request your contribution is complete.</p><p>If it’s your own repo then you can merge it whenever you want it.</p><p><strong>Contributing to other’s project :</strong></p><p>Before you contribute to other’s project you must decide which issue you are working on or create one for the change you want.</p><p>There is not so much difference in the process. We will follow the same process explained before but keep these things in mind:</p><ol><li><em>Fork:</em> Here the first step would be to fork or copy the repo into your GitHub profile and then clone it your local.</li><li>Now run the command in terminal to clone the project locally.</li><li><em>pip install -r requirements.txt:</em> Install all requirements through this command.</li><li>Now perform steps from step2 to step7 explained before and make sure you made a separate branch.</li><li>Commit your changes and in commit message always mention the issue no. like #1 or whatever issue no. is given so your commit will be identifiable with that issue no.</li><li>Push your changes but never push directly onto the master branch.</li><li>Go to GitHub and click on ‘Compare &amp; pull request’ button and then mention the issue no in the message and that will reference it to the issue.</li><li>In this case, the owner of the repo will look into your commit and then he/she will merge it only if they are convinced with your changes.</li></ol><p>Now my suggestion to practice the process is to first create your own repo and start contributing to it. The more you contribute the more you’ll learn new things.</p><p>This blog isn’t about the detail explanation of Git &amp; Github terminologies. This blog is for the people who want to start immediately.</p><p>You should read <a href="https://git-scm.com/"><em>Git</em></a> documentation for the detailed explanation.</p><p>There is a lot to do with Git &amp; GitHub and you can google them or surf youtube for various video tutorials.</p><p>If you have any doubt regarding this blog then comment or ping me on telegram <a href="https://t.me/shivam_softwareartist">shivam_softwareartist</a>.</p><p>So what are you waiting for? start contributing and make open source your new office to learn and earn.</p><p>HAPPY CODING…😊😊</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=425b4b3865bf" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/git-github-things-to-understand-for-a-beginner-425b4b3865bf">Git &amp; Github(Doable &amp; Understandable things for beginner)</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python-Django(views, templates & models)]]></title>
            <link>https://medium.datadriveninvestor.com/python-django-views-templates-models-f0844a00db70?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0844a00db70</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Thu, 21 Feb 2019 16:59:58 GMT</pubDate>
            <atom:updated>2021-06-06T08:25:12.182Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://www.track.datadriveninvestor.com/1B9E"><img alt="" src="https://cdn-images-1.medium.com/max/700/0*dp9DcJxPSInQQTjK" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_pC3-Is47lztWPspLvR9Q.jpeg" /><figcaption>python.org/djangoproject.com</figcaption></figure><p>Django is a rich web framework written in python. Django is a free and open source and has capabilities to do wonders. Django is fast, takes security issues seriously and exceedingly scalable.</p><p>Instagram, one of the most prolific social media application use the Django framework. Google, the top ten web applications that use Django and you’ll be amazed by its reach.</p><h4>Functionality</h4><p>A Django project is a collection of different applications having different functionalities.</p><p>Django allows us to map a requested URL from a user to the code that’s actually meant to handle it and it also allows us to create that requested HTML dynamically.</p><p>By using templates we can actually inject calculated values or information from the database into an HTML page to show to the user.</p><p>So we are gonna connecting all the front end stuff to the backend stuff through this web framework.</p><h3>Installation</h3><p>It is always suggested that when you learn something new and ready to apply to your system then you should prefer to use it in a ‘Virtual Environment’.</p><p>It then protects your system as new software or application or any technology may harm in a way that you probably don&#39;t know for now.</p><p>Once you understand it completely you can then ignore the virtual environment.</p><p>To create a virtual environment(python env) in Linux we do:</p><pre>python3 -m venv myenv</pre><p>“myenv” is the name of the virtual environment and to activate the virtual environment use either of the two commands mention below:</p><pre>source myenv/bin/activate</pre><pre>. myenv/bin/activate</pre><p>Now to install Django into the virtual environment, type:</p><pre>pip install django</pre><p>You can read about the whole installation process of Django through its <a href="https://docs.djangoproject.com/en/2.1/intro/install/">docs https://docs.djangoproject.com/en/2.1/intro/install/</a>.</p><h3>FIRST PROJECT</h3><pre>django-admin startproject mysite</pre><p>The above command will start a new project <em>mysite</em>. Now inside your project, you have a directory having the same name <em>mysite</em> and <em>managed.py</em> file which we are going to use for most of the time.</p><p>Now in the mysite directory, you’ll have 4 files:</p><ol><li>A blank <em>__init__.py</em> file lets Python know this directory should be treated as a python package.</li><li>A <em>settings.py</em> file where you store all of our project settings.</li><li>An <em>urls.py</em> file to save all the URL patterns for the project and to relate different pages of the application.</li><li>A <em>wsgi.py</em> file acts as the web server Gateway interface and will help us later stage of the project.</li></ol><p>Now use the manage.py in the command line as shown and look what happens:</p><pre>python manage.py runserver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*4vRtUrKSaqDACiRnKbUaAA.png" /><figcaption>1. Terminal</figcaption></figure><p>You’ll see this type of result and can ignore the warning of the unapplied migrations for now.</p><p>We’ll see that in the later stage of the project.</p><p>Copy and paste the URL <a href="http://127.0.0.1:8000/"><em>http://127.0.0.1:8000/</em></a> into your web browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usLBqg12ccjaZlFjymTMag.png" /><figcaption>2. The first web page</figcaption></figure><p>Then You can see your very first web page being locally hosted on your computer. Congratulations you just ran your first single project.</p><h3>YOUR FIRST APP</h3><p>To start a new application in Django you need to enter this command:</p><pre>python manage.py startapp my_app</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*WI9PeUOqBSEiqhgtKNnUKw.png" /><figcaption>3. Created app</figcaption></figure><p>Here, you can see our <em>my_app</em> application has created.</p><p>The<em> my_app</em> carries some files as shown in image 3.</p><p>Let us see what these files are used for.</p><ol><li><em>__init__.py</em> is the blank script and due to its name let’s python know that directory will be treated as a package.</li><li><em>admin.py</em> is the place where you register your models to use them with Django’s admin interface.</li><li><em>apps.py, </em>Here we can place specific configurations of the application.</li><li><em>models.py</em> is the place where we are going to store our data models and the entities and relationships between the data will be specified.</li><li><em>test.py</em> file is used to save different functions to test our own application.</li><li><em>views.py </em>handle the requests and return responses.</li><li><em>‘migrations’</em> folder stores database and it’s specific information as it relates to the models.</li></ol><h4>Creating Views and Mapping it to URL</h4><p>Everything that you see in Django is a view like a homepage view, or a detail view for e.g. when we open a profile in Instagram then what we see is referring to homepage view and when we open a particular post in that profile then it is detail view.</p><p>To create a view in views.py file and then map it urls.py file we’ll create a view that will show us the most prolific statement of the programming world i.e. “Hello World”.</p><p>Now open the views.py and you’ll find the first import statement there.</p><p>We need to enter the next import statement:</p><pre>from django.http import HttpResponse</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*9K73mxvRXOB_SsqeLO-ygA.png" /><figcaption>7. views.py</figcaption></figure><p>Now we’ll create an index function that will take in a request and return an HTTP response as shown in image 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*U67Q0sMPeBFZ9pkYpECXVA.png" /><figcaption>8. my_app/urls.py</figcaption></figure><p>Then we have to Create/Open the urls.py file in my_app and import views and map the view as shown in image 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*cmiBDD3ImeqkpltlWZjthQ.png" /><figcaption>9. mysite/urls.py</figcaption></figure><p>Open the urls.py file in mysite and do what shown in image 9.</p><p>You can also read the instructions to add the views and other URL configurations in your editor.</p><p>As Django is open-source so the framework keeps on developing time-to-time.</p><p>And if you are using earlier versions, then we used some regular expressions to add the views but now we do it differently.</p><p>Run ‘python manage.py runserver’ again to check, if we are getting our “Hello WORLD” statement or not.</p><p>Copy the URL <a href="http://127.0.0.1:8000/my_app"><em>http://127.0.0.1:8000/my_app</em></a><em> </em>and run it into your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*AoihQTHOxOmTGJla8CbvkA.png" /><figcaption>10. Mozilla browser</figcaption></figure><p>If you can see the result shown then Congratulations. If you are getting an error then check your urls.py file, you may not write the import statement correctly or it can also be a syntax error while adding the method to ‘urlpatterns’.</p><p>Summarising the whole process :</p><p>1. Create a view in the <em>views.py</em> file in “my_app”.</p><p>2. Create an <em>urls.py</em> file in “my_app” and map the view here i.e. ‘my_app/urls.py’.</p><p>3. Open the <em>urls.py</em> file in “mysite” and map the URL file of “my_app” here i.e. ‘mysite/urls.py’.</p><p>Note: Don’t get confused between the two <em>urls.py</em> file as one belongs to my_app and the other belongs to the project mysite.</p><h3>Models</h3><p>A Model is a source of information about our data. It contains behavioural aspects and other essential features of our data.</p><p>Models are a way to create a database for a Django project. Each model maps to a single database table that is every time you create a model basically it is going to map to a database table.</p><p>From now we will work on a project “polls” given in the <a href="https://docs.djangoproject.com/en/2.1/intro/">documentation</a> of Django. So first go through the <a href="https://docs.djangoproject.com/en/2.1/intro/tutorial01/">first part</a> of the documentation or you just redo the above steps having an application named “polls”.</p><p>SQLite is the default database and if you wish to use the more scalable database for your project then install proper <a href="https://docs.djangoproject.com/en/2.1/topics/install/#database-installation">database bindings</a>.</p><p>You can check your default database in settings.py file, it should be something like this:</p><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.db.backends.sqlite3&#39;,<br>        &#39;NAME&#39;: os.path.join(BASE_DIR, &#39;db.sqlite3&#39;),<br>    }<br>}</pre><p>In same settings.py file we can see INSTALLED_APPS by default for common uses:</p><pre>INSTALLED_APPS = [<br>    &#39;django.contrib.admin&#39;,<br>    &#39;django.contrib.auth&#39;,<br>    &#39;django.contrib.contenttypes&#39;,<br>    &#39;django.contrib.sessions&#39;,<br>    &#39;django.contrib.messages&#39;,<br>    &#39;django.contrib.staticfiles&#39;,<br>]</pre><p>Some of these apps use at least one database, so to create table run the command:</p><pre>python manage.py migrate</pre><p>This command will look at INSTALLED_APPS and then create necessary tables. The message for each migration it applies can be seen on the terminal/command line.</p><h3>CREATING MODELS</h3><p>To create models got to polls/models.py file and create models:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*UoYXTGleIYceR_5QSSfgIw.png" /><figcaption>11. polls/models.py</figcaption></figure><p>We can create as many models as we want. Here we create two models and each inherits its features from <em>models.Model.</em></p><p>In these models, each field is represented by <a href="https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.Field"><em>Field</em></a> class for e.g. <a href="https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.CharField"><em>CharField</em></a> for character and <a href="https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.DateTimeField"><em>DateTimeField</em></a><em> </em>for date &amp; time. To make more friendly to system, Fields are named as question_text and pub_date, Our database will take it as column name and we’ll use it in python code.</p><p>There is a relationship defined by <a href="https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.ForeignKey"><em>Foreign Key</em></a> that tells each choice is related to a single question.</p><p>It is also important to add __str__ method just for our convenience when we deal with our interactive prompt.</p><h4>ACTIVATING MODELS</h4><p>The next step is to add or install our “polls” app and for that, we need to add app configuration in INSTALLED_APPS. The app configuration can be seen in <em>apps.py</em> file.:</p><pre>INSTALLED_APPS = [<br>    &#39;django.contrib.admin&#39;,<br>    &#39;django.contrib.auth&#39;,<br>    &#39;django.contrib.contenttypes&#39;,<br>    &#39;django.contrib.sessions&#39;,<br>    &#39;django.contrib.messages&#39;,<br>    &#39;django.contrib.staticfiles&#39;,<br>    &#39;polls.apps.PollsConfig&#39;,<br>]</pre><p>As Django now knows to include “polls” app so, run the command in your terminal/command line:</p><pre>python manage.py makemigrations polls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*JAgc-PK5nRIO117fH-Cuig.png" /><figcaption>12. Terminal</figcaption></figure><p>When we run <em>makemigrations</em> we are telling Django that we have added a new model or made some changes to the existing models or both.</p><ul><li>It will create a database and it runs SQL statements like Create table for this app.</li><li>It will create a Python database-access API for accessing Question and Choice objects.</li></ul><p>You can also see the SQL table process by:</p><pre>python manage.py sqlmigrate polls 0001</pre><p>You will see a similar thing shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FsJeClpFSMLPmozeofMGgg.png" /><figcaption>13. Terminal</figcaption></figure><p>Now we’ll run migrate command again to create those model tables in our database:</p><pre>python manage.py migrate</pre><p>You can see all the operation and migrations running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*lHQDAWYvEaUU2DgLYojYLQ.png" /><figcaption>14. Applying migrations</figcaption></figure><p>Basically, whenever we change the existing model or add the new one then we have to <em>makemigrations</em> and then <em>migrate.</em></p><p>To see changes made to the model, Django gives us free API to play around with and to invoke python shell run:</p><pre>python manage.py shell</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*t3PjJTy3CIJ8jFtDVG1eNQ.png" /><figcaption>15. Database API</figcaption></figure><p>As we have given the __str__ method (image 11) in our model so when we run Question.objects.all() we get the result:</p><pre>&lt;QuerySet [&lt;Question: What’s up?&gt;, &lt;Question: What’s new?&gt;, &lt;Question: Whats poppin&gt;]&gt;</pre><p>If you won’t give the __str__ method then you will get the result like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*IxzZnO4Ekb5h4Py8OQXjEg.png" /><figcaption>15.1 API</figcaption></figure><p>In the choice model, we first add three choice_text and then delete one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*IZmJUvEYdg76AdPAxU7YkA.png" /><figcaption>15.2 API</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*pXJ7HN3pFgqJnf7McAdJNA.png" /><figcaption>15.3 API</figcaption></figure><p>You can skip this choice_model adding process as there is no mention in the docs.</p><p>To learn more on how to explore the <a href="https://docs.djangoproject.com/en/2.1/topics/db/queries/">database API</a> check the docs and before moving ahead we must do the exact operations opt-out in the image or at “<a href="https://docs.djangoproject.com/en/2.1/intro/tutorial02/#playing-with-the-api">Playing with API</a>” otherwise you’ll face difficulties while we deal with templates.</p><h3>ADMIN USER</h3><p>To avoid the tedious work of generating admin sites for staff and clients to add, delete and change content, Django automates the creation of admin interface models.</p><p>So we need to create an administrator user. Run the command into your terminal/command line:</p><pre>python manage.py createsuperuser</pre><p>It will ask you three things Username, Email address and Password.</p><p>NOTE: Always remember your Username and Password otherwise you will not be able to log-in and you can’t retrieve username &amp; password in this case.</p><p>Let&#39;s start the development server and run:</p><pre>python manage.py runserver</pre><p>Now open your web browser and load <a href="http://127.0.0.1:8000/admin/">http://127.0.0.1:8000/admin/</a> you will get to see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*HPnpzTg5chc_GS5rLGYWZQ.png" /><figcaption>16. Django-administration</figcaption></figure><p>Enter your Username and password then login. After login, you’ll see two editable content groups and users.</p><p>To see the model Question that we have created, we must add our model to the polls/admin.py as shown:</p><pre>from django.contrib import admin</pre><pre>from .models import Question</pre><pre>admin.site.register(Question)</pre><p>Refresh the webpage to see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*D3HreJ3xbCyjO52sHRDnUg.png" /><figcaption>17. Admin-page</figcaption></figure><p>Here you can see the Questions is now added and don’t worry Django just pluralise the names.</p><p>Click on Questions and you can see the form is automatically generated from the Question model and you can edit, add and delete questions from here.</p><h3>TEMPLATES</h3><p>A template in Django is used to tag and implement various logics from an HTML file to python.</p><p>There are two types of templates :</p><ol><li>{{ variable }} It is used for different variables.</li><li>{% logics %} It is used to put logic, loops and links.</li></ol><p>Whenever you call templates, Django looks for the exact key element in the application so first create templates folder in polls app then polls folder into the templates then index.html file into polls folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*bQQmQg_YOipeunCJY5WClQ.png" /><figcaption>18. sublime</figcaption></figure><p>Don’t get confused it will be like polls/templates/polls/index.html.</p><p>Template tagging becomes tedious when more apps will be created in the same project.</p><p>To avoid it we create a folder having the same name as polls in templates. Now we’ll create some more views like list and detail view and we’ll see the template tagging.</p><p>Step1: Open the Views.py and write the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*1Va17SCt8BikXaMUsaGAPA.png" /><figcaption>19. polls/views.py</figcaption></figure><p>Here we have created 4 views index, detail, results and vote view.</p><p>Step2: Add the views to polls/urls.py as shown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*Z1PgtyuIbDmD44qITpwcgQ.png" /><figcaption>20. polls/urls.py</figcaption></figure><p>Here question_id is fetched from the respective function in views.py file. The #statements are telling how other URL will work and you can check it also :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*OoI5Kp8W8N-E0hp3CRh84Q.png" /><figcaption>20.1 Browser</figcaption></figure><p>#ex: <a href="http://127.0.0.1:8000/polls/2/vote/">http://127.0.0.1:8000/polls</a>/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*2CMHmXvcxy6Q_5vMqQa6HA.png" /><figcaption>20.2 Browser</figcaption></figure><p>#ex: <a href="http://127.0.0.1:8000/polls/2/vote/">http://127.0.0.1:8000/polls/2</a>/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*kTglBgYRsx7vulSFWaw9Yg.png" /><figcaption>20.3 Browser</figcaption></figure><p>#ex: <a href="http://127.0.0.1:8000/polls/2/vote/">http://127.0.0.1:8000/polls/2</a>/results/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*QcCyaSIj4SCx8diXpri9gw.png" /><figcaption>20.4 Browser</figcaption></figure><p>#ex: <a href="http://127.0.0.1:8000/polls/2/vote/">http://127.0.0.1:8000/polls/2</a>/vote/</p><p>Step3: Now the write this HTML code into index.html:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*Xbsv3qcc7xY6GHGzbqY7LA.png" /><figcaption>21. polls/templates/polls/index.html</figcaption></figure><p>Step4: Now write this into detail.py :</p><pre>{{ question }}</pre><p>It will work for now.</p><p>So we have seen how we can create views, create models and use templates. We have also used free API access given by Django.</p><p>To read and learn more about Django read its <a href="https://docs.djangoproject.com/en/2.1/intro/">documentation</a>.</p><p>If you want to learn through video tutorials then check out the youtube channel “<a href="https://www.youtube.com/channel/UCqrILQNl5Ed9Dz6CGMyvMTQ">clever programmer</a>” and his playlist name “<a href="https://www.youtube.com/playlist?list=PL-J2q3Ga50oOpni_xS2PPUe4mf9lM96dD">Python Django Tutorial 2018 for Beginners</a>”.</p><p>For a different project checkout “<a href="https://www.youtube.com/playlist?list=PLQVvvaa0QuDe9nqlirjacLkBYdgc2inh3">sentdex</a>” youtube channel.</p><p>Sometimes it happens that you don’t understand the documentation because it is written in a standard way so I suggest you read “<a href="https://djangoforbeginners.com/">Django for beginners</a>”. It teaches Django step by step and has various projects to practice.</p><p>If you are an absolute beginner in python then read “<a href="https://pymbook.readthedocs.io/en/latest/">python for you and me</a>” written by Kushal Das. It will teach you everything you need as a beginner in python.</p><p>For more interesting stuff in Python read out “<a href="https://automatetheboringstuff.com/">Automate the boring stuff with python</a>”.</p><p>If you have any issue or queries with this tutorial then comment or ping me on Twitter <a href="https://twitter.com/softwareartist_">twitter.com/softwareartist_</a>or on Telegram <a href="https://t.me/shivam_softwareartist">@shivam_softwareartist</a>.</p><p>HAPPY CODING 🙂🙂</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0844a00db70" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/python-django-views-templates-models-f0844a00db70">Python-Django(views, templates &amp; models)</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WEB SCRAPING]]></title>
            <link>https://medium.datadriveninvestor.com/web-scraping-17b6891f9da4?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/17b6891f9da4</guid>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[selenium-webdriver]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Sat, 29 Dec 2018 10:00:28 GMT</pubDate>
            <atom:updated>2018-12-30T10:21:57.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://www.track.datadriveninvestor.com/1B9E"><img alt="" src="https://cdn-images-1.medium.com/max/700/0*69HYXiv7iu-QIINx" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*5yybFX25Qn-x5xZrcrqbfQ.jpeg" /></figure><p>Web scraping is a technique to surf web space. If we look to the wiki’s definition we can say that web scraping is used to extract a large amount of data from various websites.</p><p>Have a look on the internet, there are various methods and techniques given for scraping a website.</p><p>Here I am going to tell you about some basic methods that I recently learned.</p><p>The modules we are gonna discuss in this blog are:</p><ol><li><a href="https://docs.python.org/2/library/webbrowser.html">webbrowser</a></li><li><a href="https://requests.readthedocs.io/en/master/">Requests</a></li><li><a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/">BeautifulSoup</a></li><li><a href="https://selenium-python.readthedocs.io/">Selenium</a></li></ol><h3>“webbrowser” Module</h3><p>A webbrowser.open() function launch a new browser to a specific url:</p><pre>&gt;&gt;&gt; import webbrowser<br>&gt;&gt;&gt; webbrowser.open(&#39;http://google.com/&#39;)</pre><p>The above code will first import webbrowser module and then webbrowser.open() will open ‘google.com’. It opens the default browser of your system</p><p>Now suppose you need to find an address on the google maps you can easily do this by writing a simple script including this module as shown:</p><pre>&gt;&gt;&gt;import webbrowser, sys, pyperclip</pre><pre># Get address from command line.<br>&gt;&gt;&gt;if len(sys.argv) &gt; 1:<br>       address = &#39; &#39;.join(sys.argv[1:])  <br># Get address from clipboard.<br>...else:<br>       address = pyperclip.paste()</pre><pre>&gt;&gt;&gt;webbrowser.open(&#39;<a href="https://www.google.com/maps/place/&#39;">https://www.google.com/maps/place/&#39;</a> + address)</pre><p>Here, first command line arguments will be used and if there are no command line arguments then it will assume the clipboard having that address. So to get the clipboard content we can use <em>pyperclip.paste()</em> and then to launch the webbrowser with maps call <em>webbrowser.open()</em>.</p><p>This is the one use of the module that is shown above and you can learn more in details by going through its docs <a href="https://docs.python.org/2/library/webbrowser.html#">https://docs.python.org/2/library/webbrowser.html</a> .</p><h3>“REQUESTS” MODULE</h3><p><em>Requests</em> module is used to download files from the web. It is very easy and we don’t need to worry about issues like network errors &amp; connection problems.</p><p>This is a third party module so you’ll have to install it first, and it is always suggested to run third-party modules in virtual env. To install request module type:</p><pre>pip install requests</pre><p>To check if the module is properly installed or not run this command:</p><pre>import requests</pre><p>If there is no error message pop up means you have successfully installed the module. Now to download the web page type:</p><pre>import requests<br>page = requests.get(‘http://www.automatetheboringstuff.com’)</pre><p><em>Requests.get()</em> is the function used to download the complete web page. It takes the complete <em>URL</em> of the page. Then <em>type(page)</em> will give you the response from web server.</p><pre>&gt;&gt;&gt; type(page)<br>&lt;class &#39;requests.models.Response&#39;&gt;</pre><p>The downloaded web page is stored as a string in the Response object’s text variable on if the request succeeds. You can call <em>len(page.text)</em> to check the length of the text stored.</p><pre>&gt;&gt;&gt; len(page.text)<br>14139<br>&gt;&gt;&gt; print(page.text)</pre><p>As soon as you call the print statement you’ll see the complete text of page downloaded. It can be the complete source code or it can be any specific content depends on the request you made.</p><p>You can either save the entire text into your drive or set the limits according to your need.</p><p>You may be wondering why would you need to download the entire text material from the web in spite of just surfing over the web easily?</p><p>The answer is that there are scenarios where we need to surf over a web page but network issues don’t allow us, or in another case, we may find a book and we want a copy of it so we can use this method in both cases to download it. There are more situations where you stuck and easily get away by this method.</p><p>To read out more about requests module check the documentation <a href="https://requests.readthedocs.io/en/master/">https://requests.readthedocs.io/en/master/</a>.</p><h3>“BEAUTIFUL SOUP”</h3><p>Beautiful Soup is the module used for extracting information from an HTML page. It is a third-party module named as <em>bs4</em> that is Beautiful Soup, Version 4.</p><p>To install the module :</p><pre>pip install beautifulsoup4</pre><p>Basically, we use beautiful soup for parsing over HTML files. While using this module we are also going to use ‘webbrowser’ and ‘requests’ modules as well.</p><p>Before using this you should know about HTML and its tags. Not to worry you just need to know some basics to move in this module. You can go to <a href="http://www.w3schools.com/">W3schools.com</a> for learning basic HTML.</p><p>We use bs4.BeautifulSoup() to parse the HTML and it will return BeautifulSoup object. Now we can apply its methods to find specific parts of an HTML document.</p><p>Next, the thing you need to know about is a <em>parser</em> that is needed to parse the document. HTML parser is the one which is used here in this article. Generally, we use two parsers that are HTML and XML, you can search more over the web about different parsers.</p><pre>&gt;&gt;&gt; import requests, bs4<br>&gt;&gt;&gt; res = requests.get(&#39;<a href="http://nostarch.com&/#39;">http://nostarch.com&#39;</a>)<br>&gt;&gt;&gt; res.raise_for_status()<br>&gt;&gt;&gt; noStarchSoup = bs4.BeautifulSoup(res.text, &#39;html.parser&#39;)<br>&gt;&gt;&gt; type(noStarchSoup)<br>&lt;class &#39;bs4.BeautifulSoup&#39;&gt;</pre><p>Here we can see that requests.get() used to download the main page from the No starch press website and the text is passed through BeautifulSoup object to parse and the HTML parser is used to parse the text.</p><p><strong>Select() Method:</strong></p><p>Select() method is used to retrieve the web elements from a BeautifulSoup object. We pass the string of CSS selector for the element we are looking for.</p><p>Selectors are the totally different thing to understand, here we present some of the selectors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*wi8yMmPBwzhaFpYn6fEYUA.png" /><figcaption>CSS Selectors</figcaption></figure><p>All the things in this module move around CSS selectors. You need to learn some of the selectors for this module and how they can be used in this module.</p><p>You can learn some CSS selectors and how they are used in BeautifulSoup through Youtube Videos of <a href="https://www.youtube.com/channel/UC0bkqrWNBKxGZi-4gIfaCpg">Moondra</a>. This youtube channel has a playlist named “<a href="https://www.youtube.com/playlist?list=PLGKQkV4guDKEKZXAyeLQZjE6fulXHW11y">Gentle intro to web scraping</a>” and I found it very helpful in learning CSS selectors and their uses.</p><p>Now suppose we want to search for a topic like ‘shoes’. Then we first need to open the browser then search for shoes and after that, we’ll open different links one by one.</p><p>It would be very nice if we just need to type item name on the terminal/command line and the computer then automatically open the browser with the top search result. Let see how we can do it with the help of this module:</p><pre>import requests, sys, webbrowser                            #1<br>from bs4 import BeautifulSoup</pre><pre>print(&#39;Googling...&#39;)<br>res = requests.get(&#39;<a href="http://google.com/search?q=&#39;">http://google.com/search?q=&#39;</a> + &#39; &#39;.join(sys.argv[1:]))                                       #2<br>res.raise_for_status()</pre><pre>soup = BeautifulSoup(res.text, &#39;html.parser&#39;)               #3</pre><pre>linkElems = soup.select(&#39;.r a&#39;)                             #4</pre><pre>numOpen = min(5, len(linkElems))                            <br>for i in range(numOpen):                                    #5<br>    webbrowser.open(&#39;<a href="http://google.com&/#39;">http://google.com&#39;</a> + linkElems[i].get(&#39;href&#39;))</pre><p>As you can see, #1, we first import all the libraries we wanted. Then request the google home page and #2, Here “ ‘ ’.join(sys.argv[1:])” is used to get input from the terminal or command line. #3, Here you can see BeautifulSoup object and we passed ‘html.parser’ through it to parse the text. #4, Then soup.select() method is used for ‘r’ tag, you can find it out in videos suggested above. #5, We used for loop to tell the ‘webbrowser’ that to open only 5 tabs.</p><p>If HTML page of google home is same then you can use this code and pass an item name while running this into your terminal/command line. You can see it will open 5 tabs of top searches for the item name you passed.</p><p>To learn more about <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/">BeautifulSoup</a> you should go to its docs <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/">https://www.crummy.com/software/BeautifulSoup/bs4/doc/</a>.</p><h3>“SELENIUM” MODULE</h3><p>If you search about selenium module you’ll find that it is purposely used for testing applications. But the role of selenium in web scraping is very vast as it helps in automating the browsers. Then it is up to you that how much you can utilise the powers of this module.</p><p>Selenium allows you to interact with web pages in a much more advanced way. It launches a web browser so it is a bit slower than Requests and BeautifulSoup if you just need to download some files.</p><p>Selenium is a third-party module and you need ‘geckodriver’ to run this module. You can search and download it for using firefox browser or you can download it from <a href="https://github.com/bansalshivam/send_email_from_terminal-command_line/blob/master/geckodriver.log">here</a>.</p><p>Geckodriver is the link between selenium and the Firefox browser and there are different drivers available for different browsers.</p><p>Its a bit tricky to import modules for Selenium. For that you need to run :</p><pre>&gt;&gt;&gt; from selenium import webdriver                            #1<br>&gt;&gt;&gt; browser = webdriver.Firefox()                             #2<br>&gt;&gt;&gt; type(browser)<br>&lt;class &#39;selenium.webdriver.firefox.webdriver.WebDriver&#39;&gt;      #3</pre><p>#1 This is how you import a module in selenium. #2 Firefox starts up when webdriver.Firefox() is called. #3 here type() tells about the Webdriver data type.</p><h4>Element Finding:</h4><p>Webdriver objects have few different ways to find the elements on a page. The “find_element_*” and “find_elements_*” are two methods. The “fine_element_*” method returns a single and “fine_elements_*” returns a list of Webelement object for all matching elements on the page.</p><p>Some example is shown for finding elements on webdriver:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*fU3n7yF_4i3IhWM9EV-gmg.png" /><figcaption>Selenium’s WebDriver Methods for Finding Elements</figcaption></figure><p>As you can see the role of CSS selectors is also vital here like in BeautifulSoup.</p><h4>MOUSE &amp; KEYBOARD FUNCTIONS</h4><p>There are different methods available in the module that simulates some keyboard and mouse functions. Some keyboard keys are tough to type in string values.</p><p>Functions like <em>click()</em> and <em>submit()</em> are easy to access. These functions are used for selecting radio buttons and for submitting the forms.</p><pre>&gt;&gt;&gt;from selenium import webdriver<br>&gt;&gt;&gt;browser = webdriver.Firefox()<br>&gt;&gt;&gt;browser.get(&#39;<a href="http://gmail.com&/#39;">http://gmail.com&#39;</a>)<br>&gt;&gt;&gt;emailElem = browser.find_element_by_id(&#39;Email&#39;)<br>&gt;&gt;&gt;emailElem.send_keys(&#39;<a href="/service/mailto:not_my_real_email@gmail.com">not_my_real_email@gmail.com</a>&#39;)<br>&gt;&gt;&gt;passwordElem = browser.find_element_by_id(&#39;Passwd&#39;)<br>&gt;&gt;&gt;passwordElem.send_keys(&#39;12345&#39;)<br>&gt;&gt;&gt;passwordElem.submit()</pre><p>To send the keystroke to text fields, you need to find &lt;textarea&gt; or &lt;input&gt; element and then calling <em>send_keys()</em> method as shown in the above code. The code is just for understanding because Gmail may have changed the id of Username and Password text fields.</p><p>The Keyboard keys are stored in <em>selenium.webdriver.common.keys</em> module. At the top of your program type <em>from selenium.webdriver<br>.common.keys import Keys </em>to run this module. The commonly used key variables are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*2M-FbfU63aAnPrKiRBJO3A.png" /><figcaption>Commonly Used Variables in the selenium.webdriver.common.keys Module</figcaption></figure><h4>BROWSER BUTTONS</h4><p>Selenium also simulates various browser buttons such as:</p><ol><li>To click the back button use <strong><em>browser.back().</em></strong></li><li>To click the forward button <strong><em>browser.forward().</em></strong></li><li>To click the Refresh/Reload button <strong><em>browser.refresh().</em></strong></li><li>To close the Window button <strong><em>browser.quit().</em></strong></li></ol><p>Selenium can perform much more task than that are explained here. It can take screenshots, modify cookies and many more abilities are stored in this module. To learn more about the features of <a href="https://selenium-python.readthedocs.io/">Selenium</a> you can go to its documentation <a href="https://selenium-python.readthedocs.io/">https://selenium-python.readthedocs.io/.</a></p><h4>PROJECT</h4><p>Here is a simple project where you have to write a script to send emails directly from the terminal/command line. The steps include:</p><p>Step1. Load web browser</p><p>Step2. Login your details</p><p>Step 3. Go to the mail section</p><p>Step4. Compose</p><p>Step5. Enter receiver’s mail id</p><p>Step6. Enter message</p><p>Step7. Send</p><p>You can find the code of the project in my GitHub repository <a href="https://github.com/bansalshivam/send_email_from_terminal-command_line">send_email_from_terminal-command_line</a>.</p><p>There is a book “<a href="https://automatetheboringstuff.com/">Automate the Boring Stuff</a>”. It has projects for all different methods of web scraping explained above. You should check this book for the projects on various different topics. The blog is also inspired by the book.</p><p>You can also learn python through video tutorials of the book on <a href="http://udemy.com/">udemy.com</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17b6891f9da4" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/web-scraping-17b6891f9da4">WEB SCRAPING</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WORKING WITH EXCEL SPREADSHEETS]]></title>
            <link>https://medium.com/@shivam_softwareartist/working-with-excel-spreadsheets-485d343aacbb?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/485d343aacbb</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[excel-sheets]]></category>
            <category><![CDATA[automate]]></category>
            <category><![CDATA[excel]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Thu, 01 Nov 2018 23:27:58 GMT</pubDate>
            <atom:updated>2018-11-30T20:15:32.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBKHYjcvUsWxQzjBAEptqQ.png" /><figcaption>An Excel Sheet</figcaption></figure><p>The most popular and powerful spreadsheet application for windows is Excel. Since it’s release it has been one of the best spreadsheet application amongst all.</p><p>Suppose you have a job of handling excel sheets where you need to copy certain data from one spreadsheet and paste it to another one. Or you have to make small edits but you need to go through each and every row. Or you might have to search for something in different spreadsheets. All these tasks are very boring and if you can’t automate these tasks then it would be time-consuming as well.</p><p>These are exactly the sort of boring, mindless spreadsheet tasks that Python can do for you. The “openpyxl” module allows your Python programs to read and modify Excel spreadsheets files.</p><p>Although Excel is proprietary software from Microsoft, there are free alternatives that run on Windows, OS X, and Linux. Both LibreOffice Calc<br>and OpenOffice Calc work with Excel’s .xlsx file format for spreadsheets,<br>which means the openpyxl module can work on spreadsheets from these applications as well.</p><h3>ABOUT EXCEL DOCUMENT</h3><p>An Excel spreadsheet document is called a workbook. A single workbook is saved in a file with the .xlsx extension. Each workbook can contain multiple sheets (also called worksheets). The sheet the user is currently viewing (or last viewed before closing Excel) is called the active sheet.</p><p>Each sheet has columns (addressed by letters starting at A) and rows<br>(addressed by numbers starting at 1). A box at a particular column and row is<br>called a cell. Each cell can contain a number or text value. The grid of cells<br>with data makes up a sheet.</p><h3>INSTALLING THE openpyxl MODULE</h3><p>Python doesn’t come with “o<em>penpyxl” </em>module, so we have to install it. It’s a third party module so it is suggested to install it in a virtual environment.</p><p>For a virtual environment in Ubuntu, type “ <strong><em>python3 -m venv env </em></strong>” in the terminal. It will create a virtual environment in the current directory. To activate this virtual environment we need to enter “<strong><em>source env/bin/activate</em></strong>”.</p><p>Now to install openpyxl module enter “ <strong><em>pip install openpyxl </em></strong>”.</p><p>You can check out the full documentation for OpenPyXL at <a href="https://openpyxl.readthedocs.io/en/stable/">http://openpyxl.readthedocs.org/</a>.</p><h3>OPENING &amp; READING THE EXCEL DOCUMENT</h3><p>Here we are going to use some spreadsheets<em>. You can create your own spreadsheets or download it from </em><a href="http://nostarch.com/automatestuff/"><em>http://nostarch.com/automatestuff/.</em></a></p><pre>&gt;&gt;&gt; import openpyxl<br>&gt;&gt;&gt; wb = openpyxl.load_workbook(‘example.xlsx’)<br>&gt;&gt;&gt; type(wb)<br>&lt;class ‘openpyxl.workbook.workbook.Workbook’&gt;</pre><p>In the above example the ‘openpyxl.load_workbook()’ is the function that takes in the filename and returns a value of the workbook data type. It is a bit like opening a file object. One thing that to remember is that <em>example.xlsx </em>should be in the current working directory.</p><p>After the opening of a workbook the next thing you want to know about the sheets it has, ‘<em>get_sheet_names()’</em> is the function used to get names of all the sheets. You can call the ‘<em>get_active_sheet()’</em> method of a Workbook object to<br>get the workbook’s active sheet. The active sheet is the sheet that’s on top<br>when the workbook is opened in Excel.</p><h4>CELLS IN THE SHEET</h4><p>The Cell object has a value attribute that contains, unsurprisingly, the value stored in that cell. Cell objects also have rows, columns, and coordinate attributes that provide location information for the cell.</p><p>You can use ‘<em>sheet.cell()’</em> function to know about the cell by entering specific row and column. The first row or column integer is 1, not 0. For eg:</p><pre><em>&gt;&gt;&gt; sheet.cell(row=1, column=2)<br>&lt;Cell Sheet1.B1&gt;</em></pre><p>As you can see by passing the value of row = 1 &amp; column = 2 gives shell B1. You can determine the size of the sheet with the Worksheet object’s ‘<em>get_highest_row() and get_highest_column()’</em> methods.</p><p>Here an example to access the value of the cell in a particular row and column by using worksheets object’s rows and column attribute :</p><pre>&gt;&gt;&gt; import openpyxl<br>&gt;&gt;&gt; wb = openpyxl.load_workbook(‘example.xlsx’)<br>&gt;&gt;&gt; sheet = wb.get_active_sheet()<br>&gt;&gt;&gt; sheet.columns[1]<br>(&lt;Cell Sheet1.B1&gt;, &lt;Cell Sheet1.B2&gt;, &lt;Cell Sheet1.B3&gt;, &lt;Cell Sheet1.B4&gt;,<br>&lt;Cell Sheet1.B5&gt;, &lt;Cell Sheet1.B6&gt;, &lt;Cell Sheet1.B7&gt;)<br>&gt;&gt;&gt; for cellObj in sheet.columns[1]:<br> … print(cellObj.value)</pre><pre>Apples<br>Cherries<br>Pears<br>Oranges<br>Apples<br>Bananas<br>Strawberries</pre><h3>WORKBOOK, SHEETS, CELLS</h3><p>As a quick review, here’s a rundown of all the functions, methods, and data<br>types involved in reading a cell out of a spreadsheet file:<br>1. Import the openpyxl module.<br>2.Call the openpyxl.load_workbook() function.<br>3. Get a Workbook object.<br>4. Call the get_active_sheet() or get_sheet_by_name() workbook method.<br>5. Get a Worksheet object.<br>6. Use indexing or the cell() sheet method with row and column keyword-arguments.<br>7. Get a Cell object.<br>8. Read the Cell object’s value attribute.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=485d343aacbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the Boring Stuff: MANIPULATING IMAGES]]></title>
            <link>https://medium.datadriveninvestor.com/automate-the-boring-stuff-manipulating-images-33d67c70427d?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/33d67c70427d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[automate]]></category>
            <category><![CDATA[manipulating-images]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Tue, 30 Oct 2018 00:14:23 GMT</pubDate>
            <atom:updated>2018-11-06T21:31:06.805Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*gT-FnUTT4k1xAKizI4DBKQ.jpeg" /></figure><p>You must have gone through various image/photo editing tools or applications or software and it is always fun to polish images in a better way. Suppose you need to edit hundreds of images and for that, you’ll have to edit them one by one which will become time taking and boring. But in Python, <a href="https://pillow.readthedocs.io/en/5.3.x/"><strong>Pillow</strong></a> allows you to do such tasks with ease.</p><p>Pillow is a third-party Python module for interacting with image files. The module has several functions that make it easy to crop, resize and edit the content of an image. You can actually save your time in editing no. of images through this module.</p><p>Computer programs often represent a color in an image as an RGBA value.<br>An RGBA value is a group of numbers that specify the amount of red, green,<br>blue, and alpha (or transparency) in a colour. Each of these component values<br>is an integer from 0 (none at all) to 255 (the maximum).</p><p>In Pillow, RGBA values are represented by a tuple of four integer values. For example, the colour red is represented by (255, 0, 0, 255). This colour has the maximum amount of red, no green or blue, and the maximum alpha value, meaning it is fully opaque.</p><blockquote>Pillow offers the ImageColor.getcolor() function so you don’t have to memorize RGBA values for the colours you want to use.</blockquote><p>To import functions from <a href="https://pillow.readthedocs.io/en/5.3.x/">Pillow</a>, you need to install it first and it is suggested to install it in a virtual environment:</p><pre>pip install pillow</pre><p>Enter this into your Interactive shell:</p><pre>&gt;&gt;&gt; from PIL import ImageColor <br>&gt;&gt;&gt; ImageColor.getcolor(&#39;red&#39;, &#39;RGBA&#39;) <br>(255, 0, 0, 255)</pre><p>It gives you the RGBA value of the colour you passed into it.</p><p>Let make you more understanding about what we can do with Pillow through a project <strong><em>CUSTOM SEATING CARDS. </em></strong>You will also know how to use Pillow to some extent.</p><h3>PROJECT: CUSTOM SEATING CARDS</h3><p>DESCRIPTION: Use the ­ pillow module to create images for custom seating cards for your guests. For each of the guests listed in the guests.txt file from the resources at <a href="http://nostarch.com/automatestuff/,">http://nostarch.com/automatestuff/,</a> generate an image file with the guest name and some flowery decoration. A public domain flower image is available in the resources at <a href="https://nostarch.com/automatestuff/">http://nostarch.com/automatestuff/</a>.<br>To ensure that each seating card is the same size, add a black rectangle<br>on the edges of the invitation image so that when the image is printed out,<br>there will be a guideline for cutting. The PNG files that Pillow produces are<br>set to 72 pixels per inch, so a 4×5-inch card would require a 288×360-pixel<br>image.</p><h4>STEPS INVOLVE:</h4><p><strong>Step1</strong>: First you need to create a card of size 288×360-pixel and paste flower image on the card.</p><pre>import os <br>from PIL import Image, ImageDraw, ImageFont </pre><pre>#To create a new image <br>card = Image.new(&#39;RGBA&#39;, (360, 288), &#39;white&#39;) </pre><pre>#To open an existing image <br>flower = Image.open(&#39;cropFlower.jpg&#39;) </pre><pre>#Copy image <br>flowerCopy = flower.copy() </pre><pre>#Pasting flower image on card <br>card.paste(flowerCopy, (0,110))</pre><p><strong>Step2: </strong>Now you will create another black card and paste the previous one onto it then saving it with ‘.png’ extension:</p><pre>card2 = Image.new(&#39;RGBA&#39;, (364, 392), &#39;black&#39;) <br>card2.paste(card, (2,2)) </pre><pre>#Saving the image with .png extension <br>card2.save(&#39;card2.png&#39;)</pre><p><strong>Step3: </strong>Create a function to write names on the card:</p><pre>#creating a function  <br>def creating_card(guestsnames):  <br>    ceatingCard = Image.open(&#39;card2.png&#39;)  <br>#Adding font   <br>    font = ImageFont.truetype(&#39;coolvetica rg.ttf&#39;, 15)  <br>#Drawing Text on Image  <br>    draw  = ImageDraw.Draw(ceatingCard)  <br>    draw.text((120, 100), guestsnames, fill = &#39;blue&#39;, font = font)<br>    ceatingCard.save(guestsnames + &#39;.png&#39;)</pre><p><strong>Step4: </strong>Iterate through guess list and calling the function on each name:</p><pre>with open(&#39;guests.txt&#39;) as g:  <br>    guests = g.readlines()<br>for guest in guests:<br>    creating_card(guest)</pre><p>You will find the guest list on <a href="https://nostarch.com/automatestuff/">https://nostarch.com/automatestuff/</a> as ‘<em>guests.txt’.</em></p><p>In the above project, you can see how we use different functions of Pillow to manipulate images. You can do whatever you wanna do with an image using some functions like:</p><ul><li>RGBA value</li><li>.size</li><li>.new()</li><li>.crop()</li><li>.copy()</li><li>.paste()</li><li>.save()</li><li>.rotate()</li></ul><p>So start editing images in your creative way and enjoy.</p><p>To know more about the MANIPULATING IMAGES you can read “<a href="https://automatetheboringstuff.com/chapter7/">Automate The Boring Stuff with python</a>”. There, you will find more detail about manipulating images and a few projects related to it. To make the blog relatable, examples used in this blog are taken from the book.</p><p>You can also follow my <a href="https://github.com/bansalshivam">Github</a> repository <a href="https://github.com/bansalshivam/Projects-Chapter-17-Manipulating-Images--Automate-the-boring-stuff">https://github.com/bansalshivam/Projects-Chapter-17-Manipulating-Images--Automate-the-boring-stuff</a> for different projects given in this chapter.</p><p>For video tutorials about regular expression or learning the same topics of the book, you can go to <a href="https://www.udemy.com/">Udemy.com</a>. The <a href="https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS">Automate the Boring Stuff with Python Programming</a> online course on <a href="https://www.udemy.com/">Udemy.com</a> covers most of the content of the book. If you’d prefer a video format for learning to program, you can use the discount code <a href="https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS">FOR_LIKE_10_BUCKS</a> to get an 80% discount. You will have lifetime access to the course content and can post questions to the course’s forums.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33d67c70427d" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/automate-the-boring-stuff-manipulating-images-33d67c70427d">Automate the Boring Stuff: MANIPULATING IMAGES</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the boring stuff: Pattern matching with regular expression]]></title>
            <link>https://medium.com/@shivam_softwareartist/automate-the-boring-stuff-pattern-matching-with-regular-expression-cd83eaf1e93?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd83eaf1e93</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[pattern-matching]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Thu, 20 Sep 2018 22:35:38 GMT</pubDate>
            <atom:updated>2018-11-30T20:28:47.150Z</atom:updated>
            <content:encoded><![CDATA[<p>Wikipedia says “A <strong>regular expression </strong>is, in theoretical computer science and formal language theory, a sequence of characters that define a <em>search </em>pattern. Usually, this pattern is then used by string searching algorithms for “find” or “find and replace” operations on strings, or for input validation.”</p><p>Regular expression, regex or regexp are very helpful but many non-programmers and even some programmer mates do not know about it. Most modern text editors and word processors, such as Microsoft Word or OpenOffice, have ‘find’ and ‘find-and-find’ replace feature that can search based on regular expression. Regular expressions are huge time-savers, not just for software users but also for programmers. In fact, tech writer Cory Doctorow argues that even before teaching programming, we should be teaching regular expressions as a regular expression can be the difference between<br>solving a problem in 3 steps and solving it in 3,000 steps.</p><p>Suppose we want to find a phone number 415–555–9999 from a string. If we approach with regular coding without regex then no. of lines of code is more then with regex. Regular expressions are descriptions for a pattern of text. For example, a \d in a regex stands for a digit character that is, any single numeral 0 to 9. The regex \d\d\d-\d\d\d-\d\d\d\d is used to match the same text.<br>A string of three numbers, a hyphen, three more numbers, another hyphen,<br>and four numbers. Any other string would not match the \d\d\d-\d\d\d-\d\d<br>\d\d regex.</p><p>Now Let&#39;s see some coding, we want to find “415–555–9999&quot; from a string “Call me at 415–555–1011 tomorrow. 415–555–9999 is my office.” .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*Xc1xXLYbzrf5OaI47TdXxg.png" /><figcaption>Code to find no. without regex</figcaption></figure><p>The code to find the number in a string is about 26 lines. The isPhoneNumber() first checks the length of input then a ‘for loop’ check the numeric value for the first three values. Similarly different loops are used and at last another ‘for loop’ runs over the string where we want to find the number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*9DqG65G6OlqATkV2zEdpvw.png" /><figcaption>Code with regex</figcaption></figure><p>Here we can immediately notice the difference between the no. of lines. ‘\d\d\d-\d\d\d-\d\d\d\d’ is the regex pattern used to find ‘415–555–9999’.</p><p>While there are several steps to using regular expressions in Python, each<br>step is fairly simple:<br>1. Import the regex module with import re.<br>2. Create a Regex object with the re.compile() function. (Remember to use a<br>raw string.)<br>3. Pass the string you want to search into the Regex object’s search() method.<br>This returns a Match object.<br>4. Call the Match object’s group() method to return a string of the actual<br>matched text.</p><p>Use of <a href="http://regexpal.com/">web-based regular expression testers</a> can show you exactly<br>how a regex matches a piece of text that you enter. The tester at <a href="http://regexpal.com/">http://regexpal.com/</a> is recommended.</p><h3>More Pattern Matching with Regular Expressions</h3><h4>Grouping with Parenthesis :</h4><p>Adding parentheses will create groups in the regex: (\d\d\d)-(\d\d\d-\d\d\d\d). Then you can use the group() match object method to grab the matching text from just one group.</p><pre>&gt;&gt;&gt; phoneNumRegex = re.compile(r’(\d\d\d)-(\d\d\d-\d\d\d\d)’)<br>&gt;&gt;&gt; mo = phoneNumRegex.search(‘My number is 415–555–4242.’)<br>&gt;&gt;&gt; mo.group(1)<br>‘415’</pre><p>To retrieve all the groups at once, use the groups() method — note the plural form for the name.</p><pre>&gt;&gt;&gt; mo.groups()<br>(‘415’, ‘555–4242’)<br>&gt;&gt;&gt; areaCode, mainNumber = mo.groups()<br>&gt;&gt;&gt; print(areaCode)<br>415<br>&gt;&gt;&gt; print(mainNumber)<br>555–4242</pre><h4>Matching Multiple Groups with the Pipe | :</h4><p>You can use | anywhere you want to match one of many expressions. For example, the regular expression r’Cricket|Football’ will match either ‘Cricket’ or ‘Football’ .</p><h4>Optional Matching with the Question Mark ? :</h4><p>When you want to match any pattern optionally then use ?. For example:</p><pre>&gt;&gt;&gt; batRegex = re.compile(r’Bat(wo)?man’)<br>&gt;&gt;&gt; mo1 = batRegex.search(‘The Adventures of Batman’)<br>&gt;&gt;&gt; mo1.group()<br>‘Batman’<br>&gt;&gt;&gt; mo2 = batRegex.search(‘The Adventures of Batwoman’)<br>&gt;&gt;&gt; mo2.group()<br>‘Batwoman</pre><h4>Matching Zero or More with the Star |Matching One or More with the Plus:</h4><p>Star(*) means match zero or more, the plus(+) means match one or more</p><pre>&gt;&gt;&gt; batRegex = re.compile(r’Bat(wo)*man’)<br>&gt;&gt;&gt; mo1 = batRegex.search(‘The Adventures of Batman’)<br>&gt;&gt;&gt; mo1.group()<br>‘Batman’<br>&gt;&gt;&gt; batRegex = re.compile(r’Bat(wo)+man’)<br>&gt;&gt;&gt; mo1 = batRegex.search(‘The Adventures of Batwoman’)<br>&gt;&gt;&gt; mo1.group()<br>‘Batwoman’</pre><h4>Repetitions with Curly Brackets:</h4><p>When you want to match a pattern which has repetitions then we use {} curly brackets, for eg: (Ha){3} will match the string ‘HaHaHa’.</p><h3>Greedy and Non-greedy Matching</h3><p>When we see python regex, they are greedy by default, means they will match the longest string in ambiguous situations. The non-greedy version has the curly brackets followed by a question mark(?) matches the shortest string possible. For example:</p><pre>&gt;&gt;&gt; greedyHaRegex = re.compile(r’(Ha){3,5}’)<br>&gt;&gt;&gt; mo1 = greedyHaRegex.search(‘HaHaHaHaHa’)<br>&gt;&gt;&gt; mo1.group()<br>‘HaHaHaHaHa’<br>&gt;&gt;&gt; nongreedyHaRegex = re.compile(r’(Ha){3,5}?’)<br>&gt;&gt;&gt; mo2 = nongreedyHaRegex.search(‘HaHaHaHaHa’)<br>&gt;&gt;&gt; mo2.group()<br>‘HaHaHa’</pre><p>NOTE: Question mark(?) have two significance in regex declaring a non-greedy match or flagging an optional group and both are unrelated.</p><h3>The Caret and Dollar Sign Characters</h3><p>The Caret symbol(^) in the start indicates that a match must occur at the beginning, similarly Dollar sign($) at the end indicates that it should end with this regex pattern. Both ^, $ together means it should match the entire string and not the subpart.</p><p>For example:</p><pre>1:<br>&gt;&gt;&gt; beginsWithHello = re.compile(r’^Hello’)<br>&gt;&gt;&gt; beginsWithHello.search(‘Hello world!’)&lt;_sre.SRE_Match object; span=(0, 5), match=’Hello’&gt;</pre><pre>2:<br>&gt;&gt;&gt;endsWithNumber = re.compile(r’\d$’)<br>&gt;&gt;&gt; endsWithNumber.search(‘Your number is 42’)<br>&lt;_sre.SRE_Match object; span=(16, 17), match=’2&#39;&gt;</pre><pre>3:<br>&gt;&gt;&gt;wholeStringIsNum = re.compile(r’^\d+$’)<br>&gt;&gt;&gt; wholeStringIsNum.search(‘1234567890’)<br>&lt;_sre.SRE_Match object; span=(0, 10), match=’1234567890&#39;&gt;<br>&gt;&gt;&gt; wholeStringIsNum.search(‘12345xyz67890’) == None<br>True</pre><h3>Case Sensitive Matching</h3><p>For making regular expression case insensitive pass re.IGNORECASE or re.I as the second argument to re.compile. For eg:</p><pre>&gt;&gt;&gt; robocop = re.compile(r’robocop’, re.I)<br>&gt;&gt;&gt; robocop.search(‘RoboCop is part man, part machine, all cop.’).group()<br>‘RoboCop’</pre><h3>Complex Regular Expression</h3><p>It’s simple to maintain easy regular expression but when a regular expression is become hard to read again &amp; again you should split it into different lines by passing re.VERBOSE as second argument to re.compile(). For example:</p><pre>&gt;&gt;&gt;phoneRegex = re.compile(r’((\d{3}|\(\d{3}\))?(\s|-|\.)?\d{3}(\s|-|\.)\d{4}(\s*(ext|x|ext.)\s*\d{2,5})?)’) is complex regex then spread the regular expression over multiple lines with comments like this:</pre><pre>&gt;&gt;&gt;phoneRegex = re.compile(r’’’(<br>(\d{3}|\(\d{3}\))?<br>(\s|-|\.)?<br>\d{3}<br>(\s|-|\.)<br>\d{4}<br>(\s*(ext|x|ext.)\s*\d{2,5})?<br>)’’’, re.VERBOSE)</pre><h3>REGEX SYMBOLS:</h3><p>Notations used in regular expressions are:<br>• The ? matches zero or one of the preceding group.<br>• The * matches zero or more of the preceding group.<br>• The + matches one or more of the preceding group.<br>• The {n} matches exactly n of the preceding group.<br>• The {n,} matches n or more of the preceding group.<br>• The {,m} matches 0 to m of the preceding group.<br>• The {n,m} matches at least n and at most m of the preceding group.<br>• {n,m}? or *? or +? performs a nongreedy match of the preceding group.<br>• ^spam means the string must begin with spam.<br>• spam$ means the string must end with spam.<br>• The . matches any character, except newline characters.<br>• \d, \w, and \s match a digit, word, or space character, respectively.<br>• \D, \W, and \S match anything except a digit, word, or space character,<br>respectively.<br>• [abc] matches any character between the brackets (such as a, b, or c).<br>• [^abc] matches any character that isn’t between the brackets</p><p><strong>NOTE: </strong>If you need to match any actual character, prefix the character in the<br>regular expression with a backslash ‘\’ for eg: \*, \( &amp; \), \+, \|, \\.</p><p>To know more about the regular expression and it’s use, you can read “<a href="https://automatetheboringstuff.com/chapter7/">Automate The Boring Stuff with python</a>”. There, you will find more use of regular expressions and some projects related to regular expression. To make the blog relatable, examples used in this blog are taken from the book.</p><p>For video tutorials about regular expression or learning the same topics of the book, you can go to <a href="https://www.udemy.com/">Udemy.com</a>. The <a href="https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS">Automate the Boring Stuff with Python Programming</a> online course on <a href="https://www.udemy.com/">Udemy.com</a> covers most of the content of the book. If you’d prefer a video format for learning to program, you can use the discount code <a href="https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS">FOR_LIKE_10_BUCKS</a> to get an 80% discount. You will have lifetime access to the course content and can post questions to the course’s forums.</p><p>You can also watch &amp; learn through YOUTUBE. <a href="https://www.youtube.com/watch?v=7DG3kCDx53c&amp;list=PLRqwX-V7Uu6YEypLuls7iidwHMdCM6o2w">The Coding Train</a>, <a href="https://www.youtube.com/user/nesoacademy">NESO academy</a>, <a href="https://www.youtube.com/watch?v=sa-TUpSx1JA&amp;t=559s">Corey Schafer</a> have some fantastic video tutorials to learn regular expressions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd83eaf1e93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate the boring stuff with python : Part 1]]></title>
            <link>https://medium.com/@shivam_softwareartist/automate-the-boring-stuff-with-python-part-1-51e934c71fca?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/51e934c71fca</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[books]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 18:02:48 GMT</pubDate>
            <atom:updated>2018-08-27T18:02:48.341Z</atom:updated>
            <content:encoded><![CDATA[<p>Beginners in programming field often confuse with one question how to start ? But when it comes to learn python, the answer is “<em>Automate the boring stuff with python</em>”. The author “Al Sweigart” wrote it in a very simple way and the book is designed for practical programming for total beginners.</p><p>In Automate the boring stuff with python, you’ll learn how to use python to write programs that do in minutes and no prior programming experience required. You can read it for free on <a href="https://automatetheboringstuff.com/">automatetheboringstuff.com</a> .</p><h4>In the Book</h4><p>Basically the book is divided in two parts : Part 1 : PYTHON PROGRAMMING BASICS. Part 2 : AUTOMATING TASKS and here we are going to discuss about it’s part 1.</p><p>As the name suggesting part 1 tells about the basics of programming like functions, lists, manipulating strings etc. Once we’ve mastered the basics of python we moved to second part of the book. Second part is all about automating tasks i.e. Pattern matching with regular expression, Organising files, Debugging, Web scraping and many other different tasks.</p><h4><strong>Part 1</strong></h4><p>Part 1 contains 6 chapters of the book. Starting from Python basics, Flow control, Functions, Lists, Dictionaries and structuring data and the last chapter is Manipulating strings.</p><p><em>Chapter 1 </em>tells about the entering expressions into Interactive shells, different data types, String concatenation and replication, Storing values in Variables and gives you your first program to write in python. Then it will make you understand about various terms used in your first program like len(), str(), int() and float().</p><p><em>Chapter 2 </em>have three phases Operators, Loops and Importing modules.</p><p><em>Chapter 3 </em>is <em>Functions </em>and have various important phases. It tells us about def statement, Local and Global scope &amp; variables, Exception handling. There is a program given after this to understand it in a better way. Here comes the <strong>first project </strong>of the book named as ‘<strong><em>The Collatz Sequence</em></strong>’.</p><p><em>Chapter 4 </em>have phases like The List Data Type, Working with lists, Methods and String &amp; Tuples. It also contain the project ‘<strong><em>Comma Code</em></strong>’.</p><p><em>Chapter 5 </em>have The Dictionary Data Type and Using Data Structures to Model Real-World Things as two main phases of this chapter followed by another project ‘<strong><em>Fantasy Game Inventory</em></strong><em>’.</em></p><p><em>Chapter 6 </em>is the last chapter and phases of this project are Working with Strings, Useful String Methods. Project: Password Locker and Project: Adding Bullets to Wiki Markup are the projects explained briefly followed by the project ‘<strong><em>Table Printer</em></strong>’<strong> </strong>for practice.</p><p>One more thing about all the chapters is that there are practice questions given after each chapter which helps us in revising stuffs we read in chapter and the answers of those questions are given in Appendix C.</p><p>The projects that are explained in this part make us understand the whole concept thoroughly. The practice projects helps us in writing our own projects and master the basics.</p><h4><strong>For Videos</strong></h4><p>For learning the same topics of the book from video you can go to <a href="https://www.udemy.com/">Udemy.com</a>. The <a href="https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS">Automate the Boring Stuff with Python Programming</a> online course on <a href="https://www.udemy.com/">Udemy.com</a> covers most of the content of the book. If you’d prefer a video format for learning to program, you can use the discount code <a href="https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS">FOR_LIKE_10_BUCKS</a> to get an 80% discount. You will have lifetime access to the course content and can post questions to the course’s forums.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51e934c71fca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gtypist(GNU typist) / Touch typing]]></title>
            <link>https://medium.datadriveninvestor.com/gtypist-gnu-typist-2d25d08756a3?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d25d08756a3</guid>
            <category><![CDATA[typing]]></category>
            <category><![CDATA[gtypist]]></category>
            <category><![CDATA[touch-typing]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[pc]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Sat, 11 Aug 2018 22:15:26 GMT</pubDate>
            <atom:updated>2019-01-13T09:57:44.244Z</atom:updated>
            <content:encoded><![CDATA[<figure><a href="http://www.track.datadriveninvestor.com/1B9E"><img alt="" src="https://cdn-images-1.medium.com/max/700/0*6N7OKrZzZBv35MqD" /></a></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*Xe6fICW9luNvNzUY1eCZ7A.jpeg" /><figcaption>Qwerty Keypad</figcaption></figure><p>Touch typing is the most important factor for an individual to become a professional coder. If an individual is not good in touch typing then the road to becoming a coder is tough and there is no second way to avoid it.</p><p>There are many learning tools given over the internet and there are many typing classes available on YouTube. Few coaching centres also claim that they can make you typing master in a month. For students, it’s easy to go there and try to learn in their vacations but for others, it may not be that easy.</p><p>Here comes<strong> GNU Typist</strong> (<strong>gtypist</strong>). It is a universal typing tutor. You can learn to type on your own computer without any assistance of the internet. This software is available for free at ‘gtypist.html’.</p><p>It is a powerful typing tutor for Ubuntu Linux and for other operating systems as well. It’s very easy for beginners as well as for the individuals who want to upgrade their typing skills. Gtypist comes with several typing tutorials in English(QWERTY, Dvorak and Colemak keyboards), Czech, Russian and Spanish, as well as in German, French and Norwegian.</p><p>To operate this software you need to enter ‘gtypist’ in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wCDWrwiO2vV38A7fSrteBA.png" /><figcaption>Terminal</figcaption></figure><p>After this gtypist will start running on the computer and you can learn through it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*NmzmkE8ebl4Ad3q5JDCm7Q.png" /><figcaption>gtypist.</figcaption></figure><p>There are various series as Q, R, T, and V are typically for learning QWERTY touch typing, then series D &amp; C are for Dvorak and Colemak touch typing respectively. After that series, M are for the typing drills and S for the Speed drills. Gtypist also goes through the Calculator keypad. German, Spanish, Russian and other language’s typing tutorials can be accessed by ‘<em>More lessons…’.</em></p><p>Gtypist clearly guides us about typing from ground level. It first tells us about the placement of our fingers and then about the movement of our fingers for different keys. Initially, it’s hard to move fingers according to alphabets but after some time we can easily move our fingers in any direction.</p><h3>How much time it takes to learn Qwerty touch typing / How much time should we devote to it ???</h3><p>Well, it totally depends on the individual’s ability to practise &amp; learn. If we talk about my personal experience, I used to devote 1 hour daily for a month and now I can type 20 words/min, which is very slow but more practice will let me type much more faster than now.</p><p>In gtypist, the error rate can’t be more than 3%. But it is observed that beginners do not achieve it in their initial period of time but eventually, they get through it. In series Q, there are lessons about qwerty touch typing and if anyone complete one part of a lesson then they should not directly jump onto next part. For me, it’s always like I would try to achieve 3% or below error rate consecutively 3 times or else I won’t move to next part of the lesson. It gives me perfection for that part of the lesson. In the end, practice is the only way to master the touch typing.</p><p>To know more about GNU typist, go to ‘gtypist.html’, it will take you to GNU typist manual also check out <a href="https://www.gnu.org/software/gtypist/index.html">https://www.gnu.org/software/gtypist/index.html</a> .</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d25d08756a3" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/gtypist-gnu-typist-2d25d08756a3">Gtypist(GNU typist) / Touch typing</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 1 : 23–07–18 to 29–07–18]]></title>
            <link>https://medium.com/@shivam_softwareartist/week-1-23-08-18-to-29-08-18-bd62d8064e3c?source=rss-51cbc3f9bb77------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd62d8064e3c</guid>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[weekly-report]]></category>
            <dc:creator><![CDATA[Shivam Bansal]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 15:11:29 GMT</pubDate>
            <atom:updated>2018-08-10T08:42:08.675Z</atom:updated>
            <content:encoded><![CDATA[<p>Last week when I was thinking about this blog I thought that I would have a lot of things to write down here but last 7 days was extremely amusing. I was very excited when I got apprenticeship under<strong> <em>Anuvrat</em> <em>Parashar</em></strong><em>. </em>But my excitement didn&#39;t turn out the way I thought<em>. </em>I was totally on bed due to viral and other health problems but I managed to do some things and writing out here my improvements from last week.</p><p>First thing I was instructed that I should know touch typing. I started learning it through <strong><em>gtypist</em></strong> over linux terminal. After practising it for almost 1 hour daily, I am able to write this blog without looking at my keyboard. Yes the speed is very slow may be it is 15 words/minute or less but it will only increase day by day.</p><p>Next thing I had in my mind is to read the book “Automate the boring stuff with python” but wasn’t able to complete it. I should have done it but I realise that I lack the habit of reading for continuously an hour or so.</p><p>The things I noticed in past week that my time management is very poor. Also, I waste lot of time on social media due to which I have poor efficiency. My focus is not up-to mark and if I want to work with the best people then I have to get rid of above problems and try to maintain focus &amp; efficiency so that I will be more productive.</p><p>I know this blog have nothing that is impressive as an apprentice of <strong><em>Anuvrat Parashar </em></strong>but I am trying and I am determined to work under his guidance. I am working out on my problems and also my health is good now and hoping not to have such issues in near future. I’ll hope to have more improvement to show next week.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd62d8064e3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>