<?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: VISHAK</title>
    <description>The latest articles on DEV Community by VISHAK (@vishak369).</description>
    <link>https://dev.to/vishak369</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%2F795672%2F0093fe3e-88d0-44e1-b8ae-58a665814f86.jpg</url>
      <title>DEV Community: VISHAK</title>
      <link>https://dev.to/vishak369</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vishak369"/>
    <language>en</language>
    <item>
      <title>Build your first python flask App</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Sat, 23 Dec 2023 15:09:56 +0000</pubDate>
      <link>https://dev.to/vishak369/build-your-first-python-flask-app-3cao</link>
      <guid>https://dev.to/vishak369/build-your-first-python-flask-app-3cao</guid>
      <description>&lt;p&gt;Flask is a popular Python web framework that’s known for its simplicity and ease of use. If you’re new to web development or just getting started with Flask, this blog post is the perfect place to begin. We’ll guide you through the process of creating a basic Flask application from scratch. By the end, you’ll have a working Flask app and a foundational understanding of web development using Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setting Up Your Development Environment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;i) Setting up python virtual environment&lt;/p&gt;

&lt;p&gt;ii) Installing Python and Flask&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creating Your First Flask Application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building a Simple Web Page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running Your Flask App&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conclusion&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Setting Up Your Development Environment&lt;/strong&gt;&lt;br&gt;
Before you begin, ensure you have the following prerequisites in place:&lt;/p&gt;

&lt;p&gt;Python: Flask is a Python web framework, so you’ll need Python installed. If you don’t have Python, you can download and install it from the official Python website&lt;br&gt;
Text Editor or IDE: Choose a code editor or integrated development environment (IDE) for writing your Flask code. Options include Visual Studio Code, PyCharm, and Sublime Text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;i) Setting up python virtual environment&lt;/strong&gt;&lt;br&gt;
Creating a Python environment is a fundamental step in setting up your development environment, especially when working on Python projects. Python environments allow you to manage dependencies, packages, and libraries specific to your project, ensuring that your project remains isolated from the global Python environment. In this guide, we’ll create a Python environment using the popular tool virtualenv.&lt;/p&gt;

&lt;p&gt;virtualenv is a Python package that helps you create isolated Python environments. To install virtualenv, open your terminal or command prompt and run the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;To use venv in your project, in your terminal, create a new project folder, cd to the project folder in your terminal, and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ mkdir project1

 $ cd project1

 syntax: python&amp;lt;version&amp;gt; -m venv &amp;lt;virtual-environment-name&amp;gt;

 $ python3.8 -m venv myenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To activte the virtual environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source myenv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will activate your virtual environment. Immediately, you will notice that your terminal path includes env, signifying an activated virtual environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some useful commands&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// To list all the packages installed in this env
$ pip list

//To copy all the packages that we have installed in this environment and we can install the entire packages from the file in another environment
$ pip freeze &amp;gt; requirements.txt

// To install dependencies from the file
$ pip install -r requirements.txt

//To deactive the virtual environment
$ deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ii) Installing Flask&lt;/strong&gt;&lt;br&gt;
Once you have Python and a code editor ready, it’s time to install Flask. Open your terminal or command prompt and run the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This command installs Flask and its dependencies. You’re now ready to create your first Flask application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Creating Your First Flask Application&lt;/strong&gt;&lt;br&gt;
Let’s start with a basic Flask application. Create a new Python file (usually with a .py extension) and add the following code(app.py):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//import flask module
from flask import Flask

app = Flask(__name__)

//create hello world print function for the "/" route path
@app.route('/')
def hello():
    return "Hello, Flask!"

if __name__ == '__main__':
    app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we import Flask, create a Flask application, define a route for the root URL (‘/’), and create a function that returns “Hello, Flask!” when you access that URL. Finally, we run the application if the script is executed directly. We can see the “Hello, Flask!” in the browser if we run the above code.&lt;br&gt;
&lt;strong&gt;3. Building a Simple Web Page&lt;/strong&gt;&lt;br&gt;
Now, let’s create a simple HTML page and render it using Flask. You can add an HTML file to your project directory, name it index.html, and add the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;FLASK APP&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Welcome to python Flask&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;This is a simple Flask web application.&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, modify your Flask app to render this HTML page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def hello():
    return render_template('index.html')

