<?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 Asaf Pras on Medium]]></title>
        <description><![CDATA[Stories by Asaf Pras on Medium]]></description>
        <link>https://medium.com/@aspras01?source=rss-76ab98636d00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H_K4j5UGygamL6TNrKuf9g.jpeg</url>
            <title>Stories by Asaf Pras on Medium</title>
            <link>https://medium.com/@aspras01?source=rss-76ab98636d00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:15:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aspras01/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[Python Automated WhatsApp Message Sender 2.0]]></title>
            <link>https://levelup.gitconnected.com/python-automated-whatsapp-message-sender-2-0-d146704e7f2f?source=rss-76ab98636d00------2</link>
            <guid isPermaLink="false">https://medium.com/p/d146704e7f2f</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Asaf Pras]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 01:59:29 GMT</pubDate>
            <atom:updated>2022-12-12T07:30:53.113Z</atom:updated>
            <content:encoded><![CDATA[<h4>Take our automated WhatsApp sender another level up, and learn how to add a graphical user interface (GUI) for more convenient use.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZsXUuivbvvgs5eIVyXeGQ.png" /><figcaption>Image by author</figcaption></figure><p>A week ago, I published a <a href="https://levelup.gitconnected.com/python-automated-whatsapp-message-sender-db488c8c6bc7">story</a> about how to “build an automated WhatsApp sender that will send randomized messages on your behalf during the day”, and after a few days, it gained more than 20,000 views. Many people on multiple platforms (Medium, LinkedIn, and more) ask me many questions about how we can make it easier to use. So the first step to making it more applicable is to transfer the user interface into a GUI that will be more intuitive.</p><p>In this story, we won’t go over the basics of the WhatsApp Automated Message Sender (WAMS), so you can go to the previous story and dive into the basics of it from here:</p><p><a href="https://levelup.gitconnected.com/python-automated-whatsapp-message-sender-db488c8c6bc7">Python Automated WhatsApp Message Sender</a></p><h4>Let’s start</h4><p>As always, we will start by importing the library that we will use. In this case, we need only one library — <a href="https://docs.python.org/3/library/tkinter.html">tkinter</a>, which is the standard GUI library for Python. When combined with tkinter, Python provides a fast and easy way to create GUI applications. In addition, Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit. There are tons of modifications that we can use with this library, and we will use some of them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8d1aeb52d706b1c59fbb1c360944bff/href">https://medium.com/media/b8d1aeb52d706b1c59fbb1c360944bff/href</a></iframe><p>After importing, we first need to create the GUI application’s main window, which we will do with the .Tk() method. As the window’s title default is ‘tk’, we will then use the .title method to set the title as we would like. The title method takes a string as an argument, so we will call it “WAMS — WhatsApp Automated Message Sender”. Last, we need the .mainloop() method, which is simply a method in the main window that executes what we wish to execute in an application. As the name implies, it will loop forever until the user exits the window or waits for any events from the user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56df7ec2561612c6b38e8d60f6e0e964/href">https://medium.com/media/56df7ec2561612c6b38e8d60f6e0e964/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*NurtQYlnQuN4RMcatGazRw.png" /><figcaption>Our GUI. Obviously, it’s empty for now. (image by author)</figcaption></figure><p>Now, as we built the WAMS in the previous story, it takes four inputs from the user:</p><ul><li>phoneNumber: What number would the user like to text? Remember that the number must include the country calling code</li><li>numberOfMessages: How many messages will the application send to the number?</li></ul><p>As this script sends messages randomly between 2 hours, the user also needs to indicate between which two hours he would like to send the messages, so we need:</p><ul><li>startingHour</li><li>endingHour</li></ul><h4>Let’s add widgets</h4><p>tkinter provides various controls, such as buttons, labels, and text boxes used in a GUI application. These controls are commonly called widgets.</p><p>For our two first inputs, we will use the .Label widget to indicate what data we need from him and the .Entry widget to collect the data. The entry widget is a text box where the user can put his input, which takes at least two arguments. First, every widget needs us to indicate on which window we want to place it (master in this case), and second, it takes the text= argument, which, well, obviously refers to what is the text label that we want to present.</p><p>Next, we will define two variables that will hold the collected inputs. Notice that we use the .StringVar method to hold the phone number as it needs to be a string. The second one will be for the number of messages we send, which needs to be an integer.</p><p>Now, as said, we want to use the .Entry widget to collect the inputs. For that, we again start by stating on which window it will be, and then we state the text that is inserted to be assigned to the coupled variable.</p><p>Notice that for each widget, we also call the .grid() method. The grid geometry manager puts the widgets in a 2-dimensional table. The master widget is split into a number of rows and columns, and each “cell” in the resulting table can hold a widget. In our case, we put each label and its entry together in the same row.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c683f4ca61b84bdc59f3bc6bdc23eb4/href">https://medium.com/media/7c683f4ca61b84bdc59f3bc6bdc23eb4/href</a></iframe><p>Next, we need to ask the user to set the hours variables. For that, we will ask him to choose between which hours he would like to send the messages and place that in one row, but split into three columns. Both the starting and ending hours will be integer values, and beneath the “from” and the “to” we will place two .OptionMenu , a widget for a dropdown menu. As always, it first takes the window where it will be placed. Second, it takes the variable that will be assigned. Third, it takes a list of options for the menu, and last it takes a command. The command is a function that will do something that can also depend on the value we choose.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2b34cd82f8001a6f51bed5e7e468c9c/href">https://medium.com/media/d2b34cd82f8001a6f51bed5e7e468c9c/href</a></iframe><p>In both .OptionMenu widgets, we build a function that will assign the value to the widget itself, so the user can see the value that he chose. For that, we need to use the .get() method that extracts the values that are stored in the tkinter variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02a188682adc7cfd5d6fdcf278e368c3/href">https://medium.com/media/02a188682adc7cfd5d6fdcf278e368c3/href</a></iframe><p>Before we jump to the last widget, we need to define our numberOfMessages while loop as a function so it can be used for the execution of the last widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ee8913d322581d783d8517687385031/href">https://medium.com/media/5ee8913d322581d783d8517687385031/href</a></iframe><p>Last, we will add a button to send messages with the .Button widget. After stating the window, we set the text on the button and then assign a command to activate the countMessages function. As this function takes five arguments, we need to wrap it with a lambda as below. Finally, we assign the button to the 4th row and in the 5th column.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8339580259dafca27c97e966db103f11/href">https://medium.com/media/8339580259dafca27c97e966db103f11/href</a></iframe><p>The final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*H-dTGZeOVIDZ016b5dW5bg.png" /></figure><h3>And that really is it!</h3><p>I’ll stop here, and you can find the <a href="https://github.com/Waeara/Python-Automated-WhatsApp-Message-Sender/blob/main/Whatsapp%20automate%20message%20sender%20with%20GUI.ipynb">full code here</a>. As mentioned, there are tons of things that we can keep modifying in our GUI. So if you do any further modifications, let me know with a comment or do it as a fork of the git, And if you have any thoughts or questions, feel free to leave a comment 🙂</p><p>Thanks for reading! 👍</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d146704e7f2f" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/python-automated-whatsapp-message-sender-2-0-d146704e7f2f">Python Automated WhatsApp Message Sender 2.0</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Raster’s Data as ML and AI Inputs]]></title>
            <link>https://levelup.gitconnected.com/use-rasters-data-as-ml-and-ai-inputs-b6cc6ea31f84?source=rss-76ab98636d00------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6cc6ea31f84</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Asaf Pras]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 12:38:16 GMT</pubDate>
            <atom:updated>2022-12-06T12:38:16.625Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to extract a raster’s data into a DataFrame for machine learning and AI model inputs.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-MOl8zWDWQXs9N_CjTZIA.png" /><figcaption>Rasters for ML and AI model (image by author)</figcaption></figure><p>My research focuses on developing machine learning and artificial intelligence algorithms for water quality monitoring. In this field, real-world data is complex and rare to find, and whenever I get data, it doesn’t contain too many features. That’s why I must add many meta-data features that may affect the target I want to predict. A few months ago, I found out that there is a lot of data which is stored in pictures called ‘rasters’. So in this article, I will show how to take this raster and extract its data so it can be used as inputs for ML and AI models.</p><h4>What is a raster?</h4><p>A raster image is an image file format that’s defined by a pixel with one or more numbers associated with it. The number represents the location, size, or color of the pixels. Raster images are commonly <a href="https://www.computerhope.com/jargon/b/bmp.htm">BMP</a>, <a href="https://www.computerhope.com/jargon/g/gif.htm">GIF</a>, <a href="https://www.computerhope.com/jargon/j/jpeg.htm">JPEG</a>, <a href="https://www.computerhope.com/jargon/p/png.htm">PNG</a>, and <a href="https://www.computerhope.com/jargon/t/tiff.htm">TIFF</a> files. These files can represent almost any data — geographical, geological, climate, weather, population, and more. In addition, these files have coordinates so they can be projected on or as a map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGxfV_xSvg73n0_f5X5MXw.png" /><figcaption>Global cumulative precipitation for 2018 [mm/yr] (Image by Author)</figcaption></figure><h4>Let’s start</h4><p>As always, we must import all the libraries we will use, and before that, we will ask the Jupyter Notebook to present all figures inline. First, the database will be managed in <a href="https://pandas.pydata.org/docs/">Pandas</a>, a library software written for Python for data manipulation and analysis of tabular data, and its geospatial twin <a href="https://geopandas.org/en/stable/">GeoPanda</a>, which allows manipulations and analysis of geospatial data. Obviously, we will import <a href="https://matplotlib.org/">Matplotlib</a> for plotting the figures later and <a href="https://numpy.org/">Numpy</a> for some mathematical manipulations. Last, we will import <a href="https://rasterio.readthedocs.io/en/latest/">Rasterio</a>, which will be used for opening the rasters, manipulating, and plotting them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a503e4d51b934c8fe9b57997748c3dac/href">https://medium.com/media/a503e4d51b934c8fe9b57997748c3dac/href</a></iframe><h4>Load the data</h4><p>The data we will use as an example will be the locations of water samples, but without the other data. First, we will load the excel table as a pandas DataFrame with the .read_excel() method and drop rows with NaNs, which axis=0 refers to dropping the rows (and not the columns). Next, we will clean the data from non-numeric values as some of the coordinates are invalid (we can fix them, but it’s not essential for this example).</p><p>Now, we need to convert it into a GeoDataFrame. This method takes two most important parameters: (1) the data itself and (2) the geometry we want to represent the data. In our case, we will present the data as points where the location is determined with the.points_from_xy() method that takes 2 arguments: longitude and latitude.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*KTOgCYQdpZcyYbt7y2GJHQ.png" /><figcaption>Latitude is the Y axis, longitude is the X axis.</figcaption></figure><p>The last part will be changing the coordinate reference system (CRS), which is a coordinate-based local, regional or global system used to locate geographical entities. A spatial reference system defines a specific map projection, as well as transformations between different spatial reference systems. If you are not sure what CRS you should use, you can check on <a href="https://epsg.io/">this website</a>. For India’s mainland, we will use EPSG:4243.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06b312c8b39c033023b6f8744ecf5753/href">https://medium.com/media/06b312c8b39c033023b6f8744ecf5753/href</a></iframe><p>So the DataFrame we have now is a GeoDataFrame, which differs because of the ‘geometry’ column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*CX-ycrURWNGnlTqiFPuHEQ.png" /><figcaption>The GeoDataFrame that we now hold (image by author)</figcaption></figure><p>Next, we will load India’s shapefile, which format is a geospatial vector data format for geographic information system software. This can also be done with GeoPandas with the .read_file() method that takes the shapefile path as an argument. Then we must remember to set the shapefile’s CRS the same as our data is with the .set_crs() method. Let’s plot it to see how it looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/818aa3f2bd154c02a57406629f1660fe/href">https://medium.com/media/818aa3f2bd154c02a57406629f1660fe/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*KVjKCzSD2u9Eidl9_bV8kw.png" /><figcaption>Example for a shapefile (image by author)</figcaption></figure><p>W can see that we get the boundaries of India (including its island) with the axes as coordinates. Let’s plot the points to see how they look on a map:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12c9fc475a9e79a36d3cf16b7aa80429/href">https://medium.com/media/12c9fc475a9e79a36d3cf16b7aa80429/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*Bc9WLVD_g52XR0ZNQPDawQ.png" /><figcaption>Oops, that is not what we expected (image by author)</figcaption></figure><p>As can be seen from both axis — we have points with wrong coordinates. If it were a small dataset or important for the example, I would try to find out which ones are wrong and correct them, but in this case, we will filter all data points that are outside of the boundary of India, as in the next steps they won’t get any real data added to them from the rasters. These points probably had a mistake when they were recorded.</p><p>GeoPandas provides us with a great and easy way to screen this data. We will use a spatial join between our dataset and our shapefile and keep only the points where the coordinates are ‘within’ the ‘inner’ part of the shapefile. This can be done with the <a href="https://geopandas.org/en/stable/docs/reference/api/geopandas.sjoin.html">.sjoin()</a> method. After using this method, our DataFrame will also consist of index_right and Area columns, so we will drop those and plot to see the results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15060ca49592c1ae2a5f7de00cc639ef/href">https://medium.com/media/15060ca49592c1ae2a5f7de00cc639ef/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*dZPv4Df6nbgRowJJ6CcMig.png" /><figcaption>That looks much better (image by author)</figcaption></figure><h4>Extract the data</h4><p>Last step. We will spatial join the data for each data point from the raster and the shapefiles so that each point will hold its data based on the coordinates. For that, we need to make sure that we are using the same CRS also for the raster. The code below is written for extracting multiple rasters and adding them to the DataFrame, and therefore it uses the os and glob libraries and the path to the folder that holds all the rasters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w7HdZOqBnayqRVZCgACeXA.png" /><figcaption>India’s 2018 cumulative precipitation [mm/yr], which we will use in this example (Image by Author)</figcaption></figure><p>First, we need to extract all point’s longitude and latitude as x and y, which can be easily done with the .x and .y methods. Next, we will use Rasterio’s.open method to open the raster, as the following line is the center of this part. by using the Rasterio’s.sample method that takes the coordinates list as an input, we will sample for each coordinate the raster value at that location. In addition, in the same line, we already assign the value to the new column in our DataFrame (giving it the same name as the raster, just without the ‘.tif’, in this example).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2168ab7a4ce3f400943dc473f24ed83e/href">https://medium.com/media/2168ab7a4ce3f400943dc473f24ed83e/href</a></iframe><p>Finally, we got the result we so wanted, and we are ready to go with our ADE, building up a model or whatever you needed this data for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*1Dnv3LtHHS6Lq1WrU55-iw.png" /><figcaption>The raster data is added as the last column (image by author)</figcaption></figure><h4>And that really is it!</h4><p>I’ll stop here, and you can find the <a href="https://github.com/Waeara/Use-Raster-s-Data-as-ML-and-AI-Inputs">full code here</a>, including some parts that I skipped, such as clipping the global raster into India’s and more. And if you have any thoughts or questions, feel free to leave a comment 🙂</p><p>Thanks for reading! 👍</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6cc6ea31f84" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/use-rasters-data-as-ml-and-ai-inputs-b6cc6ea31f84">Use Raster’s Data as ML and AI Inputs</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Automated WhatsApp Message Sender]]></title>
            <link>https://levelup.gitconnected.com/python-automated-whatsapp-message-sender-db488c8c6bc7?source=rss-76ab98636d00------2</link>
            <guid isPermaLink="false">https://medium.com/p/db488c8c6bc7</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[whatsapp]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Asaf Pras]]></dc:creator>
            <pubDate>Fri, 02 Dec 2022 17:50:43 GMT</pubDate>
            <atom:updated>2022-12-08T10:56:42.617Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to build an automated WhatsApp sender that will send randomized messages on your behalf during the day.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DrcouZ3ci76NiVi36hosZw.png" /><figcaption>Image by author</figcaption></figure><p>Last week was very busy at work, and I barely managed during the day to arrange a time for lunch and worse than that — to talk to my wife and ask how she is. After a week where in the evenings, I had to explain why I didn&#39;t have a few seconds to send a WhatsApp message, I came up with the idea — to build a Python script that would send a daily message on my behalf. So I set out on a mission to create one and try to make it as general, random, and reliable as possible. The last thing I need is for her to find out that I spent time building such a script instead of just sending a message…</p><h4>Let&#39;s start</h4><p>We will start with importing the libraries that we&#39;ll use. First, we will import the main library <a href="https://pypi.org/project/pywhatkit/">PyWhatKit</a>, which is one of the most popular libraries for WhatsApp and YouTube automation and allows you to send WhatsApp messages quite easily in one line. In fact, the library is built so that we won&#39;t need almost any of the other libraries, as the methods are supposed to open the WhatsApp web, send the message automatically, and close the tab. But to this date, there are some bugs, so we will need more work to work around those.</p><p>One of the bugs (at least that I encountered) is that the automatic sender is not working, so to work around it, we will use <a href="https://pyautogui.readthedocs.io/en/latest/">PyAutoGUI</a>, which lets your Python scripts control the mouse and keyboard to automate interactions with other applications. In addition, we will use <a href="https://pypi.org/project/pynput/">PynPut</a>, and specifically the Key and Controller methods, so we can add control to our keyboard to send the messages.</p><p>Eventually, we will need the <a href="https://carpedm20.github.io/emoji/docs/">emoji</a> library to make our messages a bit more diverse, the <a href="https://docs.python.org/3/library/random.html">random</a> library to randomly choose the messages and the time that the messages will be sent, and the <a href="https://docs.python.org/3/library/time.html">time</a> library to give the code some time to do its job.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d627a5a59fecae02a8bf4e1c8734366/href">https://medium.com/media/3d627a5a59fecae02a8bf4e1c8734366/href</a></iframe><p>In order to send the message, we will write a function as below. In general, we will try to send the message (as I mentioned, I encountered several bugs, so it&#39;s easier to work like this), and if it won&#39;t work, we willexcept the error and just print it, so we will know what went wrong. Our function takes four parameters: a phone number with country code and a message, both as strings, and two integers for the hour (between 0 to 23) and minutes between 0 to 59.</p><p>In the try, we first use the pywahtkit.sendwahtmsg method, which, as the name suggests, sends a message. All the function&#39;s parameters are inputs for this one, and in order for this to work properly, the time should be at least 5–6 minutes before the desired time for sending the message. Next, we will wait for 10 seconds with the time.sleep() so our browser will have the time to open the WhatsApp tab, and this may vary in time depending on your internet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a40c5c8029d3665eae2e19f5b5648e8/href">https://medium.com/media/1a40c5c8029d3665eae2e19f5b5648e8/href</a></iframe><p>After the first time you will use the pywahtkit.sendwahtmsg method, the WhatsApp web will ask you to connect your device to the browser, as shown below. This can also affect the first run of the function, as it will take longer than 10 seconds to open the tab and connect your computer (the method also has a built-in 15 delay, but it might not be enough for this)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*Ghy-9CB2RdPZgQz8Tyi8ig.png" /><figcaption>Image by author</figcaption></figure><p>Now, we need to build a &quot;bank&quot; of messages, which we will randomly choose a message every time with the random.choise method. The example below shows you that along with some simple text messages. In addition, I used the emoji.emojize method to spice up some of the messages or just to send an emoji alone.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5dd7a4c00f40648525908b919f52f150/href">https://medium.com/media/5dd7a4c00f40648525908b919f52f150/href</a></iframe><p>Hold on. We are almost there. To make it more interactive, I added an option to choose how many messages I would like to send every day and between which hours (starting hour and ending hour). Obviously, that depends on your working day length. All of this is being achieved by the input() built-in function, which asks the user to write his answer as input.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40bd19fe73be8f4388e38c0de14876d2/href">https://medium.com/media/40bd19fe73be8f4388e38c0de14876d2/href</a></iframe><p>Eventually, we will run a while loop that runs as long as it doesn&#39;t send all the messages we asked for. It first randomly chooses an hour, then picks the minutes, and eventually calls the sender function that we previously built.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8adced346d800d5167e4f0edcc1df695/href">https://medium.com/media/8adced346d800d5167e4f0edcc1df695/href</a></iframe><h4>And that really is it!</h4><p>I’ll stop here, but you can find the <a href="https://github.com/Waeara/Python-Automated-WhatsApp-Message-Sender/blob/main/Whatsapp%20automate%20message%20sender.ipynb">full code here</a>. And if you have any thoughts or questions, feel free to leave a comment 🙂</p><p>Thanks for reading! 👍</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db488c8c6bc7" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/python-automated-whatsapp-message-sender-db488c8c6bc7">Python Automated WhatsApp Message Sender</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating interactive maps with Python, Folium, and some HTML]]></title>
            <link>https://levelup.gitconnected.com/creating-interactive-maps-with-python-folium-and-some-html-f8ac716966f?source=rss-76ab98636d00------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8ac716966f</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[geospatial]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[folium]]></category>
            <dc:creator><![CDATA[Asaf Pras]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 09:02:05 GMT</pubDate>
            <atom:updated>2022-11-17T21:23:43.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8J20L7TpliRkD0ZmI_v_w.gif" /><figcaption>Let’s create one like this</figcaption></figure><h4>Learn how to create beautiful, interactive maps with Python’s Folium library and some HTML for superb styling.</h4><p>For one of the projects in my research, there was a need to produce an interactive map, and as a Python programmer, I knew several methods to perform the task. To carry out the job, I chose to use the Folium library, but the popup markers that can be designed are fundamental, so to improve the design of the popups, I integrated HTML into the code. In this article, I will present a simple but beautiful example.</p><h4>Let’s start</h4><p>When it comes to creating interactive maps with Python, the Folium library does the job well, as you don’t need to know much Python to get this working and generate decent maps. So let’s go ahead and import Folium and the other dependencies we’ll need (these will be explained as we encounter them).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a326f340a19b7c695d63e6e8d7873e71/href">https://medium.com/media/a326f340a19b7c695d63e6e8d7873e71/href</a></iframe><p>We will use data about Tel Aviv’s top restaurants for this example. The data contains several restaurants’ names, locations, latitude and longitude, opening hours, price rate (one to four), and some images. So let’s go ahead and read the data with Pandas.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb5a5eecd247238093cc28039d7920f7/href">https://medium.com/media/fb5a5eecd247238093cc28039d7920f7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*kKZRVjESGDdCx0t5XtcICQ.png" /><figcaption>Tel Aviv’s top restaurants’ data</figcaption></figure><p>Now let’s create a map — just a plain and straightforward base map.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2852884393c0d54a8927c979e91c9a13/href">https://medium.com/media/2852884393c0d54a8927c979e91c9a13/href</a></iframe><p>The ‘location’ argument takes the coordinates of the center of the map. Folium comes with a few in-built map tilesets that you can easily specify using the ‘tiles’ argument. The default is the OpenStreetMap (OSM) tileset, but Folium also supports the use of publicly available map tiles from providers such as <a href="http://maps.stamen.com/#terrain/12/37.7706/-122.3782"><em>Stamen</em></a>, <a href="https://www.thunderforest.com/maps/"><em>Thunderforest</em></a>, <a href="https://stadiamaps.com/"><em>Stadia</em></a><em>, </em><a href="https://carto.com/basemaps/"><em>Carto</em></a>, and others. Check out <a href="https://leaflet-extras.github.io/leaflet-providers/preview/">this link</a> to see a comparison between some of those. The ‘zoom_start’ defines the initial zoom for the map, and the ‘control_scale’ adds a scale bar. Folium saves everything associated with your map in HTML, so it means you can quickly take a look at what your map looks like by opening the .html file in your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*ZVRnqduizcw3wDeMEVvb1A.png" /><figcaption>Folium’s base map of Tel Aviv streets</figcaption></figure><p>And that’s it! One line of Python, and we already have a bright, colorful base map.</p><h4>Next, add a marker to the map</h4><p>Let’s start and put one marker on the map. We want to place it according to its coordinates and put it in decimal coordinates as [latitude, longitude]. Folium also allows us to easily add a tag with a caption when we move the mouse over the cursor. This is done with the ‘tooltip’ argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b6c3f248d163d8197cb45512a936c0e/href">https://medium.com/media/4b6c3f248d163d8197cb45512a936c0e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*8m9Ihqq3zD_pMF4SbDdjEw.png" /><figcaption>Folium’s base map with a marker. adding the tooltip argument enables to share of short text when the cursor is over it.</figcaption></figure><p>The next step will be to make the marker clickable, and this is done by adding just one more line of code and adding another argument to the Marker method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abdb3375bf210aeb74cd133b1bf174a6/href">https://medium.com/media/abdb3375bf210aeb74cd133b1bf174a6/href</a></iframe><p>The Popup method enables us to add text and uses other languages, such as HTML. The max width and max height arguments allow us to set a limit to how big the popup will be, while the ‘popup’ argument in the Marker method specifics the marker to use that popup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*kobbh3CLocSou8FWy43VqQ.png" /><figcaption>Folium’s base map with a clickable marker</figcaption></figure><p>As we want our interactive map to be functional and attractive, we won’t just put the details as text and finish. Instead, we will arrange the text under accordion buttons and also use some images of the restaurants and their dishes. The best way to do that is by using HTML. HTML is often used to design websites, but in this case, it allows us to design our markers nicer. So first:</p><h4>Let’s arrange the pictures for the presentation</h4><p>There are several ways to showcase images in the popups, such as slideshow, video, etc., but we will use an easy way of wrapping those images into a GIF. For that, we will use the <a href="https://imageio.readthedocs.io/en/stable/">Imageio</a> Python package, which provides an easy interface to read and write a wide range of image data, and the <a href="https://docs.opencv.org/4.x/d6/d00/tutorial_py_root.html">cv2</a> package, which has many uses, but we will use it to generate our GIF.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6af3dccd3fff5c6ce934c164044ede5/href">https://medium.com/media/b6af3dccd3fff5c6ce934c164044ede5/href</a></iframe><p>We start with looping for each restaurant through the JPEG names and appending the JPEGs themselves to the frame list. With the imageio.get_writer method, we write a new .gif file that will show each frame with a duration of 2 seconds. Last, we read and resized all images to the same scale and append them to the writer. This is not the highest quality method to showcase the images, but I find it the easiest:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*rISAuWAy862HFPaXw6NCXQ.gif" /></figure><h4>Now, let’s design those popups</h4><p>Here we use a simple for-loop to run through all the restaurants we want to create markers for them. Please don’t get overwhelmed, as we will go through this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e0ee3160f5efb4ffc70ec28702b6037/href">https://medium.com/media/4e0ee3160f5efb4ffc70ec28702b6037/href</a></iframe><p>Folium has a built-in method for integrating HTML into the popup- ‘Folium.Html’ which takes the HTML code as its input. And to allow us flexibility in entering the features of each restaurant in the loop into the appropriate field, we will use the f-string method.</p><p>We will set each popup a header with the restaurant’s name. In this example, we aligned it to the center, used Calibri font, colored it in white, and set it to bold (&lt;strong&gt;):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6acfbfb6ee828def78ecc52799efe569/href">https://medium.com/media/6acfbfb6ee828def78ecc52799efe569/href</a></iframe><p>The following two lines link our HTML pages with (1) font awesome’s icons so we can use them in the text and (2) bootstrap’s CSS for accordion buttons. The next code block represents an accordion button, and in this example, is used four times:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c5b85ba4678043975655d9938cff7c7/href">https://medium.com/media/9c5b85ba4678043975655d9938cff7c7/href</a></iframe><p>Most of it is the definitions for the buttons and the relationship between them (clicking one closes the others). To style the button’s text, you can change or add the ‘style’ in the &lt;h4 class=&quot;panel-title&quot; line. By changing the &lt;i class=&quot;fa-light fa-newspaper&quot;&gt;&lt;/i&gt; to one of the many other icons in the <a href="https://fontawesome.com/icons/">font-awesome website</a>. The &lt;div class=&quot;panel-body&quot; is responsible for the text under the button. In this case, we just set it to align as “justify”, but this can also be styled with color, font family, font size, etc. The last part of the HTML code is to upload our GIF:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8a82317ce45347deff8dcc1188929c4/href">https://medium.com/media/b8a82317ce45347deff8dcc1188929c4/href</a></iframe><p>This part is relatively straightforward. ‘src’ takes the image/gif location, where the ‘width’ sets its size. In addition, to give it a better style, we set the ‘border-radius’ to 50px to get a nicer look.</p><p>The last two steps for each marker are to (1) define the popup with the HTML code in it and set up the marker just like we did before and (2) set a nice background. In our case, I used HTML to define a linear gradient background moving from blue at the top to white, finishing the transition after 25% of the page (popup). Still, you can also use images or GIFs with the same method- replace what comes after ‘background:’ with the same structure of the line we used to present the gif. So the final product that we got:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8J20L7TpliRkD0ZmI_v_w.gif" /><figcaption>The final result</figcaption></figure><h4>And that really is it!</h4><p>I’ll stop here, but you can find the finished <a href="https://waeara.github.io/Creating-interactive-maps-with-Python-Folium-and-some-HTML/Tel%20Aviv%20Resturants.html">map here</a>. And if you have any thoughts or questions, feel free to leave a comment 🙂</p><p>Thanks for reading! 🍔</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8ac716966f" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/creating-interactive-maps-with-python-folium-and-some-html-f8ac716966f">Creating interactive maps with Python, Folium, and some HTML</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>