<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rahul Kumar</title>
    <description>The latest articles on DEV Community by Rahul Kumar (@rahulkumarmalhotra).</description>
    <link>https://dev.to/rahulkumarmalhotra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F815668%2F153bc62d-a8b1-435c-831c-6a114e74f105.jpeg</url>
      <title>DEV Community: Rahul Kumar</title>
      <link>https://dev.to/rahulkumarmalhotra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahulkumarmalhotra"/>
    <language>en</language>
    <item>
      <title>I wrote an entry for Future Writing Challenge, please give any feedback.</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Sun, 30 Mar 2025 15:34:46 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/i-wrote-an-entry-for-future-writing-challenge-please-give-any-feedback-1c8m</link>
      <guid>https://dev.to/rahulkumarmalhotra/i-wrote-an-entry-for-future-writing-challenge-please-give-any-feedback-1c8m</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://future.forem.com/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f" class="crayons-story__hidden-navigation-link" rel="noopener noreferrer"&gt;Today You Are Searching for a Dress Mom, Tomorrow You Will Be Designing It.&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/rahulkumarmalhotra" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F815668%2F153bc62d-a8b1-435c-831c-6a114e74f105.jpeg" alt="rahulkumarmalhotra profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/rahulkumarmalhotra" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Rahul Kumar
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Rahul Kumar
                
              
              &lt;div id="story-author-preview-content-2365301" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/rahulkumarmalhotra" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F815668%2F153bc62d-a8b1-435c-831c-6a114e74f105.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Rahul Kumar&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://future.forem.com/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f" class="crayons-story__tertiary fs-xs" rel="noopener noreferrer"&gt;&lt;time&gt;Mar 29 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://future.forem.com/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f" id="article-link-2365301" rel="noopener noreferrer"&gt;
          Today You Are Searching for a Dress Mom, Tomorrow You Will Be Designing It.
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/futurechallenge"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;futurechallenge&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/foremfest"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;foremfest&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/technology"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;technology&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://future.forem.com/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left" rel="noopener noreferrer"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;10&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://future.forem.com/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center" rel="noopener noreferrer"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>futurechallenge</category>
      <category>foremfest</category>
      <category>ai</category>
      <category>technology</category>
    </item>
    <item>
      <title>Today You Are Searching for a Dress Mom, Tomorrow You Will Be Designing It.</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Sat, 29 Mar 2025 19:01:55 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f</link>
      <guid>https://dev.to/rahulkumarmalhotra/mom-why-dont-you-ask-chatgpt-2f1f</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://future.forem.com/challenges/writing-2025-02-26" rel="noopener noreferrer"&gt;Future Writing Challenge&lt;/a&gt;: How Technology Is Changing Things.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Dear Mom, &lt;/p&gt;

&lt;p&gt;I received your message earlier, but I was busy with work so couldn’t figure out the one myself. But my little buddy here found the best among the two glass frames you asked me to choose from. He gave me good enough reason to choose the oval-broad frame as per your face length over the spherical one. His name is ChatGPT. Download it, it's an app on play store.&lt;/p&gt;

&lt;p&gt;But wait, since you are buying from the regular, why don't you try their AR feature that allow you to check their glasses on you, live. It's a little bit rough right now but its good enough to give you an idea on how it would look on you. AR is a cool technology, it's on Amazon too, you can put any of their sofa or bed or carpet to check how it looks in our living room. But in coming time we will be able to get better quality of AR with less jank. Today, you have to make peace with their low-quality AR that does the job. &lt;/p&gt;

&lt;p&gt;Anyway, I was wondering have you got the enough information on that tablet you were looking for. I think it's much easier to ask ChatGPT in simple language rather than typing long English sentences in Google Search. He will give you all the relevant information anything from salt to the dosage or any long-term side effect that medicine possess. In distant future our AIs will be able to prescribe us medicines on the basis of our symptoms same as what Doctors are doing online these days. The monitoring will be done by our smart watches like devices. The AI will take this information and prescribe us medicines. &lt;/p&gt;

&lt;p&gt;Wait, you have sent me the picture of that pretty dress your favorite vlogger was wearing right? I wonder why she hasn't shared the link in the description, maybe not getting paid for wearing that dress 😅. Never mind, I found the link it's pretty cheap in price however it's not in the color you were looking for. I found that using the Google Lens. All you have to do is to take a screenshot and the lens icon will do the rest for you. &lt;br&gt;
We are moving toward the future where we will just be able to design our own clothing, and the machines will prepare it in real time and deliver to us. No more worrying about the missing colors in the future.&lt;/p&gt;

&lt;p&gt;I know you might be worried about the privacy using such apps and you might think I am using them as an excuse or trying to shrug away my responsibilities. First, as long as you are not sharing your "top-secret" personal information you will be fine. Keep in mind that ChatGPT do make a mental memory of the stuff you are sharing. But you can delete it. Second, no I am not shrugging off my responsibilities and apps like AI and AR is just making our life easier. I mean how would I find out that vlogger is wearing cheap dress?  Anyway, have fun trolling the vlogger in her comment section.&lt;/p&gt;

&lt;p&gt;With love,&lt;br&gt;
Your son.&lt;/p&gt;

&lt;p&gt;[Cover Photo by Anna Shvets from Pexels.]&lt;/p&gt;

</description>
      <category>futurechallenge</category>
      <category>foremfest</category>
      <category>ai</category>
      <category>technology</category>
    </item>
    <item>
      <title>Creating an ExpressJs Endpoint to Upload Single Image to Cloudinary</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Sun, 23 Mar 2025 16:38:46 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/creating-an-expressjs-endpoint-to-upload-single-image-to-cloudinary-5dp9</link>
      <guid>https://dev.to/rahulkumarmalhotra/creating-an-expressjs-endpoint-to-upload-single-image-to-cloudinary-5dp9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1avbud2tqo9zbwjho390.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1avbud2tqo9zbwjho390.jpg" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial we will explore the easiest way to upload an image to &lt;a href="https://cloudinary.com/" rel="noopener noreferrer"&gt;Cloudinary&lt;/a&gt;, a firebase alternative to upload images for free.&lt;/p&gt;

&lt;p&gt;GitHub URL -&amp;gt; &lt;a href="https://github.com/rahul7kumar7/Wallpaper-Website-MERN" rel="noopener noreferrer"&gt;Wallpaper Website MERN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's get to the introduction of technologies that we are needing for this project.&lt;/p&gt;

&lt;h3&gt;
  
  
  About Cloudinary
&lt;/h3&gt;

&lt;p&gt;Cloudinary is a cloud solution that work as an alternative to firebase when it comes to uploading images. Cloudinary provides its SDK for almost all major languages. Not just through SDK, you can also use their API URL to upload Images directly from frontend, &lt;a href="https://rmideasblog.in/programming/adding-cloudinary-to-your-react-frontend/" rel="noopener noreferrer"&gt;here is the tutorial&lt;/a&gt;.&lt;br&gt;
Once file uploaded to their server, Cloudinary provide us with &lt;strong&gt;delivery URL&lt;/strong&gt; that hot link the image that we have uploaded.&lt;/p&gt;
&lt;h3&gt;
  
  
  About Multer
&lt;/h3&gt;