if __name__ == '__main__':
    app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when you access the root URL, Flask will render the HTML page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Running Your Flask App&lt;/strong&gt;&lt;br&gt;
To run your Flask app, open a terminal, navigate to the directory where your Python file is located, and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//python your_app_name.py
$ python app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Flask app will start, and you can access it by opening a web browser and navigating to &lt;a href="http://localhost:5000/"&gt;http://localhost:5000/&lt;/a&gt;. You'll see your "Welcome to My Flask App" page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Conclusion&lt;/strong&gt;&lt;br&gt;
You’ve just built a simple Flask web application, which is your gateway to Python web development. Flask’s simplicity and ease of use make it an excellent choice for both beginners and experienced developers. As you continue your journey in web development, you can explore more complex features and build web applications with rich functionality.&lt;/p&gt;

&lt;p&gt;Flask provides a solid foundation for creating web applications, and there’s a wealth of resources, extensions, and libraries available to help you build more advanced projects. So, dive into Flask, experiment, and enjoy the world of web development with Python.&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Best extension in VSCode for DevOPs/Developers</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Wed, 09 Nov 2022 16:35:56 +0000</pubDate>
      <link>https://dev.to/vishak369/best-extension-in-vscode-for-devopsdevelopers-569e</link>
      <guid>https://dev.to/vishak369/best-extension-in-vscode-for-devopsdevelopers-569e</guid>
      <description>&lt;p&gt;Found this amazing extension &lt;a href="https://dev.tourl"&gt;draw.io&lt;/a&gt; in vscode editor.&lt;/p&gt;

&lt;p&gt;Now you can create architecture diagrams/flowcharts alongside your code from the vscode itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install?
&lt;/h2&gt;

&lt;p&gt;1) Just add the &lt;strong&gt;draw.io&lt;/strong&gt; extension in your vscode editor.&lt;/p&gt;

&lt;p&gt;2) Create a file with the extension .drawio&lt;br&gt;
   eg: test.drawio&lt;/p&gt;

&lt;p&gt;3) Explore 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;1) Uses an offline version of Draw.io by default.&lt;br&gt;
2) Multiple Draw.io themes are available.&lt;br&gt;
3) Use Liveshare to collaboratively edit a diagram with &lt;br&gt;
   others.&lt;br&gt;
4) Nodes/edges can be linked with code spans.&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>webdev</category>
      <category>devops</category>
      <category>design</category>
    </item>
    <item>
      <title>3-Tier Architecture</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Wed, 09 Nov 2022 15:22:32 +0000</pubDate>
      <link>https://dev.to/vishak369/3-tier-architecture-3a79</link>
      <guid>https://dev.to/vishak369/3-tier-architecture-3a79</guid>
      <description>&lt;p&gt;Three-tier architecture is a well-established software application architecture that organizes applications into three logical and physical computing tier, the presentation tier, or user interface; the application tier, where data is processed, and the data tier, where the data associated with the application is stored and managed.&lt;/p&gt;

&lt;p&gt;It is more complex than the 2-tier client-server computing model, because it is more difficult to build a 3-tier application compared to a 2-tier application. The physical separation of application servers containing business logic functions and database servers containing databases may be something that affects performance.&lt;/p&gt;

&lt;p&gt;The diagram for a three-tier architecture,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1_gFyBro--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hf5lsy0swd48tf6gm76m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1_gFyBro--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hf5lsy0swd48tf6gm76m.png" alt="Image description" width="880" height="929"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Presentation  Layer&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The request from the external loadbalancer will refer to either of the web servers because it is the topmost layer, which the user can access directly. The request is forwarded to the second live server if one web server is offline.  It is responsible to communicate with the application server to provide output to the user end.-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It regulates the fundamental operations of the application by carrying out careful processing. The database layer and web layer are connected via the application layer. The application, which is used to exchange processed data, will be implemented in this layer. This layer is where all logical operations will take place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An Oracle, MongoDB, MySQL, SQL, PostgreSQL, MariaDB, etc., can be used as the database layer. The database server will house all of the data. This increases security because only the application layer will have direct interface with the database layer. The database layer can leverage Innodb clusters to increase availability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Innodb Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The innodb cluster is used to increase the database's availability. It consists of numerous database servers with identical data in each database. The innodb cluster will respond appropriately to the request forwarded to it. Requests are sent to the other two active databases if one database fails. Only the application server will have the direct communication with the cluster that improves the security, no external request can directly access the db cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Work Flow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The request from the user passes through the firewall to the external loadbalancer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The external load balancer will send request to anyone of the healthy webserver.The load balancer will route requests to the other web server if one web server is down or has too many requests.Httpd, nginx can  be be used as an web server to server the incoming requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Webserver pass the request to the internal loadbalancer(Haproxy) that will handles the incoming requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From the internal loadbalancer the request will be send to the application server. As we discussed earlier the internal loadbalancer have some logic to send traffic to the suitable application server(depends on the loadbalancer configuration). Also we can restrict sending request to app server using reverse proxy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Application loadbalancer will be interconnected with the innobd cluster to store and retrieve data from the database. Application server will only have direct communication with the database.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) As a result of the application servers' ability to be &lt;br&gt;
  installed on numerous machines, increased scalability is the &lt;br&gt;
  primary three-tier benefit.&lt;/p&gt;

