<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexander Popov on Medium]]></title>
        <description><![CDATA[Stories by Alexander Popov on Medium]]></description>
        <link>https://medium.com/@alexppv?source=rss-d2be9e0bdea9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8jKVEDvNs5I2o7M-T5uS_g.jpeg</url>
            <title>Stories by Alexander Popov on Medium</title>
            <link>https://medium.com/@alexppv?source=rss-d2be9e0bdea9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:50:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexppv/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Working with large datasets: An Introduction to SQL.]]></title>
            <link>https://medium.com/analytics-vidhya/working-with-large-datasets-an-introduction-to-sql-fcf8ab9cadc8?source=rss-d2be9e0bdea9------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcf8ab9cadc8</guid>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Alexander Popov]]></dc:creator>
            <pubDate>Sun, 02 May 2021 16:51:58 GMT</pubDate>
            <atom:updated>2021-05-02T16:51:58.156Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hNx1mNTcl3XenYwk" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=medium&amp;utm_medium=referral">Caspar Camille Rubin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>SQL</strong> Structured Query Language: the language to access databases and manipulate data. We will talk about how SQL works and how we can get started quickly with our first querys in this article. But first:</p><p><strong>What is SQL?<br></strong>SQL is the standard programming language for relational databases and to be precise not just one because there are several different versions of SQL languages. However, the main syntax is the same and it is useful to know it.</p><p>In 1969, an IBM employee Edgar F. Codd defined the relational database model, which became the foundation for the well-known programming language developed several years later. SQL is used to manage data, especially data from relational databases, which consist of several tables linked together. SQL is designed to work with very large amounts of data than is common with Excel, and can handle these amounts of data very well. For example, all the data that a project has ever collected can be stored and used for specific searches in the future within the database. But also for pretty much all searches on web pages and in programs offered to a user are made possible in the background using SQL.</p><p><strong>How do we get started?<br></strong>First of all, it is worth mentioning that SQL is an uncomplicated language and therefore faster to learn than Java or PHP. Probably the most popular variant, which is also open-source, is Oracle’s MySQL. To get an understanding: a relational database describes several tables in a database, which are connected by certain IDs. SQL keywords can be written in upper and lower case, but they are always written in upper case for homogeneity and overview by users.</p><p>When and how SQL is used — a practical example:</p><p>1. Identify the task: Certain information is needed, which is in a database full of all available information. This big dataset has now to be filtered to get the needed results. Real-world example: A company wants to see only the sales figures in a certain time interval, with sales in a certain country and from customers who see ar of a certain age, in order to recognize at what time most purchases are made by this clientele and to optimize sales for these customers.<br>2. Perform Query: Writing a SQL query — what data should be taken from the database and what parts of it should be filtered afterward?<br>3. Analyse Results: We get a list or table of results, which we can then present as a chart to justify a change in e.g. marketing strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WcuKpON7yDFHXbKZ" /><figcaption>Photo by <a href="https://unsplash.com/@m_b_m?utm_source=medium&amp;utm_medium=referral">M. B. M.</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>How do we write an SQL query?</strong> In the following section, I will introduce the tools for this (the main SQL commands) and show examples to illustrate. Some general commands and their functions:</p><p>SELECT — lets us pull data from a database<br>CREATE DATABASE — creates a new database<br>ALTER DATABASE — modify an existing database<br>DROP TABLE — deletes a table<br>UPDATE — updates data in the database<br>DELETE — deletes data from its database<br>INSERT INTO — inserts new data into a database</p><p><strong>Basics to start with:</strong></p><ol><li><strong>SELECT</strong></li></ol><p>To display all data from a table we use</p><pre>SELECT *FROM your_table</pre><p>SELECT is used to extract the data from the table<br>The “*” stands for “everything”, which means you want to output everything inside of this table. It can be used universally. If we want to output all data starting with “A00” we write “A00*”. FROM refers to where we are extracting the data from.</p><p>Usually we don’t want to have the whole table, but only a part of it. For this we can just pick the parts we need. As an example:</p><pre>SELECT Name, Country FROM Your_Table;</pre><p>Now we get only the names and countries from the table “Your_Table”.</p><p><strong>2. DISTINCT</strong></p><p>DISTINCT is used to check certain columns for redundancies and remove them. To execute such a function we have to select the column that should be checked for redundancies. The result looks like this:</p><pre>SELECT DISTINCT columnX FROM tableY;</pre><p>As a result, we get the contents of the selected columnX without repeating values.</p><p><strong>3. WHERE</strong></p><p>This command can be used to filter results from an SQL query according to certain criteria.</p><pre>SELECT columnX FROM tableY WHERE columnX = specific value;</pre><p>Thus, with WHERE we specify which condition has to be fulfilled, to gain the needed result. In this case, the value in columnX has to have exactly the specific value. Besides the “=”, the operators greater than (&gt;), less than (&lt;), greater than or equal to (&gt;=), less than or equal to (&lt;=), or not equal to (&lt;&gt;) can also be used. An example of such a query could be, for example, filtering by sales figures:</p><pre>SELECT Price FROM Sales Where Price &gt; 2000</pre><p><strong>4. AND &amp; OR</strong></p><p>These operators are used in the SQL-WHERE conditions to include or exclude certain results. They are used as follows:</p><pre>SELECT columnX<br>FROM table<br>Where columnname1 = value 1<br>AND columnname2 = value 2</pre><p>Now both criteria must be fulfilled. Alternatively, the AND can be replaced with an OR. In this case, only one of these two specified criteria would have to be met. To clarify the functionality a bit, here is an example with the table I named “SalaryInfo”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7F_oiF7B7IOipaiJ50h5g.png" /><figcaption>Table “SalaryInfo”</figcaption></figure><p>With the following query:</p><pre>SELECT Name, Salary, Age, Gender<br>FROM SalaryInfo<br>WHERE Salary &gt; 50000<br>AND GENDER = ‘f’</pre><p>gets us the correct result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NIo1sz9ZGx0O1GCuPtgYrw.png" /><figcaption>Result for: Salary higher than 50.000 and female</figcaption></figure><p><strong>5.</strong> <strong>BETWEEN</strong></p><p>To withdraw only the data in one area, we can use BETWEEN.</p><pre>SELECT columnX<br>FROM tableX<br>WHERE columnX<br>BETWEEN ‚1‘ AND ‚100‘</pre><p>This gives us only the values from the range between 1 and 100.</p><p>Do you want to dive deeper into the matter and execute more complex queries? For this, I can recommend <a href="https://www.w3schools.com/sql/">w3schools</a> and their great tutorials.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcf8ab9cadc8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/working-with-large-datasets-an-introduction-to-sql-fcf8ab9cadc8">Working with large datasets: An Introduction to SQL.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automation testing, scraping and more with Selenium and Python.]]></title>
            <link>https://medium.com/analytics-vidhya/automation-testing-scraping-and-more-with-selenium-and-python-9247278b00d2?source=rss-d2be9e0bdea9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9247278b00d2</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[automatisation]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[selenium]]></category>
            <dc:creator><![CDATA[Alexander Popov]]></dc:creator>
            <pubDate>Wed, 31 Mar 2021 16:27:30 GMT</pubDate>
            <atom:updated>2021-03-31T16:27:30.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0JURFS_NOjP-6Pzl" /><figcaption>Photo by <a href="https://unsplash.com/@kevnbhagat?utm_source=medium&amp;utm_medium=referral">Kevin Bhagat</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Selenium — once started as a browser extension and is now one of the most popular frameworks for testing web-based applications. In this article, you’ll learn what Selenium is, how to use it, and how to get started with your first steps.</h3><p><strong>Selenium Basics<br></strong>Selenium is an open-source framework and consists of the components:</p><p>1. Selenium Webdriver: the main component that automatically performs the user’s actions in the browser.</p><p>2. Selenium Grid: the component that allows multiple instances to run simultaneously — on multiple devices, operating systems, and browsers. This makes it possible to run test results on as many platforms as possible, which is a prerequisite for successful automation testing.</p><p>3. Selenium IDE: records and repeats actions of the user in the browser.</p><p>The Webdriver communicates with the browser via a browser-specific driver, which also sends HTTP responses to the Webdriver in the opposite direction. This simple structure, coupled with an open architecture and the possibility of working cross-platform and cross-language, attracts many users and developers and enables extensions to be built in.</p><p><strong>Let’s get started!<br></strong>First of all, the setup: We need Selenium — which we can download and install in the terminal with“-m pip install selenium”. Next, we need the already mentioned webdriver. I use Google Chrome for this project and you can find the Chrome webdriver <a href="https://chromedriver.chromium.org/downloads">here</a>. We start a new Python project — and import Selenium with the first lines of code, select the webdriver.Chrome and give the path where the chromedriver is located.</p><pre>from selenium import webdriver<br>driver = webdriver.Chrome(‘/Users/NAME/Desktop/chromedriver’)<br></pre><p>Here you can already test if everything was imported correctly: Running the code should open a new Chrome window with the message: “Chrome is being controlled by automated test software”.</p><p>To get a first understanding of how Selenium works and to start learning the syntax — let’s start with a very simple example. To call a page, we use “<em>get</em>” on the “driver” we just defined to open the desired URL:</p><pre>driver.get(‘<a href="https://www.google.com/xhtml&#39;">https://www.google.com/xhtml&#39;</a>)</pre><p>To do an automated Google search we have to find the elements needed to perform a search. To find it out which elements we need, we have to go to “View Page Source” with a right-click on the site (using Chrome browser) to see the HTML-Code. How HTML codes are built and how to navigate here, I have described in a previous article using a scraping example with BeautifulSoup.</p><p><a href="https://medium.com/analytics-vidhya/how-to-find-a-car-under-market-value-with-python-beautifulsoup-and-your-own-telegram-bot-c9d91e23c0d1">https://medium.com/analytics-vidhya/how-to-find-a-car-under-market-value-with-python-beautifulsoup-and-your-own-telegram-bot-c9d91e23c0d1</a></p><p>To implement the elements we need in our code we will use the function: “<em>find_element_by_name</em>” to use the elements on the page by name. Side info: We are using “google.com/xhtml” so we can better read the HTML code of google. A short search shows us that the name of the search bar element is simply “q”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*25oFiHLyoP-x_51R36bvQg.png" /><figcaption>Search Bar HTML</figcaption></figure><p>Now we go to the element via “<em>find_element_by_name</em>” and let enter the desired text with “<em>send_keys</em>”.</p><pre>search=driver.find_element_by_name(‘q’)<br>search.send_keys(‘Our First Google Search’)</pre><p>To make our automation more “human” we add wait times between commands. For this we first have to import “time” and set a pause of e.g. 4 seconds after calling the web page by entering the following:</p><pre>time.sleep(4)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*iWyVmlu_sC89fqWHCK72aA.png" /><figcaption>Our first google search is starting</figcaption></figure><p>The last part we have to add to our code is submitting the search with:</p><pre>search.submit()</pre><p>This line is simulating a smash of the enter-button which brings us to the search results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tnv31pfITcVLv0T1VfGoeA.png" /><figcaption>First successful automated google search</figcaption></figure><p>To end a session (caution: the window closes immediately, so include a sleep time to see the result before the window disappears) we use the quit function:</p><pre>driver.quit()</pre><p>There are, of course, a variety of other ways we could select the required element in the code — <em>“find_element_by_name”</em> is just one option. Other common possibilities are: <em>“find_element_by_id”</em>, <em>“find_element_by_xpath”</em> <em>“find_element_by_class_name”</em> and others. A detailed selenium-documentation can be found <a href="https://selenium-python.readthedocs.io/">here</a>.</p><p>With these tools, all elements can be found in the HTML code, incorporated as an element in the Python code, and used variably to create an automated flow. Similarly, one can automatically log in to web pages by selecting and filling in the individual elements. For example, using the website Facebook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*GnVz7BbURbC2CAZqhcGBvQ.png" /><figcaption>Facebook HTML — Where to put my E-Mail?</figcaption></figure><p>A quick search on the front page reveals that the email is hidden under id=”email” and the password under “pass”. All you have to do is “<em>send_keys</em>” to those and once again perform “enter” by submitting.</p><p>I would like to end this article with more useful functions that can be used in creative ways to customize your individual automation process:</p><ul><li>“<em>getCurrentUrl()</em>” — gets the current URL as a string, which can be useful when you’re traveling through website and want to crawl them</li><li>“<em>getText()</em>” — gets the inner text of a web element you pick — great for automated crawling of strings and characters</li><li>“<em>implicitlyWait()</em>” — sometimes the webpage needs some time to load and your driver tries to find an element, that is not loaded yet. implicitlyWait will pause the action for the number of seconds you type in.</li><li>“<em>visibilityOfElementLocated()</em>” paired with “untill()” — pretty much does the same, but will not wait for X seconds, but will wait for a certain element to become visible. For example: wait.until(SomethingWeAreWaitingFor.sivibilityOfElementLocated). This becomes handy when the loading time is long and you don’t know how much waiting time to set.</li><li>“getScreenshotAs()” — will take a screenshot at this moment, which can be used for control later on. Don’t forget to set a filename and a format in the brackets.</li></ul><p>With all these functions you can build a program that can: automatically navigate through web pages, check web-app-functions and extract and save information to detect errors and improve performance.</p><p>As always: Thank for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9247278b00d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/automation-testing-scraping-and-more-with-selenium-and-python-9247278b00d2">Automation testing, scraping and more with Selenium and Python.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to solve data tasks quickly — An introduction to Pandas]]></title>
            <link>https://medium.com/analytics-vidhya/how-to-solve-data-tasks-quickly-an-introduction-to-pandas-a5838c219484?source=rss-d2be9e0bdea9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5838c219484</guid>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[cheatsheet]]></category>
            <dc:creator><![CDATA[Alexander Popov]]></dc:creator>
            <pubDate>Mon, 01 Mar 2021 15:37:36 GMT</pubDate>
            <atom:updated>2021-03-01T15:37:36.572Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to solve data tasks quickly — An introduction to Pandas</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oGMrAoXBGPEx7vhX" /><figcaption>Photo by <a href="https://unsplash.com/@lukechesser?utm_source=medium&amp;utm_medium=referral">Luke Chesser</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the most important tools for Data Science: Pandas — learn the most used functions in a short time and how to get results quickly. You start with a large data set: how can you read it, clean it, and evaluate it properly? I’ll show you the most important functions for this.</p><p><strong>But first: What is Pandas and when is it used?<br></strong>Pandas is an open-source analysis and manipulation tool built on Python. It was built to enable practical, real-world data analysis in Python. The advantages are its flexibility and ease of use. In this article, I will show the common steps while working on tasks with big datasets, most important features and explain how they are used to get started with your first projects.</p><p><strong>Basics of Pandas:<br></strong>Mainly there are two types of objects used in Pandas:<br>1. <strong>DataFrame</strong>: A table with an array of independent entries. These can be integers or strings. Pandas can thus be used universally for a wide variety of tasks. To create a DataFrame object, we use the function: pd.DataFrame()<br>2. <strong>Series</strong>: A series, on the other hand, is not a table but a list and can be created directly from a simple list.</p><p><strong>Example of creating a DataFrame:</strong></p><p>First of all, we have to import pandas:</p><pre>import pandas as pd<br>from pandas import DataFrame</pre><p>Creating a DataFrame with some random values:</p><pre>df = DataFrame({&#39;ImportantValues&#39;:[5,6,7],&#39;EvenMoreImportantValues&#39;:[1,2,3]})</pre><p>An enumeration (starting from 0) is automatically generated and shown on the left side. With print(df) we can see the output of our Dataframe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*16zdxdGD-FH1Kmt0DaUEMg.png" /><figcaption>DataFrame Output</figcaption></figure><p>It’s good to know how the basics work, however, for future projects we won’t be entering the data by hand, but rather pulling it from sources and importing it. For the import we use the function that reads CSV(comma separated values) files with: pd.read_csv(). For this article, I will use a random dataset as an example. Here I’m using the <a href="https://www.kaggle.com/aungpyaeap/supermarket-sales">supermarket dataset </a>from Kaggle and rename it to a shorter filename “super”.</p><pre>supermarkt_data = pd.read_csv(&quot;../path_to_file/super.csv&quot;)</pre><p><strong>Handling: We have imported tables— what’s next? <br></strong>Since the datasets we will be working with are very large — it will be confusing to output them as a whole. In order to make working with large datasets as efficient as possible, we use some functions to get an overview of the data and go into more detail on certain areas. To get a short insight into the data, we can use the following function, which gives us the first 5 entries:</p><pre>print(supermarkt_data.head())</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chhJooa2xShr7f9aLGQC5Q.png" /><figcaption>Head Of Supermarkt.csv</figcaption></figure><p>To output a specific value from a table (and in this example only the first value of it) the following function can be called:</p><pre>your_dataframe[&#39;TheColumnYouLikeToSee&#39;][0]</pre><p><strong>Useful functions:</strong></p><p>If we want to create a single table from several tables (e.g. numbers for each year from different CSV files into a total table) we can solve this with a simple loop:</p><pre>for file in files:<br>       df = pd.read_csv(&#39;./PATH!&#39;+file)<br>       all_data = pd.concat([all])</pre><p>Now to save this new table as a new CSV we simply run the lines:</p><pre>all_data.to_csv(&quot;all_data.csv&quot;, index=false)</pre><p>The last part “index=false” disables the automatic left column, which only contains an enumeration.</p><p><strong>Data</strong> <strong>Cleaning</strong><br>One of the most important tasks in data science projects is data cleaning. This can be a big part of the project and is essential for a good result. The result can only be as good as your input. It is not uncommon for data sets to be re-cleaned multiple times during a project after analysis, as many errors in the data sets can be detected from these results. A machine learning algorithm, for example, can only be as good as the data fed to it. The first thing you check for data cleaning: Are there any blanks or NaN (NotANumber) entries? For this, we use: “dataframe.isna()”.</p><pre>NaN_df = your_data[your_data.isna().any(axis=1)]</pre><pre>#check the results by running following line<br>NaN_df.head()</pre><p>So if we have NaN-Values — the easiest method to get rid of them is by doing following:</p><pre>our_data = our_data.dropna(how=&#39;all&#39;)</pre><p>Sidenote:</p><p>axis = 0 drop rows which contain missing values.</p><p>axis = 1 drops columns that contain missing values</p><p>More information about dataframe.isna() and dataframe(dropna) can be found <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html">here</a> and <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.isna.html">here</a>.</p><p><strong>Analysis— Extract Information from large datasets</strong><br>Since it is hard to read and analyze large data sets, we use functions that summarize information for us. The best example of this is the total amount of revenue from a month of sales data. In order to give information about sales, losses, developments, we can sort the dataframe by certain series (e.g. year) and draw the sum from it.</p><pre>supermarkt_data.groupby(‘gross income’).sum()</pre><p>This gives us an overview of the totals for all years and we may be able to identify and graph initial trends, spot outliers and perform interpretations.</p><p><strong>Filtering Data</strong></p><p>It often happens that you need to filter information: In our case, for example, it could be the supermarket location (city), sales figures of a certain product, or time of purchase. As an example, I show how to filter the DataFrame by cities. For this, I have chosen the city ‘Yangon’.</p><p>To create a new DataFrame that contains only the information that is relevant for us, we can use the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html">DataFrame.loc function</a>.</p><pre>new_df = our_data.loc[(our_data[&#39;City&#39;] == &#39;Yangon&#39;)]</pre><p>When we print the result of the new DataFrame out, we can make sure that the filtering worked:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07xrC28_pH_OSgE20fS58A.png" /><figcaption>Filtering by City with df.loc</figcaption></figure><p>The loc function is not limited to one characteristic. So several ‘and’ and ‘or’ functions can be used and also limits, like price &gt; X, can be adjusted individually. As an example, here is a function that filters by the city of Yangon, a gross income for purchases above 10, and a product rating above 9.</p><pre>new_df = our_data.loc[(our_data[&#39;City&#39;] == &#39;Yangon&#39;) &amp; (our_data[&#39;gross income&#39;] &gt; 10) &amp; (our_data[&#39;Rating&#39;] &gt; 9)]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhzrCSvPwu3QYFzV6dMddw.png" /><figcaption>Filtering by City, gross income and rating</figcaption></figure><p>With the functions presented here, you can import CSV-files, read them, output specific values, merge multiple tables and export new ones, find and remove unfilled entries to clean your dataset, automatically calculate totals, and create new DataFrames with specific filter criteria. With these tools you can read, interpret, and target large data sets to get meaningful information.</p><p>As always: Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5838c219484" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/how-to-solve-data-tasks-quickly-an-introduction-to-pandas-a5838c219484">How to solve data tasks quickly — An introduction to Pandas</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make your own fully customizable Audio-Assistant with Python and Amazon Polly]]></title>
            <link>https://medium.com/analytics-vidhya/how-to-make-your-own-fully-customizable-audio-assistant-with-python-and-amazon-polly-def49074d5e9?source=rss-d2be9e0bdea9------2</link>
            <guid isPermaLink="false">https://medium.com/p/def49074d5e9</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scraper]]></category>
            <category><![CDATA[news]]></category>
            <category><![CDATA[polly]]></category>
            <dc:creator><![CDATA[Alexander Popov]]></dc:creator>
            <pubDate>Fri, 25 Dec 2020 21:36:45 GMT</pubDate>
            <atom:updated>2020-12-27T12:38:38.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TgLr2AWjvJjFQqX2" /><figcaption>Photo by <a href="https://unsplash.com/@markuswinkler?utm_source=medium&amp;utm_medium=referral">Markus Winkler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>You’re driving from one important appointment to another (in the current situation, you’re probably more likely to jump into online conferences), you need to find time for work, sports, and your social contacts — your time is limited and valuable. Ideally, you’d like the news and figures that are relevant to you and your business to be automatically collected and read to you in a short audio message between appointments: Customized, filtered news — daily.</p><p>In this article, we will try to solve this problem using Python, web scraping, simple mathematical equations, and Amazon Polly. The result should be a fully automated assistant that prepares and reads out a daily report at a specified time every day.</p><p><em>As always, my articles aim to teach you the basics of the tools used in the project and give you a sense of how to solve problems creatively using current technologies.</em></p><h4>Where do we start? What do we need?</h4><p>The project is divided into the following work packages:</p><p>1. <strong>Planning</strong> — What do I want to hear in my daily report? Where can I get the information I need for this?</p><p>2. <strong>Code</strong> — Writing a program that obtains the needed information, does some simple functions, and packages the information into a text message.</p><p>3. <strong>Amazon Web Services (AWS) — Amazon Polly</strong> — Creating an AWS account, performing settings, including Polly in our code, and performing neural text-to-speech (NTTS) with our text.</p><h4>1. What is the content and where do we get it?</h4><p>Within this project, I set myself the goal of obtaining the following information:</p><ul><li>Date and weather forecast for today.</li><li>The current price of Bitcoin and IOTA</li><li>The ratio of the current price for Bitcoin to a certain purchase value</li><li>A calculated prediction of how the price development will possibly go. (Since this part will be very extensive, I will refer to it in the next article “Audio Assistant Part 2”).</li><li>Performance of certain stocks</li><li>A random quote from a personally selected list</li></ul><p><em>Of course, you can customize the news however you like and add any information you can scrape from the web using the same techniques.</em></p><p>Most of the information can be found on the internet and scraped using BeautifulSoup. To do this, we need to find the web pages that contain the needed information and fight our way through the HTML jungle to find the container we want. I won’t go into this in detail so as not to go beyond the scope of this article. However, if you’re not familiar with scraping or Beautifulsoup please check out my last article:</p><p><a href="https://medium.com/analytics-vidhya/how-to-find-a-car-under-market-value-with-python-beautifulsoup-and-your-own-telegram-bot-c9d91e23c0d1">How to find a car under market value — with Python, BeautifulSoup, and your own Telegram Bot.</a></p><p>Here I explain the fundamental basics of scraping by showing an example of how to pull the information you are looking for, process it, and set up a Telegram bot to send automatic alarm-messages.</p><p>For this project, we will pull Bitcoin and IOTA prices using the website coindesk. Since it is only one value at a time, the search is relatively simple. Looking up the HTML-Code we can see that the current value is in the div container “price-large” with a span tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQx_4gH2bxYXBiaBT-NOSA.png" /><figcaption>Bitcoin HTML-Container</figcaption></figure><p>For the weather, I use the website wetter.de. Again, it can be quickly found out that the div container “weather-daybox-minMax” contains two objects: The maximum temperature and minimum temperature for the current day. To get the current price of Tesla stock, I use the website marketwatch.</p><h4>2. Let’s start coding</h4><p>Our code mainly consists of cleaning the scraped data, doing some light calculations, creating a list of quotes, a random quote-output, and then saving all the information in one text. We then embed Amazon Polly and have her read out our text. First of all, we load the required libraries, we need. To use Amazon Polly we need to load the library Boto3 from the AWS services.</p><pre>import requests<br>from bs4 import BeautifulSoup<br>from requests import get<br>import pandas as pd<br>import decimal<br>import itertools<br>import schedule<br>import time<br>import random<br>from time import sleep<br>from datetime import datetime<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>from datetime import date<br>import boto3</pre><p>To clean the data (temperature, bitcoin, IOTA, stock price), we again use the join, isdigit and filter functions. Then we convert the objects into integers. With this, the raw data is ready to use.</p><pre>price = &#39;&#39;.join(filter(lambda i: i.isdigit(), price))<br>price = int(price)</pre><p><strong>Weather and date:</strong> To get the current date, we imported “date” from “datetime”. With the function date.today() we can get the current date. With the name %B we can get the month and with %d the number for the current day. This option makes the most sense in an Audio file. I have combined the information about temperature and date in one sentence:</p><pre>d = date.today()<br>date = d.strftime(&quot;%B %d&quot;)<br>print(&quot;date =&quot;, date)<br>dateweather = &quot;Hello Alexander, today is &quot; + date +&quot; and the maximum temperature is &quot;+ temperature +&quot;° celsius.&quot;</pre><p>The output looks like this:</p><pre>date = December 23<br>Hello Alexander, today is December 23 and the maximum temperature is 18° celsius.</pre><p><strong>Crypto: </strong>To give automated information on how much profit or loss we made we first enter a value “Bought” we (theoretically) bought the coins and perform some simple calculations. Let’s say we bought one Bitcoin for 17.000 USD and would like to know the profit/loss:</p><pre>CurrentStr = str(Current)<br>Bought=17000<br>BoughtStr = str(Bought)<br>Ratio = Bought/Current<br>Difference = Current-Bought<br>DifferenceStr = str(Difference)<br>IotaStr=str(IOTA_value)<br>if Difference &gt; 0:<br><br>    BitcoinText = &quot;The bitcoin price today is &quot; + CurrentStr + &quot;, which     means you have made a profit of &quot; + DifferenceStr<br>else:<br>    Difference = Bought-Current<br>    DifferenceStr = str(Difference)<br>    BitcoinText = &quot;The bitcoin price today is&quot; + CurrentStr + &quot;. As of today you have made a loss of &quot; + DifferenceStr<br><br>IOTA_Text = &quot;The current price for IOTA is &quot; + IotaStr + &quot;dollars.&quot;<br>crypto = BitcoinText + IOTA_Text</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ysC1Q_1djY9fSD83" /><figcaption>Photo by <a href="https://unsplash.com/@gillyberlin?utm_source=medium&amp;utm_medium=referral">Gilly</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Quotes:</strong> Now we create a list of interesting quotes and have a random quote from the list sent to us every day. Creating a list:</p><pre>quote_list =[&quot;InsertQuote1Here&quot;,&quot;InsertQuote2Here&quot;,&quot;InsertQuote3Here&quot;]<br>#insert as many quotes in the list as you like</pre><p>I have collected ten quotes for this and put them on this list. To get a random quote we can use the random.choice function. For this, we have imported the library ‘Random’ at the beginning.</p><pre>random_quote = random.choice(quote_list)</pre><p><strong>Putting all parts together:</strong></p><pre>finaltext = dateweather + crypto + stock + random_quote</pre><h4>3. Text to Speech</h4><p>Now comes the fun part. We bring our text to life with the help of neural text to speech voices. Amazon Polly supports certain SSML tags to allow for more precise settings in the text. There are a number of tags for this purpose. An overview of them can be found <a href="https://docs.aws.amazon.com/de_de/polly/latest/dg/supportedtags.html">here</a>.</p><p>For this short message, we can use the tags &lt;break&gt; and &lt;p&gt; to add logical breaks between messages. However, there are also many interesting tags, such as speaking softly or whispering &lt;amazon:effect name=”whispered”&gt;. Another interesting function is the emphasis, when a certain word should be emphasized — using the tag <em>&lt;emphasis&gt;.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DAkaSdcsGJy_cY9hPM0Vwg.png" /><figcaption>Overview of some SSML-Tags</figcaption></figure><p>To get Polly up and running, we first need to create a free AWS Amazon account. This includes many free features and limited usage for many services. Amazon Polly costs per character: For the standard TTS version, you pay $4 for 1 million characters (approximately 23 hours of audio), and for the neural TTS version (which sounds less robotic) you pay $16 for 1 million characters. However, the first 12 months are completely free up to a quota of 1 million characters.</p><p>After we have created an AWS account we need to create our AWS credentials. To do this, we go to “IAM” in AWS Services. In the “User” tab we can create a new user. In the next steps of the creation, we give it “Programmatic Access” and assign the required permissions. To do this, we go to “Attach existing policies directly” and select “AmazonPollyFullAccess”. Once the user is created, it is important to save the “Access Key ID” and the “Secret access key”, as we will need them right away for the setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPI0OaslbiPeDpAmIgftEg.png" /><figcaption>Giving full Polly Access permission for this user</figcaption></figure><p>Next, we install Amazon CLI — this is a tool that serves as an interface for the AWS command lines. You can download CLI <a href="https://aws.amazon.com/de/cli/">here</a>. Once installed, we can enter our user by entering the command: “aws configure” via Command Promt or Terminal. Here we enter the AWS Acess Key ID we just created and the AWS Secret Access Key, select a region (e.g. us-east-2). <em>Sidenote: You can use the command “aws help” to display a help page.</em></p><p>This completes the settings and we can continue with the code. In the beginning, we have already imported the library Boto3 to use the service. Now we just have to enter what service we would like to use, our input text, output format, the voice we picked and whether we want to use the standard or neural version. The last part is saving the audiofile.</p><pre>polly = boto3.client(&#39;polly&#39;)<br>spoken_text = polly.synthesize_speech(Text=finaltext,<br>                                      OutputFormat=&#39;mp3&#39;,<br>                                      VoiceId=&#39;Joanna&#39;,<br>                                      Engine=&#39;neural&#39;)<br>with open(&#39;news2.mp3&#39;, &#39;wb&#39;) as daily:<br>    daily.write(spoken_text[&#39;AudioStream&#39;].read())<br>    daily.close()</pre><p>When we run the program, all the data will be collected, prepared and the audio file will be created. What you do with the file now is up to you. You can just play it at home or on the way on your notebook or write some more lines of code to automatically send the audio file to you via a Telegram Bot.</p><p>I’ve uploaded the final result of today&#39;s news on soundcloud:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F953643142%26show_artwork%3Dtrue&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fuser-474416677%2Fautomated-news-python-polly&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b8919ba5eaaa54dfa6b372f28babfcf/href">https://medium.com/media/2b8919ba5eaaa54dfa6b372f28babfcf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def49074d5e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/how-to-make-your-own-fully-customizable-audio-assistant-with-python-and-amazon-polly-def49074d5e9">How to make your own fully customizable Audio-Assistant with Python and Amazon Polly</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to find a car under market value — with Python, BeautifulSoup, and your own Telegram Bot.]]></title>
            <link>https://medium.com/analytics-vidhya/how-to-find-a-car-under-market-value-with-python-beautifulsoup-and-your-own-telegram-bot-c9d91e23c0d1?source=rss-d2be9e0bdea9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9d91e23c0d1</guid>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[telegram]]></category>
            <dc:creator><![CDATA[Alexander Popov]]></dc:creator>
            <pubDate>Sat, 12 Dec 2020 17:29:05 GMT</pubDate>
            <atom:updated>2020-12-21T20:03:54.737Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to find a car under market value — with Python, BeautifulSoup, and your own Telegram Bot.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*klbDSi1hpaJDQHtx" /><figcaption>Photo by <a href="https://unsplash.com/@cbowers?utm_source=medium&amp;utm_medium=referral">Cam Bowers</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Buying a car is an investment that should be done thoughtfully. But how do you find a good offer when you are competing with other buyers and car dealers who may have more experience and time than you? The really good offers are usually online for a very short time because the seller receives too many calls — so it is important to be one of the first callers. I would like to show you how to solve this problem with Python, BeautifulSoup, and your own Telegram Bot. At the end of this project, we will have a running program that:</p><p><strong>1. Scrapes the results of one of the biggest used car portals in Germany</strong></p><p><strong>2. Automatically notifies you about a good offer</strong></p><p>This project is designed to teach the basics of scraping web data with Python and BeautifulSoup using a practical example and show you how Data Science can be used to solve individual everyday problems.</p><p>If you want to build this project, please make sure that the website you are working with allows scraping! You can find out if this is allowed by appending “/robots.txt” to the domain of the page. The following project is for demonstration purposes only.</p><h3>Let&#39;s get started!</h3><p>For this project, I will scrape from a german used car website. The site has a large database and many users. To specify my search I will first select a car model that I want to track to narrow down the search. For this, I have chosen the Bentley Continental GT with the first registration from 2010 and maximum mileage of 100,000 km.</p><h4><strong>How does the web scraping work and where do we start?</strong></h4><p>Scraping means getting all the information from a specific website. We can scrape the whole HTML-Code from a page, filter it with our code to get clean data, and draw conclusions easier and faster.</p><p>First of all, we have to find out our target URL, which in this case already contains a predefined search. To do this, we perform one search manually. That means we have to fill in the search mask on the site, execute the search, set the sorting to “price ascending” and then copy the URL from the browser. The filter function offers a large number of settings, but now we have to choose wisely which ones are useful for deciding quickly: Is this a good or a bad car offer? We don’t want to filter away a good offer. I decided to use only three filter settings for this search: Company name and Car model, First registration (year), and mileage. With this search, we get an overview of the latest cars published.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqAY87naOra0c6PEm2WYVQ.png" /></figure><p>Now comes the most exciting part: how do we now find the best possible offer fully automatically? To do this, we first define what makes a good offer. After short research about the market price of such a car, I found out that the cheapest offers in Germany are around 60.000–70.000 Euro and can be considered as relatively cheap. I decided to stick with a 65.000 Euro limit. So we want our program to inform us when a car is advertised on exactly this URL with a price below 65.000 Euro. First of all, we will implement the URL we got through the manual search in our code to get the filtering automatically as we run the code.</p><p>One of our main tasks is to find out where exactly the information about the price for every car is located in the <strong>HTML</strong> code of this website. And for this, we will use <strong>BeautifulSoup</strong>. To get started we first need to insert the libraries needed for our project and define a header. A header allows us to make it look like we are accessing this page from a browser. Using web pages too much can cause you to get temporarily blocked. For this reason, you should take it easy.</p><pre>import requests<br>from bs4 import BeautifulSoup<br>from requests import get<br>import pandas as pd<br>import itertools<br>import schedule<br>import time<br>import random<br>from time import sleep<br>from datetime import datetime<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>sns.set()<br><br>headers = ({&#39;User-Agent&#39;:<br>                &#39;Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36&#39;})</pre><h4>Handling HTML-Code</h4><p>Before we start with the main part of the code, we should first find out where exactly in the HTML-Code the information about the price is stored. This is where the detective work begins and the tool I use for this is in the Chrome browser (Right-click -&gt; “View Source Code”). To make the search easier I right-click on the field where the price for a car is located and click on “Inspect”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsLF9snY4JRDDMfgYkd1_A.png" /><figcaption>Right-click on the price — Inspect (Turns yellow)</figcaption></figure><p>Now a window with the HTML code opens, in which the element I selected has already been marked. As we can see, the text information 61.899,- is located right here with a span-tag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*X8meWJnnCHmW5YpUXyqx2A.png" /><figcaption>Finding the target information in HTML-jungle</figcaption></figure><p>We can see that we still need to clean up the price to continue working with it as a number. All characters (“€”,” —” and so on) have to be cleaned up in the code. We will soon take care of this part, but first, we will take care of correctly extracting the price information.</p><p>Now we know the price is located somewhere with a span-tag. Since we want to pull the price of each car, we still need to find out under which tag we can find the main-container for every car. By climbing up the HTML tree we can find out the container for a car. For this step, it is useful to put the web page and the HTML code side by side and move the mouse cursor over the code. The browser will then — depending on which line of code the mouse pointer is in — display the corresponding field in your browser in blue. This makes it easy to find out where the main container is. In this case, it is the marked div-container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OopX_kw_UgEc6wSz4ZHuXg.png" /><figcaption>Finding the Main-Container for a single car</figcaption></figure><p>If we click through the div-container, we see that all the information we get to see on the website is stored right in here. All of the subheadings are also tagged with div and span. Our next task now is to call the correct main container in our code and correctly indicate where exactly and under which tag the price information is located.</p><h4>Main Part of the Code</h4><p>Now to start with the main part of the code, we define the target URL for our code and run BeautifulSoup.</p><pre>cars_url = &#39;https://www.HERE-GOES-YOUR-TARGET-URL!!&#39;</pre><pre>r = get(cars_url, headers=headers)</pre><pre>page_html = BeautifulSoup(r.text, &#39;html.parser&#39;)</pre><p>The next task is to find the exact location of the price. For this research we will take only the first car on the page, let the program search all entries with ‘span’-tag, and show the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1fnnTqR0qVRPqN31b52zA.png" /><figcaption>Searching for the right location</figcaption></figure><p>Running the code gives us the following information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*KuVVyUB0OP3FqqftTwWZQQ.png" /><figcaption>Results of running the code</figcaption></figure><p>As we can see the information we are looking for is in the 3rd span-tagged container. It is important to note that Python starts counting at 0. So the first result can be called via [0], the second via [1], and so on. This means we can call the price with [2]. Now that we know the exact position of the information, we can take care of cleaning the data.</p><h4>Cleaning!</h4><p>The cleaning can be done with different approaches. To make the project as beginner-friendly as possible I have written out two options. In the first option, we look at which characters have to be removed to get the digit-number we are looking for. In this case: the euro sign, hyphen, dot, comma, and the space character. Manually we can remove them as follows (single characters written out in a separate line):</p><pre>price=firstcar.find_all(&#39;span&#39;)[2].text<br>print(&quot;price before replacing characters:&quot; + price)<br>price = price.replace(&#39;.&#39;, &#39;&#39;)<br>price = price.replace(&#39;€&#39;, &#39;&#39;)<br>price = price.replace(&#39;,&#39;, &#39;&#39;)<br>price = price.replace(&#39; &#39;, &#39;&#39;)<br>price = price.replace(&#39;-&#39;, &#39;&#39;)<br>print(&quot;price after replacing characters:&quot; + price)</pre><p>Alternatively, we can use the more complicated, but elegant solution: Putting together the “join()”, “isdigit()” and “filter()” functions in one line of code:</p><pre>price = &#39;&#39;.join(filter(lambda i: i.isdigit(), price))</pre><p>Both options will give us the same result:</p><pre>price before replacing characters:<br>€ 61.899,-</pre><pre>price after replacing characters: <br>61899</pre><p>Although we now have only numbers in “price”, this object is still a string. With (print(type(price)) we can check this at any time. We still need to convert this object to an integer to be able to perform the mathematical equation: price &lt; price limit.</p><pre>price = int(price)<br>print(type(price))</pre><p>For the completion of the code we are still missing the following items:</p><p><strong>1. Connecting and setting up a Telegram bot</strong></p><p><strong>2. An “if-query” if the price scraped is below a value we set as a limit</strong></p><p><strong>3. Setting up the program to repeat after a certain time interval</strong></p><h4><strong>Setting up your Telegram Bot</strong></h4><p>To create a bot we need to install Telegram (if it’s not already on your phone or computer) and use the BotFather: <a href="https://t.me/botfather">https://t.me/botfather</a></p><p>Via /start , /newbot we can create a bot and assign a name. In response, we will receive a link to our bot and a bot token that we need to implement in our code. Additionally, we need our private chat ID. To get this, use the bot via the link generated above, start it and send a message. Then open the following link in our browser:</p><p><a href="https://api.telegram.org/bot%3cyourtoken%3e/getUpdates">https://api.telegram.org/bot&lt;yourtoken&gt;/getUpdates</a></p><p>Replace &lt;your token&gt; with your bot token you just received and copy the number after “id”: this is your chat ID. To implement the Telegram Chat-Bot into Python you can use the following code:</p><pre>def telegram_bot_sendtext(bot_message):<br>    bot_token = &#39;Put your Token here!!&#39;<br>    bot_chatID = &#39;Put your Chat-ID here!!&#39;<br>    send_text = &#39;https://api.telegram.org/bot&#39; + bot_token + &#39;/sendMessage?chat_id=&#39; + bot_chatID + &#39;&amp;parse_mode=Markdown&amp;text=&#39; + bot_message<br>    response = requests.get(send_text)<br>    return response.json()</pre><pre>message = telegram_bot_sendtext(&#39;A new car has been found!&#39;)</pre><p>Don’t forget to insert your Token and Chat-ID. Also, you can customize your message in the last line.</p><p>Filtering out the prices above our limit can be done simply by running this if-query before sending a message.</p><pre>limit = 65000<br>if price&lt;limit:</pre><p>To process all cars on the first search page, and not only the first one, we have to add a loop at the beginning of our code:</p><pre>if car_containers != []:<br><br>    for container in car_containers:</pre><p>Because we would like to repeat the whole searching process automatically we have to define our main code as a function with</p><pre>def crawlcar():</pre><p>and set up schedule the function:</p><pre>schedule.every(X).seconds.do(crawcar)</pre><p>With this, the code will run again after X seconds.</p><p><strong>One thing we have not solved yet: How do we handle the alarm when the same car is ‘found again’ in the next run?</strong></p><p>Because our program finds the same car again and again it will send you an alarm every run. To avoid this problem we can set a list with certain characteristics. Since we are already dealing with the price we can use this attribute right away. We only need two lines of code that do the following: Store the current price for every scraped car in a list. Ask before starting the Telegram function: Is this price already on the list? If so, don’t send it out. This way we avoid the error of an alert being triggered for the same vehicle.</p><p>And with that, we are done and can run our program! A test result shows that the crawler is working: We receive the following message on Telegram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*UYrtGkAPyYcp8hUE8sb3fw.png" /><figcaption>First message!</figcaption></figure><p>Now at least we know that a car with our criteria has just been posted. However, to see the car or any other information, we have to go to the page manually and search for it (which is basically no problem). Nevertheless, we can customize our code and shorten this step by simply adding the link to the car. To do this, analogous to the price search, we search the HTML code for the container which holds the link to the car description, save it (just like we did with the price), and link it directly into our bot notification. Just like that, we can extract any information that is of interest to us, such as first registration and mileage. Extracting this data is even easier since we don’t have to edit it or put it into mathematical equations, but can take it directly as a string. The result looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*vYghihGtLphcDRTalcRrBQ.png" /><figcaption>Now this looks better</figcaption></figure><p>Now, all we need to do is save up 61.899 Euros! Thanks for reading! Let me know if you’re interested in similar projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9d91e23c0d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/how-to-find-a-car-under-market-value-with-python-beautifulsoup-and-your-own-telegram-bot-c9d91e23c0d1">How to find a car under market value — with Python, BeautifulSoup, and your own Telegram Bot.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>