&lt;p&gt;Multer provides us with API that we need to upload image to our server. In our context we are using Multer to store image into memory as a buffer. You can also use this to upload your image to your local storage instead of Cloudinary. You will find more information through their &lt;a href="https://www.npmjs.com/package/multer" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Making a Backend Cloudinary Uploader is very straight forward. All you need are these few steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating a frontend that provide a single file uploader.&lt;/li&gt;
&lt;li&gt;Making a route to the endpoint.&lt;/li&gt;
&lt;li&gt;Creating a middleware using Multer to store file as a buffer in a memory.&lt;/li&gt;
&lt;li&gt;Creating an entry point function that points to Cloudinary uploader function and make an entry in mongodb.&lt;/li&gt;
&lt;li&gt;Making a function that upload the image stream to Cloudinary.&lt;/li&gt;
&lt;li&gt;Converting image buffer into readable stream and then write it into Cloudinary.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Frontend Code
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';

export default function Submit() {
    const [formData, setFormData] = useState({
        title: '',
        img: null,
    });

    const [selectedImg, setSelectedImg] = useState(null);
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState('');

    // Handle file selection
    const handleFileChange = (e) =&amp;gt; {
        setFormData(prev =&amp;gt; ({ ...prev, img: e.target.files[0] }));
        setSelectedImg(URL.createObjectURL(e.target.files[0]));
    };

    // Handle text input changes
    const handleChange = (e) =&amp;gt; {
        setFormData(prev =&amp;gt; ({ ...prev, [e.target.id]: e.target.value }));
    };

    // Handle category selection
    const handleCategoryChange = (e) =&amp;gt; {
        setFormData(prev =&amp;gt; ({ ...prev, category: e.target.value }));
    };

    // Submit form
    async function handleSubmit(e) {
        e.preventDefault();
        console.log('Submit button clicked');
        setLoading(true)

        if (!formData.img) {
            alert("Please select an image to upload.")
            setLoading(false)
            setError("Enter an image file to proceed")
            return;
        }

        const formDataToSend = new FormData();
        formDataToSend.append("img", formData.img);
        formDataToSend.append("title", formData.title);
        try {
            const res = await fetch('http://localhost:8080/wallpaper/upload', {
                method: 'POST',
                body: formDataToSend
            });
            const data = await res.json();
            console.log("Upload Success:", data);
            setLoading(false)
        } catch (error) {
            setLoading(false)
            setError('Error occurred while uploading wallpaper:', error)
            console.error('Error occurred while uploading wallpaper:', error);
        }
    }

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
                &amp;lt;h1&amp;gt;Select an image file to upload (supported: .jpg, .png, .webp):&amp;lt;/h1&amp;gt;
                &amp;lt;input type="file" id="img" onChange={handleFileChange} accept="image/*" required /&amp;gt;

                {formData.img &amp;amp;&amp;amp; (
                    &amp;lt;div&amp;gt;
                &amp;lt;img src={selectedImg} alt=""/&amp;gt;

                &amp;lt;label htmlFor="title"&amp;gt;Title:&amp;lt;/label&amp;gt;
                &amp;lt;input type="text" id="title" onChange={handleChange} required /&amp;gt;

                &amp;lt;button type="submit"&amp;gt;{loading ? "Uploading Wallpaper...." : "Upload Wallpaper"}&amp;lt;/button&amp;gt;
                &amp;lt;/div&amp;gt;
                )}


                {error &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{error}&amp;lt;/p&amp;gt;}
            &amp;lt;/form&amp;gt;
        &amp;lt;/div&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So far, we have made a simple page that have an input to upload image and a button to submit the form.&lt;br&gt;
We have an endpoint &lt;a href="http://localhost:8080/wallpaper/upload" rel="noopener noreferrer"&gt;http://localhost:8080/wallpaper/upload&lt;/a&gt; which we create in next step.&lt;/p&gt;
&lt;h2&gt;
  
  
  Route to endpoint
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import {uploadFileMiddleware, uploadWallpaper} from "../somepath.js"
const router = express.Router();
router.post('/upload', uploadFileMiddleware, uploadWallpaper)
export default router;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We have created a route where we can send some data to upload our image.&lt;br&gt;
Now before I start with the actual code, I want to make a quick schema for mongoose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import mongoose from 'mongoose';

const wallpaperSchema = new mongoose.Schema({
    title:{
        type: String,
        required: true
    },
    img:{
        type: String,
        required: true
    },
    timestamp: {
        type: Date,
        default: Date.now
    }
});

const Wallpaper = mongoose.model('Wallpaper', wallpaperSchema);
export default Wallpaper;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting Up Middleware
&lt;/h2&gt;

&lt;p&gt;Let's get to our imaginary somepath.js and set up middleware function.&lt;br&gt;
In order to do that we need to install Multer.&lt;br&gt;
First install Multer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install multer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Importing Multer to our project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import multer from 'multer';
const storage = multer.memoryStorage()
const upload = multer({storage:storage})
export const uploadFileMiddleware = upload.single('img');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We first create a storage that points to &lt;strong&gt;memoryStorage&lt;/strong&gt; that means &lt;u&gt;we are storing our image as a buffer into memory&lt;/u&gt;. And since we are storing it in memory the file size of an image may affect your system performance, but you don't need to worry since image file in many of our case won't go above 20MB (at best).&lt;br&gt;
Then we will make an instance of multer named upload, that is configured to use memoryStorage.&lt;br&gt;
Now we define our middleware. We are uploading a single image i.e., "img" in memory that will be accessible through req.file.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up uploadWallpaper Function
&lt;/h2&gt;

&lt;p&gt;uploadWallpaper is the entry function to upload image to Cloudinary as well creating an entry to mongoDB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const uploadWallpaper = async (req, res, next) =&amp;gt; {
    console.log("uploadWallpaper");
    try {
        if (!req.file){
            console.error('Image not selected.')
            return next(404, 'Image not selected.');
        }
        const {img, title, altTitle, category, tags} = req.body;

        if (!title) {
            console.error('Title not filled.')
            return next(404, 'Title not filled.');
        }
        const uploadedUrl = await uploadToCloudinary(req.file.buffer, title);
        console.log("uploading wallpaper...");
        if (!uploadedUrl) {
            return next(500, 'failed to upload image to cloudinary');
        }
        console.log("uploadedUrl", uploadedUrl);
        const newWallpaper = await Wallpaper.create({
            title: title,
            img: uploadedUrl.secure_url.toString(),
        });
        res.status(200).send(newWallpaper)
    } catch (error) {
        console.log(error);
        next(error)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have made a next middleware to handle all the message that I need to send as a response. &lt;br&gt;
Here is the code for that, you can put it into your index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use((err, req, res, next)=&amp;gt; {
    const statusCode = err.statusCode || 500;
    const message = err.message || 'Internal Server Error';
    res.status(statusCode).send({
        success: false,
        status: statusCode,
        error: message
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up uploadToCloudinary Function
&lt;/h2&gt;

&lt;p&gt;We are making a function that is &lt;strong&gt;uploadToCloudinary&lt;/strong&gt; we are receiving file name (title) and the image file as a buffer through uploadWallpaper entry function. &lt;br&gt;
Our job is to &lt;u&gt;convert that buffer into a readable stream of data and upload that as a stream to Cloudinary&lt;/u&gt;.&lt;/p&gt;

&lt;p&gt;We are using cloudinary SDK, if you need more information on that you can check their &lt;a href="https://cloudinary.com/documentation/upload_images" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before doing that we need certain access-data from Cloudinary that is their &lt;strong&gt;Cloud Name&lt;/strong&gt;, &lt;strong&gt;API Key&lt;/strong&gt; and &lt;strong&gt;API Secret&lt;/strong&gt;. You will find API Key and API secret right from their dashboard through "Go To API Key" button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fair6iu4bjgfyhkyrnkcm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fair6iu4bjgfyhkyrnkcm.png" alt="Image description" width="800" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will find the cloud name there as well. You can change your cloud name from Settings &amp;gt; Product Environment if you like to do so.&lt;/p&gt;

&lt;p&gt;Let's install Cloudinary to our project now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install cloudinary 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our &lt;strong&gt;uploadToCloudinary&lt;/strong&gt; function, the first order of business is configuring the access-data we have now. I would put this data into an env so uploading it to github doesn't expose my sensitive information to the public.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    cloudinary.config({
        cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
        api_key: process.env.CLOUDINARY_API_KEY,
        api_secret: process.env.CLOUDINARY_API_SEC
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to check wether your connection is working or not, you can ping to cloudinary using the below code, thanks to &lt;a href="https://gist.github.com/Pawper/a4da5e1c5fb16164a74a87af0fdc3ad1" rel="noopener noreferrer"&gt;this github&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    await cloudinary.api.ping((error, result) =&amp;gt; {
        if (error) {
            console.error("Ping failed", error);
        } else {
            console.log("Ping successful:", result);
        }
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our &lt;strong&gt;uploadToCloudinary&lt;/strong&gt; function will return a promise. Inside the promise we will create another function uploadedImage that will connect with upload_stream to upload our image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        const uploadedImage = cloudinary.uploader.upload_stream(
            {
                resource_type: "image",
                public_id: `wallpaper/${title.trim()}`,
                display_name: title,
                overwrite: false,
                media_metadata: true,
            },
            (err, result) =&amp;gt; {
                if (err) {
                    console.log('Error uploading image to server', err)
                    return reject(err)
                }
                else {
                    console.log(result)
                    console.log('Image uploaded successfully', result.secure_url)
                    resolve(result)
                }

            }            
        )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;upload_stream&lt;/strong&gt; works on certain options, you can configure it as per your choice or just use the one I have here.&lt;/p&gt;

&lt;p&gt;The public_id however reflect in delivery url as well, it provides the url that has /wallpaper/certainimage.jpg. Thing to note here is wallpaper is not a folder but a prefix.&lt;/p&gt;

&lt;p&gt;display_name will display the name of the image in cloudinary media explorer.&lt;/p&gt;

&lt;p&gt;media_metadata has some specific informations regarding your image like piexlPerUnitX etc, you most like don't need it but I kept it true in case I may need it later.&lt;/p&gt;

&lt;p&gt;You can find more information on it through their &lt;a href="https://cloudinary.com/documentation/image_upload_api_reference" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turning this &lt;strong&gt;fileBuffer&lt;/strong&gt; into a Readable Stream
&lt;/h2&gt;

&lt;p&gt;In order to do that, first we need to import Readable from Stream (pretty convenient, eh?)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {Readable} from "stream"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we store the stream into a variable str.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = Readable.from(fileBuffer)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, we will pipe this stream into &lt;strong&gt;uploadedImage&lt;/strong&gt; function, that function will now upload the image as a stream.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str.pipe(uploadedImage)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pipe method will transfer readable stream to writeable stream&lt;/strong&gt;. Picture what a pipe does in real life with a stream of water (not read and write offcourse) taking water stream from point source to destination that's what we are doing here.&lt;/p&gt;

&lt;p&gt;Now we are done with it.&lt;br&gt;
Here is the one uploading page I made for my project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgz0jqp5v8bwy8z90ivu.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgz0jqp5v8bwy8z90ivu.jpeg" alt="Image description" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clicking Upload Wallpaper will upload this image to Cloudinary with the title I chose.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftnaaz65ftf0b00p4pc41.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftnaaz65ftf0b00p4pc41.jpeg" alt="Image description" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://res.cloudinary.com/dg01gwwoc/image/upload/v1742745025/wallpaper/Blue%20Moon%20Something%20Something.jpg" rel="noopener noreferrer"&gt;url&lt;/a&gt; to download this image in case you find it wallpaper worthy!&lt;/p&gt;

&lt;p&gt;I will put more tutorials on my dev.to page and I would like to continue this particular project on my website &lt;a href="https://rmideasblog.in/" rel="noopener noreferrer"&gt;RM Ideas Blog&lt;/a&gt;. If you are interested, you can bookmark it for future reading. If you need any help, please add your comment and click on heart button if you liked this tutorial.&lt;/p&gt;

</description>
      <category>react</category>
      <category>express</category>
      <category>webdev</category>
      <category>cloudinary</category>
    </item>
    <item>
      <title>DFS Traversal Guide: Easy way to remember DFS Traversel Path</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Wed, 19 Jun 2024 15:19:03 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/dfs-traversal-guide-easy-way-to-remember-dfs-traversel-path-257a</link>
      <guid>https://dev.to/rahulkumarmalhotra/dfs-traversal-guide-easy-way-to-remember-dfs-traversel-path-257a</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1y6tm0s3epuzuhdsyc2q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1y6tm0s3epuzuhdsyc2q.jpg" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two different way to traverse Binary Search Tree and Graph. The first approach is Breadth First Search (BFS) and the second one is Depth First Search (DFS). Both approaches have their own use case but two common objectives one can think of are finding the shortest distance between two nodes and detecting the loop in a tree. &lt;/p&gt;

&lt;p&gt;BFS traverse horizontally acrross all levels, while DFS traverse vertically. Since we are traversing vertically, it give us more flexibility in choosing our approach of travelling. &lt;br&gt;
These 3 paths are Pre-order, In-order, and Post-order. Although this flexibility is useful, it can also be confusing. Suppose you forget the order of DFS traversals but remember the rest of the code during an exam or interview. This could be disastrous because the overall code for DFS is relatively straightforward and similar for all three cases.&lt;/p&gt;
&lt;h2&gt;
  
  
  Depth First Search Traversal Approaches
&lt;/h2&gt;

&lt;p&gt;In today's tutorial we are looking into the easiest way possible to remember DFS traversals.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DFS Pre-Order: In Pre-order DFS we move from Root/Subroots node to the Left node and to the Right node.&lt;/li&gt;
&lt;li&gt;DFS In-Order: In In-order DFS we move from Left node to Root/Subroots node and to the Right node.&lt;/li&gt;
&lt;li&gt;DFS Post-Order: In Post-order DFS we move from Left node to Right node and then to Root/Subroots node.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Probing the DFS Traversal Approaches to make it Easy to Remember
&lt;/h2&gt;

&lt;p&gt;There are two common things in all three of the statements. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The order of Root/Subroot is changing but Left and Right are constant in simple words, we first move left and then right in all 3 traversals.&lt;/li&gt;
&lt;li&gt;The traversal method's name indicate the position of Root/Subroot traversal. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let's see this through an example.&lt;/p&gt;

&lt;p&gt;We have this BST &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2n2xgmd2t61pxd7a5ywz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2n2xgmd2t61pxd7a5ywz.png" alt="A Binary Search Tree" width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  DFS Pre-Order
&lt;/h3&gt;

&lt;p&gt;We first do the DFS Pre-order for this bst:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def dfs_in_order():
    results = []

  def traverse(current_node):
    results.append(current_node)
    if current_node.left:
        traverse(current_node.left)
    if current_node.right:
        traverse(current_node.right)

    traverse(root)
    return results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above code we are adding Root first than traversing left and right if they exist. The output will be [47,21,18,27,76,52,82]&lt;/p&gt;

&lt;p&gt;Notice our Root/Subroots is before Left and Right.&lt;/p&gt;

&lt;h3&gt;
  
  
  DFS In-Order
&lt;/h3&gt;

&lt;p&gt;Doing DFS In-order will give us this result: [18,21,27,47,52,76,82]&lt;/p&gt;

&lt;p&gt;Notice our Root/Subroots is in between Left and Right node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def traverse(current_node):
    if current_node.left:
        traverse(current_node.left)
    results.append(current_node)
    if current_node.right:
        traverse(current_node.right)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DFS Post-Order
&lt;/h3&gt;

&lt;p&gt;Now we have left with DFS Post-order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def traverse(current_node):
    if current_node.left:
        traverse(current_node.left)
    if current_node.right:
        traverse(current_node.right)
    results.append(current_node)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Post-order wil further push &lt;code&gt;results.append()&lt;/code&gt; to bottom. The output generated will be [18,27,21,52,82,76,47].&lt;/p&gt;

&lt;p&gt;Notice how our Root/Subroots are after Left and Right node.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Using "In/Pre/Post" prefix will help you determine the position of Root and Subroots in DFS easily. Other than that we are traversing Left to Right in all cases regardless of the position of Root and Subroots.&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>dfs</category>
      <category>tree</category>
      <category>learning</category>
    </item>
    <item>
      <title>The Wonders of Python any() and all() function</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Wed, 15 May 2024 18:27:04 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/the-wonders-of-python-any-and-all-function-199p</link>
      <guid>https://dev.to/rahulkumarmalhotra/the-wonders-of-python-any-and-all-function-199p</guid>
      <description>&lt;p&gt;Before I start with any() and all() functions, I want to raise a situation where we have to match some text from provided strings. &lt;br&gt;
Say, if we find "brown" and "fox" in this passage &lt;br&gt;
"The quick brown fox jumps over the lazy dog." our program will print "we found it." &lt;/p&gt;

&lt;p&gt;So, how do you do that?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3evl2pi35brcs78s0csg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3evl2pi35brcs78s0csg.png" alt="Image description" width="800" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Easy enough? &lt;br&gt;
If you say no, we can do the same by storing "fox" and "brown" in a list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvum36dxzqnuxrjgdfxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flvum36dxzqnuxrjgdfxl.png" alt="Image description" width="800" height="133"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This looks clean. &lt;br&gt;
But,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatkb6fzasm0i7qyuxkd7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatkb6fzasm0i7qyuxkd7.png" alt="Image description" width="800" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python doesn't like it because it doesn't allow a list on the left operand. Why? Because you simply can't find a list of items in a string. It's like checking all your grocery items from one small aisle.&lt;/p&gt;

&lt;p&gt;But we can do the inverse of it. Say, we need to find "jump" in the following passages, "The quick brown fox jumps over the lazy dog" and "The five boxing wizards jump quickly."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo2rpe768q9471yygy0oy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo2rpe768q9471yygy0oy.png" alt="Image description" width="743" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will print "we found it" without any error because we are looking for "jump" from two different passages, not the other way around.&lt;/p&gt;

&lt;p&gt;But how do we fix our first error? Here Python's any() function comes into play.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1exiidurnvjxr33gjq5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1exiidurnvjxr33gjq5k.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will successfully print "here, we found it!" How? any() is an in-built Python function which returns a boolean. &lt;br&gt;
Since we have "fox" and "brown" in our phrase, the following condition becomes True. Let's dissect a little bit for you in case you are new to Python.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;any([phrase in passage for phrase in ["fox", "brown"]])&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Look at this line and try to understand what is happening. We are using list comprehension technique to find a phrase in a passage. The phrase will take elements from the list ["fox", "brown"] one by one and check with the passage. It's like writing:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffp9f6ffjm3tms8id5gkn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffp9f6ffjm3tms8id5gkn.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The any() function will return true if either "fox" or "brown" is found in the passage. Otherwise, it returns False. It basically combines the if "fox" in passage or "brown" in passage, in short, the or condition for you.&lt;/p&gt;

&lt;p&gt;Now, let's take an example of the all() function. Instead of using any() in the previous code, we are using all() to determine whether all the words in the phrase match those in the passage.&lt;/p&gt;

&lt;p&gt;This will print:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8loqhtb9893tdsnjnl6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8loqhtb9893tdsnjnl6r.png" alt="Image description" width="750" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will prints:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dzmhbzmzijconm7lnp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dzmhbzmzijconm7lnp1.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;all() function is easy to understand once you understood any(). All the all() function does is to check wether all the phrase exist inside the passage or not. If it doesn't, it will return True else False. In our case it prints "we found nothing" since the word "boy" is not in our passage.&lt;/p&gt;

&lt;p&gt;In case we remove boy this will print "here we found it".&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
You can utilize any() in any of your project where your objective is to compare a list of items with a specific phrase of condition. For instance here is one real world example of any() function in selenium. Here we have a list of some common phrases we can found in error pages like 404 or Bad Gateway.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpr4qt1fr0cdgghgiwxkk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpr4qt1fr0cdgghgiwxkk.png" alt="Image description" width="800" height="239"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thats all I wanted to cover in the any() and all() wonders. I hope I am able to make it easier for you to understand. &lt;/p&gt;

&lt;p&gt;You can add some real world example in the comments too if you think of any().&lt;/p&gt;

&lt;p&gt;Thanks for reading this article and have a great day ahead.&lt;/p&gt;

</description>
      <category>python</category>
      <category>any</category>
      <category>beginners</category>
      <category>all</category>
    </item>
    <item>
      <title>Goodreads Scraping using Python and Selenium</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Tue, 12 Apr 2022 19:26:30 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/goodreads-scraping-using-python-and-selenium-343j</link>
      <guid>https://dev.to/rahulkumarmalhotra/goodreads-scraping-using-python-and-selenium-343j</guid>
      <description>&lt;p&gt;Goodreads is the biggest library of books that allows saving your reading progress. Moreover, you can find a myriad of options for your next read. &lt;br&gt;
Github - &lt;a href="https://github.com/rahul-kumar-bly/Goodreads-Scrapper-Alpha" rel="noopener noreferrer"&gt;https://github.com/rahul-kumar-bly/Goodreads-Scrapper-Alpha&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note - This tutorial is for educational purposes only. No intent to scrape large-scale data from Goodreads. Logos used in cover-image are intellectual properties of Selenium and Goodreads.&lt;/p&gt;

&lt;p&gt;Here in this tutorial, we are using Selenium to scrap a list of &lt;strong&gt;Must Read books&lt;/strong&gt; available in their library along with we are going to create a module that allows us to search their website for a particular book.&lt;br&gt;
So, let's get started. &lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisite
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In case you are new to selenium first read my how to get started with selenium in python guide, link &lt;a href="https://dev.to/rahulkumarmalhotra/selenium-scraping-in-python-with-installationsetup-guide-3n3o"&gt;here&lt;/a&gt;. The guide will help you to understand the basics you need to learn Selenium.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Goodreads account is needed for this tutorial along with its email id and password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need to have basic idea of Xpath (&lt;a href="https://www.w3schools.com/xml/xpath_intro.asp" rel="noopener noreferrer"&gt;link&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, let's first import all the required modules.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhb3enjzdfo4fmrmkxyfl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhb3enjzdfo4fmrmkxyfl.jpg" alt="Image description" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Time to do the basic part now, creating instance of Service and Options class ready to your browser to open goodreads login page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhmz1geu039n115og54o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhmz1geu039n115og54o.jpg" alt="Image description" width="800" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will use instance of options later, first we need to check everything is working fine.&lt;/p&gt;

&lt;p&gt;Run this script and it open the sign-in page of goodreads. Now, we are going to supply login id and password to this page as without it we are going to have some complication scraping data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzjdvydjn9mbwzwb0opl5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzjdvydjn9mbwzwb0opl5.jpg" alt="Image description" width="800" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you load it will open the same login page but this time it login you and redirect to your profile page.&lt;/p&gt;

&lt;p&gt;Let's move to the next step where we start doing scraping.&lt;br&gt;
Our first objective to open a dedicated search page and send a book name and then retrieve a list of books.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87noy5w7hfm71yrzog5r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87noy5w7hfm71yrzog5r.jpg" alt="Image description" width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will search 20 books, unlike the first 2 result most of the other are summaries and translations or other related books with same title. So there is no reason to loop through all available pages and display every single result. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu63d89rhc26ooa35wubv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu63d89rhc26ooa35wubv.jpg" alt="Image description" width="800" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open &lt;a href="https://www.goodreads.com/search?utf8=%E2%9C%93&amp;amp;q=1984&amp;amp;search_type=books&amp;amp;search%5Bfield%5D=on" rel="noopener noreferrer"&gt;this link&lt;/a&gt; in your browser tab. Hit Ctrl+Shift+C to open inspect element and Ctrl + F inside inspect element window. Paste this code &lt;code&gt;//table/tbody/tr[contains(@itemtype, 'http://schema.org/Book')]&lt;/code&gt; and hover over highlighted area. It will highlight a block which includes the cover image, title, rating, and other stuff as in below screenshot.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fontjvgq05ebhvdthtnm8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fontjvgq05ebhvdthtnm8.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;XPath stands for XML Path-Language.&lt;br&gt;
I am not going into too much detail about Xpath but for starter it is a flexible way to address any part of HTML (well XML originally) which means you can access anything in HTML (or XML) using Xpath.&lt;br&gt;
In our snippet we want to access &lt;code&gt;&amp;lt;tr itemscope="" itemtype="http://schema.org/Book"&amp;gt;&lt;/code&gt; so in order to access we need to use relative path &lt;code&gt;//table/tbody/tr&lt;/code&gt; tr contains itemptype="&lt;a href="http://schema.org/Book" rel="noopener noreferrer"&gt;http://schema.org/Book&lt;/a&gt;" so for the same we will use &lt;code&gt;[contains (@itemtype, 'http://schema.org/Book')]&lt;/code&gt; thus the complete code will be &lt;code&gt;//table/tbody/tr[contains (@itemtype, 'http://schema.org/Book')]&lt;/code&gt;. There will be other instance of Xpath too in our tutorial that help you understand it better.&lt;/p&gt;

&lt;p&gt;We also need to extract book-cover image url since the above code will not provide us with that. The image tag has class with a value bookcover which we can access using the &lt;code&gt;.find_elements()&lt;/code&gt; method.&lt;br&gt;
Next step is to create a list and store Title, Auhtor info, Rating, Image as list-tuple which we can achieve using loop. &lt;/p&gt;

&lt;p&gt;It's time to display data in our terminal using pandas.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import pandas&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and add these three lines of codes&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgu3nowo6lcmsn7f902o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbgu3nowo6lcmsn7f902o.jpg" alt="Image description" width="800" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run and this will generate an excel file like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fox2xc19him45s479103t.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fox2xc19him45s479103t.jpg" alt="Image description" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far we have,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Goodreads and login with credentials&lt;/li&gt;
&lt;li&gt;Search for a particular book title&lt;/li&gt;
&lt;li&gt;Save the data into excel spreadsheet&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Selenium Scraping in Python with Installation/Setup Guide</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Tue, 29 Mar 2022 17:49:33 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/selenium-scraping-in-python-with-installationsetup-guide-3n3o</link>
      <guid>https://dev.to/rahulkumarmalhotra/selenium-scraping-in-python-with-installationsetup-guide-3n3o</guid>
      <description>&lt;p&gt;Selenium allows you to automate web-related tasks whether it is fetching data from website (web scraping), filling forms and many more. &lt;/p&gt;

&lt;p&gt;All these tasks are performed using a &lt;strong&gt;headless browser&lt;/strong&gt;. A headless browser is nothing more than a browser without visible GUI which allows you to - &lt;u&gt;make HTTP requests and keep session information&lt;/u&gt;.&lt;/p&gt;

&lt;p&gt;My main focus in doing some basic operations on a website and fetch some information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisite
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;You should have basic HTML knowledge to understand how selenium works. &lt;/li&gt;
&lt;li&gt;Understanding of DOM will be beneficial.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;First Installation, regardless of your platform you need three things to get started.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Selenium&lt;/strong&gt;
Install selenium using &lt;code&gt;pip install selenium&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Headless Browser&lt;/strong&gt; 
For this tutorial I am using chrome's chromedriver. Alternatively, you can use firefox headless browser called geckodriver.
Install Chromedriver from &lt;a href="https://chromedriver.chromium.org/downloads" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.
Install Geckodriver from &lt;a href="https://github.com/mozilla/geckodriver/releases" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A web browser with GUI&lt;/strong&gt;
Install Chrome using the following commands
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now without further ado let's create our first demo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Import Selenium packages to your active project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import selenium
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.service import Service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's open a website using.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = Service("chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get("https://rugsforyou.in/")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Service class demands a path of executable, I have &lt;strong&gt;chromedriver.exe&lt;/strong&gt; in same folder as my python file. &lt;br&gt;
You can also use geckodriver.exe for Firefox.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;webdriver.Chrome&lt;/strong&gt; creates a new instance of chrome driver.&lt;/p&gt;
&lt;h4&gt;
  
  
  Now its time to explain a bit about webdriver.
&lt;/h4&gt;

&lt;p&gt;A webdriver is a component of Selenium which accept command and send them to browser to return result. &lt;code&gt;Webdriver.Chrome&lt;/code&gt; demands an executable file for &lt;code&gt;chromedriver&lt;/code&gt; that I am provide through a reference to Service class.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;.get()&lt;/strong&gt; method is a way to load a web page in the current browser session. In short it creates an HTTP request for the supplied URL.&lt;/p&gt;

&lt;p&gt;Now lets, create a simple automation using selenium. This will open this wonderful eCommerce site and enter a value into search bar and then show the result. &lt;br&gt;
For this we need to import another class By.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;from selenium.webdriver.common.by import By&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# in continuation to the above code
send_data = driver.find_element(By.CLASS_NAME, value="ms-search-field")
send_data.send_keys("flower")
send_data.submit()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;driver.find_element find the web element with class name &lt;code&gt;"ms-search-field"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;By&lt;/strong&gt; you can define the locator eg - &lt;strong&gt;CLASS_NAME&lt;/strong&gt; or &lt;strong&gt;ID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;.send_keys("value")&lt;/strong&gt; holds the value to allow typing into an input field in our case "ms-search-field" is an input field.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;.submit()&lt;/strong&gt; submits the form.&lt;/p&gt;

&lt;p&gt;In order to access the resulting website URL you can use &lt;strong&gt;.current_url&lt;/strong&gt; object. For eg - &lt;code&gt;print(driver.current_url)&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Using headless browser
&lt;/h4&gt;

&lt;p&gt;Just add the following command to run this program in headless state.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;from selenium.webdriver.chrome.options import Options&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# continuation to above code
opts = Options()
opts.headless = True
# change the arguments of Chrome class
driver = webdriver.Chrome(options=opts, service=s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will not open chrome browser but still load the data and print the result in terminal.&lt;/p&gt;

&lt;p&gt;In order to revert it back to GUI remove &lt;code&gt;options=opts&lt;/code&gt; from &lt;strong&gt;Chrome()&lt;/strong&gt;.&lt;br&gt;
I now at this point you must be wondering why we have imported so many packages. So let's recap.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegp3silh4ofidz3u59qd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fegp3silh4ofidz3u59qd.png" alt="Image description" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>selenium</category>
      <category>python</category>
      <category>scraping</category>
      <category>beginners</category>
    </item>
    <item>
      <title>All possible LIST Idioms and Operations in Python</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Mon, 14 Mar 2022 18:49:06 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/all-possible-list-idioms-and-operations-in-python-32p8</link>
      <guid>https://dev.to/rahulkumarmalhotra/all-possible-list-idioms-and-operations-in-python-32p8</guid>
      <description>&lt;p&gt;I have added possible list operations/idioms available in Python.&lt;br&gt;
Please note I have uploaded images of the code snippet as dev.to default code block offers lame black background with white text. You can find the following code into this github repo. &lt;/p&gt;
&lt;h2&gt;
  
  
  1. String to List
&lt;/h2&gt;

&lt;p&gt;Code snippet to accept a string paragraph and convert it into list. Might be the most easiest code in the python.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lp60ko3fqc0nrjr3499.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lp60ko3fqc0nrjr3499.jpg" alt="String to list in python" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['Lorem', 'Ipsum', 'is', 'simply', 'dummy', 'text', 'of', 'the',
'printing', 'and', 'typesetting', 'industry.', 'Lorem', 'Ipsum', 
'has', 'been', 'the', "industry's", 'standard', 'dummy', 'text', 
'ever', 'since', 'the', '1500s,', 'when', 'an', 'unknown', 
'printer', 'took', 'a', 'galley', 'of', 'type', 'and', 
'scrambled', 'it', 'to', 'make', 'a', 'type', 'specimen', 'book.']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. List to String
&lt;/h2&gt;

&lt;p&gt;Not really a list operation but very helpful for begineers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffixintvyw9wjnbbzudwh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffixintvyw9wjnbbzudwh.jpg" alt="List to string in python" width="800" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lorem Ipsum is simply dummy text of the printing and typesetting 
industry. Lorem Ipsum has been the industry's standard dummy text 
ever since the 1500s, when an unknown printer took a galley of 
type and scrambled it to make a type specimen book.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Integer to List
&lt;/h2&gt;

&lt;p&gt;This code accept an integer and convert it into a list with all items being integer type. You can check the type of variable using &lt;code&gt;print(type(variable_name))&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvbro9mttzoxixw8wwn84.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvbro9mttzoxixw8wwn84.jpg" alt="Integer to list in python" width="800" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[4, 5, 8, 9, 4, 1, 2, 5, 6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. List to Integer
&lt;/h2&gt;

&lt;p&gt;You can do this too using the same strategy as in Step 2.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuibf4vdux5nbpanq22f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuibf4vdux5nbpanq22f.jpg" alt="List to integer in python" width="800" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;458941256
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Dictionary to List
&lt;/h2&gt;

&lt;p&gt;Dictionary is by far the most powerful python data-type for me. So, what I am gonna do is convert the dictionary items and values into a nested list for eg., [[1,"alpha"], [2,"beta"]].&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4d1gygpm17eywos5xe7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu4d1gygpm17eywos5xe7.jpg" alt="Dictionary to list in python" width="800" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[1, 'alpha'], [2, 'beta'], [3, 'gamma'], [4, 'sigma'], [5, 'omega']]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Tuple to List
&lt;/h2&gt;

&lt;p&gt;This code will accept a nested tuple into nested list. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytsztcay7tt2lfdy6rw3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytsztcay7tt2lfdy6rw3.jpg" alt="tuple to list in python" width="800" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[[1, 'alpha'], [2, 'beta'], [3, 'gamma'], [4, 'sigma'], [5, 'omega']]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Find duplicates in the List
&lt;/h2&gt;

&lt;p&gt;A code to find duplicate items in the list, find how many time it is repeated and put the detail into dictionary for eg., {'Lorem': 2, 'Ipsum': 2}.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3j4wp2bmtsvxmttlukfh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3j4wp2bmtsvxmttlukfh.jpg" alt="Find duplicates in the list in python" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'Lorem': 2, 'Ipsum': 2, 'dummy': 2, 'text': 2, 'of': 2, 
'the': 3, 'and': 2, 'a': 2, 'type': 2}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Split String List into pairs
&lt;/h2&gt;

&lt;p&gt;Split string into the pairs, what?&lt;br&gt;
Say, "hello I am working" to ["hello I", "am working"].&lt;br&gt;
Seems easy right? Let's do it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrqa80pjs1ii61l2tmme.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flrqa80pjs1ii61l2tmme.jpg" alt="Split string list into pairs in python" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['Lorem Ipsum', 'is simply', 'dummy text', 'of the', 'printing 
and', 'typesetting industry.', 'Lorem Ipsum', 'has been', "the 
industry's", 'standard dummy', 'text ever', 'since the', '1500s, 
when', 'an unknown', 'printer took', 'a galley', 'of type', 'and 
scrambled', 'it to', 'make a', 'type specimen', 'book.']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. List can store Functions inside it
&lt;/h2&gt;

&lt;p&gt;Yes you can store functions inside a list and access it the same way you access a list item, both using for-loop and through indices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb77w6et25jha5nk1vsum.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb77w6et25jha5nk1vsum.jpg" alt="python functions in a list" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello Rahul how are you !
I AM MAD!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10. Map function with list
&lt;/h2&gt;

&lt;p&gt;In simple words, map accept two iterators and iterate one iterator item with other until no items left. So, I am going to be a little creative and using the greet function from last step for demonstration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbew03b9udolunrglrc04.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbew03b9udolunrglrc04.jpg" alt="python map function with list" width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['Hello, Ram how are you !', 'Hello, Abhishek how are you !', 
'Hello, Rahul how are you !']
[480, 250, 120]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>Simple Diary/Note App in Django with User Login</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Mon, 07 Mar 2022 15:53:59 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/simple-diarynote-app-in-django-with-user-login-5bom</link>
      <guid>https://dev.to/rahulkumarmalhotra/simple-diarynote-app-in-django-with-user-login-5bom</guid>
      <description>&lt;p&gt;This is a simple note/diary app which allow you to create user account and write notes. &lt;/p&gt;

&lt;h2&gt;
  
  
  Sample Pictures
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybu1v0xqywh15nox1hty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybu1v0xqywh15nox1hty.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0ja6ihpx7tdfvan7vm0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0ja6ihpx7tdfvan7vm0.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rahul-kumar-bly/Simple-Note-WebApp-In-Django" rel="noopener noreferrer"&gt;Find this on Github&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to add data from CSV file to MySQL using Python</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Sat, 05 Mar 2022 12:23:11 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/how-to-add-data-from-csv-file-to-mysql-using-python-342e</link>
      <guid>https://dev.to/rahulkumarmalhotra/how-to-add-data-from-csv-file-to-mysql-using-python-342e</guid>
      <description>&lt;p&gt;For this tutorial my agenda is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Fetch data from CSV file&lt;/li&gt;
&lt;li&gt;Add data to a list&lt;/li&gt;
&lt;li&gt;Insert list data into a MySQL database&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is my CSV file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcd21yjcg0hok0fgj9k7i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcd21yjcg0hok0fgj9k7i.png" alt="data.csv" width="798" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, I will write a code to first add this data into a list which has dictionaries like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dict_list = [{'empid': '1', 'name': 'john', 'phone': '5123'}, {'empid': '2', 'name': 'jane', 'phone': '5124'}, {'empid': '3', 'name': 'doe', 'phone': '5678'}, {'empid': '4', 'name': 'adam', 'phone': '7427'}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, let's get started with today's tutorial. Make sure to have data.csv file into the same folder as your python file.&lt;br&gt;
I assume that you have mysql up and running.&lt;/p&gt;


&lt;h2&gt;
  
  
  Step [1]: Import Required Modules
&lt;/h2&gt;

&lt;p&gt;In this step I will import important modules&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pathlib
import csv
import mysql.connector
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [2]: Assign file path
&lt;/h2&gt;

&lt;p&gt;Make sure to keep you csv file in current working directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;csv_path = pathlib.Path.cwd() / "data.csv"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [3]: Fetch data from the csv file and add to dictionary
&lt;/h2&gt;

&lt;p&gt;This will create a list with dictionaries as shown above&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dict_list = list()
with csv_path.open(mode="r") as csv_reader:
    csv_reader = csv.reader(csv_reader)
    for rows in csv_reader:
        dict_list.append({'empid':rows[0], 'name':rows[1], 'phone':rows[2]})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [4]: Add a MySQL connection and cursor
&lt;/h2&gt;

&lt;p&gt;Using connection we connect to database and cursor will help performing operations on it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mydatabase = mysql.connector.connect(
    username = 'root',
    password = 'adminuser',
    host = 'localhost',
)

mycursor = mydatabase.cursor()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [5]: Create a database and assign it to connection
&lt;/h2&gt;

&lt;p&gt;We're making a database name "myempdb"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mycursor.execute("CREATE DATABASE myempdb")
# add below line inside your connect method 
# database = 'myempdb',
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [6]: Create table 'emptable' in myempdb
&lt;/h2&gt;

&lt;p&gt;The table will contains 3 rows "empid", "name", "phone"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mycursor.execute("CREATE TABLE emptable (empid INT PRIMARY KEY, name VARCHAR(255), phone INT")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [7]: Adding data to database
&lt;/h2&gt;

&lt;p&gt;Add list_dict data to database using loop and closing database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for item in dict_list:
    sql = "INSERT INTO emptable(empid, name, phone) VALUES (%s, %s, %s)"
    val = item['empid'], item['name'], item['phone']
    mycursor.execute(sql, val)
mydatabase.commit()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [8]: Fetch the data and display it on terminal
&lt;/h2&gt;

&lt;p&gt;This will show all the data stored in "emptable" into terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mycursor.execute('SELECT * FROM emptable')
myresult = mycursor.fetchall()
for x in myresult:
    print(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step [9]: Fetch the data and display it on terminal
&lt;/h2&gt;

&lt;p&gt;This will disconnect the connection to MySQL server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mydatabase.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnoi1c5nbh1v109ijzjpp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnoi1c5nbh1v109ijzjpp.png" alt="SQL Workbench" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Final code
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# fetch data from csv file

import pathlib
import csv
import mysql.connector

csv_path = pathlib.Path.cwd() / "data.csv"

dict_list = list()
with csv_path.open(mode="r") as csv_reader:
    csv_reader = csv.reader(csv_reader)
    for rows in csv_reader:
        dict_list.append({'empid':rows[0], 'name':rows[1], 'phone':rows[2]})


mydatabase = mysql.connector.connect(
    username = 'root',
    password = 'adminuser',
    host = 'localhost',
    database = 'myempdb',
)

mycursor = mydatabase.cursor()

mycursor.execute("CREATE DATABASE myempdb")

mycursor.execute("CREATE TABLE emptable (empid INT PRIMARY KEY, name VARCHAR(255), phone INT")

for item in dict_list:
    sql = "INSERT INTO emptable(empid, name, phone) VALUES (%s, %s, %s)"
    val = item['empid'], item['name'], item['phone']
    mycursor.execute(sql, val)
mydatabase.commit()


mycursor.execute('SELECT * FROM emptable')
myresult = mycursor.fetchall()
for x in myresult:
    print(x)

mydatabase.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>database</category>
      <category>mysql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Django Basic Oversimplified Part - 1</title>
      <dc:creator>Rahul Kumar</dc:creator>
      <pubDate>Tue, 15 Feb 2022 12:50:21 +0000</pubDate>
      <link>https://dev.to/rahulkumarmalhotra/django-basic-oversimplified-2hek</link>
      <guid>https://dev.to/rahulkumarmalhotra/django-basic-oversimplified-2hek</guid>
      <description>&lt;p&gt;Hi and welcome to Django Basic Oversimplified.&lt;/p&gt;

&lt;p&gt;Before I start with the tutorial, let me tell you a little story.&lt;br&gt;
15 days ago I started working on django and I kid you not this is the most intimidating process I have ever faced in my life. There are steps after steps I needed to take before displaying just 2 words on a blank page.&lt;/p&gt;

&lt;p&gt;It's not just me but other people too found it baffling. So, once I learned and created 2 small projects I decided to create a simple tutorial to explain what you really need to know in your first try. &lt;/p&gt;

&lt;p&gt;In this tutorial I will focus on introduction of various steps used in creating a Django app/website. Again, this post might look scary but trust me its not. &lt;/p&gt;
&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Getting Started with Django&lt;/li&gt;
&lt;li&gt;Initializing the Project Folder and App Folder&lt;/li&gt;
&lt;li&gt;Defining Views&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A short note: I am using WSL2 on top of my Windows 10 Visual Studio Code IDE. I highly recommend you to use WSL2 in case you are in Windows 10 or higher.&lt;/p&gt;

&lt;h2&gt;
Getting Started with Django&lt;/h2&gt;

&lt;h4&gt;Installing necessary files and setting up virtual environment.&lt;/h4&gt;

&lt;p&gt;Now lets start by creating a folder with whatever name you like, for the sake of this tutorial I am choosing "django-oversimplified".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mkdir django-oversimplified&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we need to open our visual code in this folder. In order to do that first enter into folder using cd.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd django-oversimplified
code .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mind the space between code and .(dot) it will open VS Code into our folder. If this ask for permission, allow it.&lt;/p&gt;

&lt;p&gt;Now we have to run &lt;strong&gt;virtual environment&lt;/strong&gt; first install it using&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt virtualenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You don't need to overthink about virtual environment here. It will pack all our python module inside and make it accessible by the other people who are using our code.&lt;/p&gt;

&lt;p&gt;The next step is to activate it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 -m venv .venv
source .venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0k4wis2lj0rse9a0oh0w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0k4wis2lj0rse9a0oh0w.jpg" alt="Django Virtualenv activation code" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first line means we are &lt;u&gt;creating a folder for virtual environment&lt;/u&gt;. Let me explain it further &lt;strong&gt;python3 -m&lt;/strong&gt; means we are accessing a python module which is &lt;strong&gt;venv&lt;/strong&gt; in our case and creating an &lt;strong&gt;enivronment directory&lt;/strong&gt; named &lt;strong&gt;.venv&lt;/strong&gt;. The dot before name will make it hidden.&lt;/p&gt;

&lt;p&gt;The second line means we are activating a script which is in activate folder within &lt;strong&gt;.venv/bin&lt;/strong&gt;&lt;br&gt;
There is nothing more you need to know about venv right now. Beside it will carry any module we download or install inside it.&lt;/p&gt;

&lt;p&gt;You can use clear command to clear your terminal window.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;clear&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, its time for me to create our first project but before that we need to install django. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install django&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you already have django isntalled then this will copy django to your .venv folder.&lt;/p&gt;

&lt;p&gt;Till this point we - &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Created a directory for our project&lt;/li&gt;
&lt;li&gt;Installed PIP and Virtual Environment&lt;/li&gt;
&lt;li&gt;Activated Virtual Environment&lt;/li&gt;
&lt;li&gt;Downloaded Django&lt;/li&gt;
&lt;/ol&gt;



&lt;h2&gt;
Initializing the Project Folder and App Folder&lt;/h2&gt;

&lt;h4&gt;The first step to your app, setting up urls and running our sample app.&lt;/h4&gt;

&lt;p&gt;Now we are ready to create our first app but first lets create our project. The project in itself is not your app it does not visualize anything.&lt;br&gt;
In simple words it is a set of settings or configurations which power your django apps or websites you will come to know more about them when we start using them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;django-admin startproject myproject&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will generate a directory and inside another directory with same name and a python file "manage.py".&lt;br&gt;
Its a bit awkward to enter myproject and then working on another myproject directory. So let's remove it and create our project folder right inside django-oversimplified.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rm -r myproject&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can simply delete it but it just a linux command for us. &lt;strong&gt;rm&lt;/strong&gt; is for remove directory and &lt;strong&gt;-r&lt;/strong&gt; flag denotes the directory is not empty.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;django-admin startproject myproject .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Mind the space between myproject and .(dot). The dot ensure this directory (django-oversimplified) and ensure the project folder is generated inside our main directory.&lt;/p&gt;

&lt;p&gt;Your project folder will look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28on7q46h6kuncxj5ybs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28on7q46h6kuncxj5ybs.jpg" alt="Django Project Folder" width="407" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Time to create an app named 'myapp'.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;django-admin startapp myapp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You don't need to worry about subfolder this time as this will be generated inside your main folder.&lt;/p&gt;

&lt;p&gt;Now once you expand the myapp folder you will see some bunch of files there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrfyrgrie0gjmgdh9rmj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrfyrgrie0gjmgdh9rmj.jpg" alt="Django App Folder" width="496" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to work with &lt;strong&gt;admin.py, apps.py, models.py, and views.py&lt;/strong&gt; for this project plus one more file which you will find soon.&lt;/p&gt;

&lt;p&gt;Now, lets get back to our settings folder "myproject". In here we are going to work with &lt;strong&gt;settings.py and urls.py&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The very first thing I am gonna do is &lt;strong&gt;register our app&lt;/strong&gt; in settings.py. Remember our app name is same as its directory &lt;br&gt;
myapp'.&lt;/p&gt;

&lt;p&gt;In settings.py find the &lt;strong&gt;INSTALLED_APPS (line 33) list&lt;/strong&gt; and inside this list enter your app name.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;'myapp',&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This means we have linked/installed myapp with our project. Save it and close it for now.&lt;/p&gt;

&lt;p&gt;Now we are very close to our first app.&lt;/p&gt;

&lt;p&gt;Open &lt;strong&gt;urls.py&lt;/strong&gt; this file will ensure the navigations in our app. However, we are going to create another file in our app folder in order to make everything easy.&lt;br&gt;
For this we need to include that particular file in our URLS.py. Just to make it clear the first line of code in **urlpatterns **list ensure the path to admin.&lt;/p&gt;

&lt;p&gt;See you urls will be like this &lt;u&gt;127.0.0.1:8000&lt;/u&gt; and the admin here will be &lt;u&gt;127.0.0.1:8000/admin/&lt;/u&gt; the extra slash after admin ensure the same on your URL part in browser. We will learn more about it later.&lt;/p&gt;

&lt;p&gt;Now what we want to do is to avoid using this file in future so we are going to create a point where we can access all of this file feature right from our app folder.&lt;/p&gt;

&lt;p&gt;In our myapp folder create a file, URLS.py. &lt;br&gt;
Now, get back to the project folder and URLS.py and add a piece of code first.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;from django.urls import include&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and inside your urlpatterns &lt;/p&gt;

&lt;p&gt;&lt;code&gt;path('', include('myapp.urls')),&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We have pointed our urls.py file inside myapp folder which will handle operations on every url except admin.&lt;br&gt;
So, if you want to handle &lt;u&gt;127.0.0.1:8000/helloworld/&lt;/u&gt;, the &lt;strong&gt;urls.py file inside myapp&lt;/strong&gt; will take care of it.&lt;/p&gt;

&lt;p&gt;Now move on to your myapp.urls file and enter the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.urls import path
urlpatterns = [

]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Till this point we - &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Created our project/setting folder&lt;/li&gt;
&lt;li&gt;Created an app named myapp&lt;/li&gt;
&lt;li&gt;Installed our app in settings.py&lt;/li&gt;
&lt;li&gt;Handle the URL behaviors&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
Defining Views&lt;/h2&gt;

&lt;h4&gt;Creating urls.py file and running our very first hello world app.&lt;/h4&gt;

&lt;p&gt;Now we are going to design what we call view.&lt;br&gt;
Now, what does it means? is it means we are designing our frontend? Sort of.&lt;/p&gt;

&lt;p&gt;Remember Django is not MVC, it is MVT.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;M stands for models/database&lt;br&gt;
V stands for views &lt;br&gt;
T stands for template&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just like in MVC the C is controller its exactly what &lt;strong&gt;views&lt;/strong&gt; in our Django. &lt;br&gt;
Controller controls what going to be in your front end it doesn't design the frontend but controls the behavior of it.&lt;br&gt;
The template will display the content to your front-end nevertheless.&lt;/p&gt;

&lt;p&gt;This article is getting longer. but don't worry it will become a piece of cake.&lt;br&gt;
Now in our views.py we are going to create a function that display the most anticipated &lt;strong&gt;hello world&lt;/strong&gt; message. But before anything let's ensure everything is working fine. Type,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python manage.py runserver&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Click on the url by holding ctrl key or just type 127.0.0.1:8000 in your browser.&lt;/p&gt;

&lt;p&gt;If you can see "The install worked successfully" page, well done its working.&lt;br&gt;
If you can't make sure to back-track this tutorial.&lt;/p&gt;

&lt;p&gt;It's time to display a hello world message on our home page.&lt;br&gt;
Open your views.py file and enter below code first then I will explain what we just did.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def hello_world(request):
    return HttpResponse("&amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now get to your urls.py (myapp) and enter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from . import views
urlpatterns =[
path('',views.hello_world),
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbc1nevbbhbofcnpseama.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbc1nevbbhbofcnpseama.jpg" alt="Django App URLS.py" width="555" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will display this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyrcgo2lhowqan4641juu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyrcgo2lhowqan4641juu.jpg" alt="Django Hello World App" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the first code block we define a function name &lt;strong&gt;hello_world&lt;/strong&gt; which receive a request.&lt;br&gt;
Now request is whatever you provide to the browser. In our case we are requesting the homepage which means &lt;strong&gt;127.0.0.1:8000&lt;/strong&gt; see we are not using requesting any endpoint like /admin/ after the url.&lt;/p&gt;

&lt;p&gt;And it returns the httpresponse which in simple word is html.&lt;br&gt;
If you open the page in browser as code (Ctrl+U) you will see the exact same code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We have defined a pattern for this file inside the urls.py (myapp).&lt;br&gt;
We used empty '' string to ensure this hello world will display on our homepage and we added our hello_world to make sure it process the function we created for every &lt;strong&gt;&lt;u&gt;&lt;a href="http://127.0.0.1:8000/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/&lt;/a&gt;&lt;/u&gt;&lt;/strong&gt; request.&lt;/p&gt;

&lt;p&gt;At this point we -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Learn what is views and created one&lt;/li&gt;
&lt;li&gt;Link our view to URLS.py file in my app&lt;/li&gt;
&lt;li&gt;Accessed our &lt;strong&gt;hello world&lt;/strong&gt; app&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This was the part 1 of our Django Basic Oversimplified series. I will get back to you with more forthcoming parts. &lt;br&gt;
What's next?&lt;br&gt;
We will create a site which accept data from user and store it into database and send an email on behalf of it.&lt;br&gt;
Till now, happy coding.&lt;/p&gt;

</description>
      <category>django</category>
      <category>beginners</category>
      <category>python</category>
    </item>
  </channel>
</rss>