&lt;p&gt;2) Balancing of load is much easier with division of core &lt;br&gt;
   business from the server of the database.&lt;/p&gt;

&lt;p&gt;3) Improve security and data integrity. Business logic is more&lt;br&gt;&lt;br&gt;
   secure because it is stored on a secure central server&lt;/p&gt;

&lt;p&gt;4) High scalability due to the tiers are based on the &lt;br&gt;
   deployment of layers, scaling out an application is &lt;br&gt;
   reasonably straightforward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) A separate proxy server may be required.&lt;/p&gt;

&lt;p&gt;2) Network traffic will be increased if a separate proxy &lt;br&gt;
   server is used.&lt;/p&gt;

&lt;p&gt;3) The physical separation of application servers containing&lt;br&gt;&lt;br&gt;
   business logic functions and database servers containing &lt;br&gt;
   databases may be something that affects performance.&lt;/p&gt;

&lt;p&gt;4) Increased complexity &lt;/p&gt;

</description>
      <category>architecture</category>
      <category>linux</category>
      <category>beginners</category>
      <category>devops</category>
    </item>
    <item>
      <title>Two-Tier Architecture</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Sat, 27 Aug 2022 07:31:00 +0000</pubDate>
      <link>https://dev.to/vishak369/two-tier-architecture-56hl</link>
      <guid>https://dev.to/vishak369/two-tier-architecture-56hl</guid>
      <description>&lt;p&gt;In two-tier architecture, the presentation layer or user interface layer runs on the client side while dataset layer gets executed and stored on server side.&lt;/p&gt;

&lt;p&gt;Data is stored in a seperate server that offers greater control over the server along with higher level of security. Even if the application fails, data will be stored securely in the server and can be retained. Backup data in multiple servers will defenitely improves the data redundancy.&lt;/p&gt;

&lt;p&gt;The user system interface is usually located in the user’s desktop environment and the database management services are usually in a server that is a more powerful machine that services many clients. There wont be any business logic layers between the application layer and database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p4BvvPES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rewcdv3k5gk8jo6a4krq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p4BvvPES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rewcdv3k5gk8jo6a4krq.png" alt="Image description" width="752" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) As most of the data is stored centrally in the server, it is much easier to do updates on the data. This is one of the simplest architectural styles.&lt;/p&gt;

&lt;p&gt;2) Since this contains static business rules it’s more &lt;br&gt;
   applicable for homogenous environments.&lt;/p&gt;

&lt;p&gt;3) Easy to maintain.&lt;/p&gt;

&lt;p&gt;4) It runs faster and it is tightly coupled between client &lt;br&gt;
   applications and data source.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) Cannot be used for higher applications.&lt;/p&gt;

&lt;p&gt;2) Scalability will be problematic.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>architecture</category>
      <category>devops</category>
    </item>
    <item>
      <title>One-Tier Architecture</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Thu, 21 Jul 2022 15:57:00 +0000</pubDate>
      <link>https://dev.to/vishak369/one-tier-architecture-4o0m</link>
      <guid>https://dev.to/vishak369/one-tier-architecture-4o0m</guid>
      <description>&lt;h2&gt;
  
  
  Single tier Architecture
&lt;/h2&gt;

&lt;p&gt;All services that are needed to build an application will be configured inside a single server that also handles requests and responses.&lt;/p&gt;

&lt;p&gt;Basically, an application needs a webserver(httpd, nginx etc) ,app server(JBoss, Tomcat, Glassfish) and finally database server(mysql, oracle, mongoDB etc) to work effectively, so in a single server architecture all the above mentioned components will be configured in a single server. The server's private IP will be used for all communications between the web, app, and database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S4sUMEQf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txry597jm11n74yu7wyo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S4sUMEQf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txry597jm11n74yu7wyo.jpg" alt="Image description" width="628" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a single-tier architecture,all the services will be on the same machine using the same resources, which can create an availability risk. If the server is down, then the entire application will be down. Single tier is suitable for simple applciations or sites with low traffic.&lt;/p&gt;

&lt;p&gt;Below is a basic diagram of a single tier architecture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MeNUUonu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22q0av307al07h0kvslr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MeNUUonu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22q0av307al07h0kvslr.jpg" alt="Image description" width="803" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see from the above diagram that user requests are routed through the firewall to a single server, and that all communications take place solely between the user and the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;br&gt;
1) Cost effective&lt;br&gt;
2) Simple and uncomplicated design&lt;br&gt;
3) Faster communication between App, Web and Database services&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;br&gt;
1) Less Availability&lt;br&gt;
2) Higher down time&lt;/p&gt;

&lt;p&gt;Cheers🥂🚀&lt;br&gt;
Keep Learning!&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>help</category>
    </item>
    <item>
      <title>Most needed commands for "SED" and "Vim" in linux.</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Sun, 17 Jul 2022 14:00:00 +0000</pubDate>
      <link>https://dev.to/vishak369/most-needed-commands-for-sed-and-vim-in-linux-161b</link>
      <guid>https://dev.to/vishak369/most-needed-commands-for-sed-and-vim-in-linux-161b</guid>
      <description>&lt;h2&gt;
  
  
  SED
&lt;/h2&gt;

&lt;p&gt;SED command in UNIX stands for stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening them, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's explore some powerful commands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;sed options,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-n&lt;/strong&gt; is for viewing the changes(will not update the file with the changes).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-i&lt;/strong&gt;  is used to update the changes.&lt;/p&gt;

&lt;p&gt;1) How to delete a specific word in a file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i  's/devops//g' filename.txt&lt;/code&gt; &lt;br&gt;
 &lt;em&gt;It will delete the word "devops" from the file filename.txt&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;2) How to change word in a file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i 's/centos/ubuntu/g' filename.txt&lt;/code&gt;&lt;br&gt;
  &lt;em&gt;All word changes from centos to ubuntu&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;3)  How to delete a file containing specific word&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i '/_linux_/d' file.txt&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;em&gt;It will delete the line containing the word "linux"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;4) How to list all the specific words in a file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -n '/_docker_/p' filename.txt&lt;/code&gt;&lt;br&gt;
&lt;em&gt;It will list all the lines containing word docker&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;5)How to delete matching line and 2 lines after matching line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i '/_NAME_/,+2d' filename.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;6) How to replace all uppercase characters of the text with lowercase characters&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i 's/\(.*\)/\L\1/ filename.txt'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;7) How to view only a specific range of lines in a file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sed -n '5,10p' filename.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;8) How to replace words inside range of line &lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i '60,80 s/centos/ubuntu/g'&lt;/code&gt;&lt;br&gt;
  &lt;em&gt;Centos will change to ubuntu between lines 60-80&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;9) How to insert 5 spaces to the left of every lines&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# sed -i 's/^/     /' filename.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;10) how to delete particular line using sed&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sed -i '10d' filename.txt&lt;/code&gt;  &lt;em&gt;It will delete 10th line&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  VIM
&lt;/h2&gt;

&lt;p&gt;Vim is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface). It is mainly because it can be managed entirely without menus or a mouse with a keyboard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's explore some powerful commands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) How to delete all lines in a file&lt;br&gt;
 &lt;em&gt;Inside the vim editor&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dG&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2) How to delete a specific line &lt;/p&gt;

&lt;p&gt;&lt;code&gt;dd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3) How to delete range of lines&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:3,5d&lt;/code&gt;&lt;br&gt;
  &lt;em&gt;It will delete lines from line number 3 to line &lt;br&gt;
  number 5&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;4) How to delete current line to end of line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:.,$d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;5) How to delete current line to beginning of line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dgg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;6) How to remove the next three lines from the current line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;3dd&lt;/code&gt; - delete 3 lines&lt;br&gt;
&lt;code&gt;5dd&lt;/code&gt; -  delete 5 lines&lt;/p&gt;

&lt;p&gt;7) How to search a specific word in vim&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/string_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;8) How to get to a specific line &lt;/p&gt;

&lt;p&gt;&lt;code&gt;:_line_number_&lt;/code&gt;&lt;br&gt;
   eg- :50    &lt;em&gt;It will redirect to line 50&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;9) Save a file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:wq!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;10) exit without saving a file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:q!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Enjoy Learning🚀🐧&lt;/p&gt;

</description>
      <category>linux</category>
      <category>help</category>
      <category>bash</category>
    </item>
    <item>
      <title>Linux server health/process check.</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Wed, 06 Jul 2022 05:59:00 +0000</pubDate>
      <link>https://dev.to/vishak369/linux-server-healthprocess-check-20co</link>
      <guid>https://dev.to/vishak369/linux-server-healthprocess-check-20co</guid>
      <description>&lt;p&gt;All the details about the server health, process, resource utilization can be find using this single bash script.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Easy to get complete server information in a single click.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The script is simple to edit and add services to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shows details about the Process running, disk space, downtime, memory details, high process lists and lot more.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let's start!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1) Create the "healthcheck" script file and add the following codes to it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# vim healthcheck&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;#! /bin/bash
#color notes
NC='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
cyan='\033[0;36m'
yellow='\033[0;33m'
#Sectioning .........
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
echo "Server details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"

#fetching basic specs from the server(user,ip,os)
user=`whoami`
echo -e "${cyan}User:${NC} $user"
hostname=`hostname`
echo -e "${cyan}hostname:${NC} $hostname"
ip=`hostname -I`
echo -e "${cyan}IP address:${NC} $ip"
os=`cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' | grep NAME`
echo -e "${cyan}OS:${NC} $os"

#Sectioning.....
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
echo "Service status:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
sleep 1

#checking tomcat status
echo -e "${yellow}1) Tomcat${NC}"
#grepping tomcat status from ps aux
pp=`ps aux | grep tomcat | grep "[D]java.util"`
if [[ $pp =~ "-Xms512M" ]];then
 echo -e "   Status: ${GREEN}UP${NC}"

else
 echo -e "   Status: ${RED}DOWN${NC}"

fi
echo ""
#function to check apache is running or not!
function apache(){
echo -e "${yellow}2) Apache-httpd${NC}"
#grepping apache status from ps aux
httpd=`ps aux | grep httpd | grep apache`
if [[ $httpd =~ "apache" ]];then
 echo -e "   Status: ${GREEN}UP${NC}"

else
 echo -e "   Status: ${RED}DOWN${NC}"

fi

}

#function to check elastic is running or not
function elastic(){
echo -e "${yellow}3) Elasticsearch${NC}"
#grepping elasticsearch status from ps aux
elastic=`ps aux | grep elasticsearch`
if [[ $elastic =~ "elastic+" ]];then
  echo -e "   Status: ${GREEN}UP${NC}"
else
 echo -e "    Status: ${RED}DOWN${NC}"

fi
#function to check mysql is running or not
}
function mysql(){
echo -e "${yellow}4) Mysql${NC}"
#grepping mysql status from ps aux
mysql=`ps aux | grep mysqld`
if [[ $mysql =~ "mysqld" ]];then
 echo -e "   Status: ${GREEN}UP${NC}"
else
 echo -e "   Status: ${RED}DOWN${NC}"

fi
}


function docker(){
echo -e "${yellow}5) Docker${NC}"
#grepping docker status from ps aux
docker=`systemctl status docker | grep dead`
if [[ $docker =~ "dead" ]];then
 echo -e "   Status: ${GREEN}UP${NC}"
else
 echo -e "   Status: ${RED}DOWN${NC}"

fi
}

#calling functions
apache
echo ""
elastic
echo ""
mysql
echo ""
docker
echo ""
#Sectioning............
#Fetching mem and cpu informations
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
echo "Memory Details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
sleep 1
#view mem info
free -h
#get uptime details
uptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e "${cyan}System Uptime:${NC} :$uptime"
#Fetching the load average
loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e "${cyan}Load average:${NC}: $loadaverage"
echo -e "${cyan}The top 10 services with high resource usage are listed below.${NC}"
#Get top services with high resource utilization
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head


#sectioning...........
#Fetching server space details!
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
echo "Server space Details:"
echo -e "${YELLOW}---------------------------------------------------------------------------------------------------------------${NC}"
#View disk space details
df -h


echo "----------------------------------------------------------------------------------------------------------------"


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

&lt;/div&gt;



&lt;p&gt;2) By copying the file to the sbin directory and giving it execute permission, we can turn the script into a global command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# cp healthcheck /usr/sbin/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# chmod +x /usr/sbin/healthcheck&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3) Now you can call the script from anywhere in the shell&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# healthcheck&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;checkout the script output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qLKji--Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgkm0vjy5tcutu1q6uy6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qLKji--Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgkm0vjy5tcutu1q6uy6.jpg" alt="Linux health/process check" width="880" height="758"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RGO55ob9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w39egdn850jdfkoshagu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RGO55ob9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w39egdn850jdfkoshagu.jpg" alt="Linux health/process check-2" width="880" height="603"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boom&lt;/strong&gt;🚀🚀&lt;br&gt;
Keep Learning🥂&lt;/p&gt;

</description>
      <category>linux</category>
      <category>bash</category>
      <category>centos</category>
      <category>monitoring</category>
    </item>
    <item>
      <title>Dockerfile for Elasticsearch</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Sat, 28 May 2022 08:57:00 +0000</pubDate>
      <link>https://dev.to/vishak369/dockerfile-for-elasticsearcn-30fi</link>
      <guid>https://dev.to/vishak369/dockerfile-for-elasticsearcn-30fi</guid>
      <description>&lt;p&gt;Elasticsearch is a distributed, free and open search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured.&lt;/p&gt;

&lt;p&gt;Elasticsearch is the central component of the Elastic Stack, a set of free and open tools for data ingestion, enrichment, storage, analysis, and visualization.&lt;/p&gt;

&lt;p&gt;It is considerably easier and faster to run elasticsearch in a container than to install it on a host server.&lt;/p&gt;

&lt;p&gt;1)Create a docker file and add the below contents.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# vim Dockerfile&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;FROM centos:7
MAINTAINER vishakkv954@gmail.com
RUN useradd -ms /bin/bash elasticsearch
RUN yum -y install java-1.8.0-openjdk-devel
RUN yum -y install wget
RUN wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.rpm
RUN rpm -ivh elasticsearch-5.5.0.rpm
RUN mkdir /usr/share/elasticsearch/config
RUN cp -R /usr/share/elasticsearch/* /home/elasticsearch/
COPY elasticsearch.yml /home/elasticsearch/config/
COPY log4j2.properties /home/elasticsearch/config/
RUN chown -R elasticsearch:elasticsearch /home/elasticsearch/*
WORKDIR /home/elasticsearch
USER elasticsearch
EXPOSE 9200
EXPOSE 9300
CMD ["/home/elasticsearch/bin/elasticsearch"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;elasticsearch.yml and log4j2.properties are the updated files with the configurations needed for our elasticsearch.Place both files in the same directory where dockerfile exists.&lt;/p&gt;

&lt;p&gt;2) Build docker image&lt;br&gt;
   NB: be in the directory where dockerfile exists&lt;br&gt;
   &lt;code&gt;docker build -t elasticsearh .&lt;/code&gt;&lt;br&gt;
   "elasticsearch is the image name"&lt;/p&gt;

&lt;p&gt;3) Create docker container&lt;br&gt;
    &lt;code&gt;# docker images&lt;/code&gt; #to get the docker image id&lt;br&gt;
    &lt;code&gt;# docker run -d -P 9200:9200 -P 9300:9300 --name elastic &amp;lt;image id&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4) check container status&lt;br&gt;
    &lt;code&gt;# docker ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Play with docker🥂&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>docker</category>
      <category>linux</category>
      <category>dockerfile</category>
    </item>
    <item>
      <title>Mysql Dockerfile --&gt; Docker container. 🐧🐳</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Mon, 24 Jan 2022 18:58:00 +0000</pubDate>
      <link>https://dev.to/vishak369/mysql-dockerfile-docker-container-1phb</link>
      <guid>https://dev.to/vishak369/mysql-dockerfile-docker-container-1phb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Spinup Mysql Docker Container✨&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spinning a MySQL DB on docker is easier than installing and configuring it on a raw server and can spin up the MYSQL container within a few mins.&lt;/p&gt;

&lt;p&gt;We can avoid MySQL secure installations, cnf configurations, and other setups that needed to be composed before starting the DB.&lt;/p&gt;

&lt;p&gt;We can classify this into 3 stages,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Dockerfile creation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2) Docker image creation&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3) Docker container creation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; Create the docker file&lt;/p&gt;

&lt;p&gt;A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.&lt;br&gt;
First, create a docker file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# vim Dockerfile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Refer to the Dockerfile below to spinup MySQL 8.0&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM mysql:8.0.23    
MAINTAINER vk@gmail.com
COPY my.cnf /etc/mysql/my.cnf  
ENV MYSQL_ROOT_PASSWORD mypassword 
ENV MYSQL_USER bob  
ENV MYSQL_DATABASE DATA123 
ENV MYSQL_PASSWORD new_password 
RUN mkdir /var/lib/mysql-files
RUN touch /var/log/mysqld.log
RUN chown mysql:mysql /var/log/mysqld.log
EXPOSE 3306
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FROM mysql:8.0.23&lt;/strong&gt;  --&amp;gt; Choosing base image as mysql.&lt;br&gt;
&lt;strong&gt;MAINTAINER &lt;a href="mailto:vk@gmail.com"&gt;vk@gmail.com&lt;/a&gt;&lt;/strong&gt; --&amp;gt; Author field.&lt;br&gt;
&lt;strong&gt;COPY my.cnf /etc/mysql/my.cnf&lt;/strong&gt; --&amp;gt; Need to setup the cnf file as for your configuration and copy the .cnf file to the directory where Dockerfile is located.&lt;br&gt;
&lt;strong&gt;ENV MYSQL_ROOT_PASSWORD mypassword&lt;/strong&gt; --&amp;gt; 'mypassword' will be the password for root user&lt;br&gt;
&lt;strong&gt;ENV MYSQL_USER bob&lt;/strong&gt; --&amp;gt; Create a additional mysql user named 'bob' if needed&lt;br&gt;
&lt;strong&gt;ENV MYSQL_DATABASE DATA123&lt;/strong&gt; --&amp;gt; Creating database 'DATA123' &lt;br&gt;
&lt;strong&gt;ENV MYSQL_PASSWORD new_password&lt;/strong&gt; --&amp;gt; Password for mysql users.&lt;br&gt;
&lt;strong&gt;RUN mkdir /var/lib/mysql-files&lt;/strong&gt; --&amp;gt; Create mysql lib file directory.&lt;br&gt;
&lt;strong&gt;RUN touch /var/log/mysqld.log&lt;/strong&gt; --&amp;gt; Creating mysql log file to write the mysql logs.&lt;br&gt;
&lt;strong&gt;RUN chown mysql:mysql /var/log/mysqld.log&lt;/strong&gt; --&amp;gt; Ownership change for that file.&lt;br&gt;
&lt;strong&gt;EXPOSE 3306&lt;/strong&gt;  --&amp;gt; Assigning container port.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; Docker image creation&lt;/p&gt;

&lt;p&gt;Move to the directory where the  Dockerfile is located, then run the below command to create the docker image.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# docker build -t image_name .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; Finally create docker container.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# docker images&lt;/code&gt; // to view the image id&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# docker run -d -p host_port:container_port --name {container-name} {image id}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;eg : # docker run -d -p 3306:3306 --name mydatabase 037da8935fa&lt;/p&gt;

&lt;p&gt;check the status of the container,&lt;br&gt;
&lt;code&gt;# docker ps -a&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Cheers!🥂✨&lt;/p&gt;

</description>
      <category>docker</category>
      <category>mysql</category>
      <category>linux</category>
      <category>dockerfile</category>
    </item>
    <item>
      <title>Virtual Assistant using python</title>
      <dc:creator>VISHAK</dc:creator>
      <pubDate>Mon, 17 Jan 2022 18:33:42 +0000</pubDate>
      <link>https://dev.to/vishak369/virtual-assistant-using-python-2ldc</link>
      <guid>https://dev.to/vishak369/virtual-assistant-using-python-2ldc</guid>
      <description>&lt;h2&gt;
  
  
  Python for Artificial Intelligence !!
&lt;/h2&gt;

&lt;p&gt;Python modules plays a very important role in AI based solutions that defines a functions, classes, and variables. A module can also include runnable code. Grouping related code into a module makes the code easier to understand and use. It also makes the code logically organized.&lt;/p&gt;

&lt;p&gt;Used Modules;&lt;br&gt;
1) Speech recognition&lt;br&gt;&lt;br&gt;
2) pyttsx3&lt;br&gt;
3) pyaudio&lt;br&gt;
4) wikipedia&lt;br&gt;
5) datetime&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Speech recognition&lt;/strong&gt; &lt;br&gt;
It allows computers to understand human language. Speech recognition is a machine's ability to listen to spoken words and identify them. You can then use speech recognition in Python to convert the spoken words into text, make a query or give a reply.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pyttsx3&lt;/strong&gt;&lt;br&gt;
pyttsx3 is a text-to-speech conversion library in Python. it is a very easy to use tool which converts the entered text into speech.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pyaudio&lt;/strong&gt;&lt;br&gt;
PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library. With PyAudio, you can easily use Python to play and record audio on a variety of platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pywhatkit&lt;/strong&gt;&lt;br&gt;
Module used for playing songs from youtube.Function pywhatkit.playonyt(), opens the YouTube in your default browser and plays the video you mentioned in the function. If you pass the topic name as parameter, it plays the random video on that topic. On passing the URL of the video as the parameter, it open that exact video.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntax: pywhatkit.playonyt(“search name”)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;wikipedia&lt;/strong&gt;&lt;br&gt;
Wikipedia is a Python library that makes it easy to access and parse data from Wikipedia. All the datas from the wikipedia can be used here by text or by audio output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;datetime&lt;/strong&gt;&lt;br&gt;
Used to return current date, that can be using in many properties as a timestamp if needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import speech_recognition as sr
import pyttsx3
import pyaudio
import wikipedia
import pywhatkit
from datetime import datetime

now = datetime.now()
current_time = now.strftime("%H"  "%M")
cam = ["who", "when", "why", "what", "where"]


listener = sr.Recognizer()
on = pyttsx3.init()
newVoiceRate = 129
on.setProperty("rate", newVoiceRate)
voices = on.getProperty('voices')
on.setProperty('voice', voices[1].id)
on.say("hello vishak what can i do for you")
on.runAndWait()
def talk(lm):
    on.say(lm)
    on.runAndWait()
def take():
    try:
        with sr.Microphone() as source:
            print("listening...")
            voice = listener.listen(source)
            com = listener.recognize_google(voice)

    except:
        pass
    return com
def vk():
    command = take()
    if 'happy' in command:
        talk('yes iam happy')
    elif 'what is your name' in command:
        talk('my name is vk 3.7')
    elif 'who created you' in command:
        talk('vishak created me')

    elif 'play' in command:
        song = command.replace('play', '')
        talk('playing' + song)
        pywhatkit.playonyt(song)

    elif 'hai' in command:
        talk('hehehe')

    elif 'how are you' in command:
        talk('iam fine thank you')
    elif 'what is' in command:
        dd = command.replace('what is', '')
        woc = wikipedia.summary(dd, 1)
        talk(woc)

    elif 'time' in command:
        time = datetime.now().strftime('%I:%M %p')
        talk('the time is' + time)
    elif 'can you talk faster' in command:
        new = 180
        on.setProperty("rate", new)
        talk('yes i can talk faster is this fast ok for you vishak')

    elif 'can you speak other languages' in command:
        talk('sorry i dont know other languages,but i can learn')

    elif 'get' in command:
        nic = command.replace('what is', '')
        wac = wikipedia.summary(nic, 1)
        talk(wac)
    elif 'can you change your voice' in command:
        voices = on.getProperty('voices')
        on.setProperty('voice', voices[0].id)
        talk('okay,what about my new voice')
    elif 'wow cool' in command:
        talk('thank you')


    elif 'then tell me something' in command:
        talk('can you please me more romantic vishak,it will be better')



    elif 'who is ' in command:
        who = command.replace('who is', '')
        ohw = wikipedia.summary(who, 1)
        talk(ohw)


while True: vk()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can edit the elif function and add appropriate &lt;strong&gt;text&lt;/strong&gt; as needed(question) and put down the reply in the &lt;strong&gt;talk&lt;/strong&gt; block.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create your own piece of code!&lt;br&gt;
Enjoy &amp;lt;3&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>bot</category>
    </item>
  </channel>
</rss>
