Analysis on Beer Consumption

Detailed analysis and code is on my Kaggle page:  https://www.kaggle.com/anudeepvurity/beer-consumption-analysis

Overview of the data:

The dataset explains about Consumption of beer in the Sao Paulo city, Brazil. The dataset has 7 columns and 365 records. This dataset file is in CSV format. Our main objective from this data is to find the rate of consumption of beer at different circumstances like minimum or maximum temperature in a day, during weekdays or weekends. We shall also have a look at how will precipitation affect the consumption of the beer. To make our project even more interesting let us add state holidays list of Sao Paulo in 2015. We can also see whether holidays are affecting consumption.

Questions to analyze on this dataset:

• Will beer consumption vary when there is a change in weather conditions like bad weather?

• Do weekends and weekdays play their role in beer consumption?

• Which months of the year has more beer consumption?

• Do national and state holidays play any role in the consumption of beer.

By answering the above questions we can understand the depth of the dataset.

Conclusion: 

The beer was consumed mostly in January and at least in July. It is also clear that weekends (Saturdays and Sundays) played a crucial role in the intake of beer, State_holidays did not play any significant role in consumption unless holidays matched with weekends. Temperature played a vital role in beer consumption as the temperature increases the beer consumption increases. Precipitation did not play a major role in consumption even though there is a slight declination in beer consumption when precipitation increases. We only used Temperature median as the dependent variable as it as higher correlation. We can also see both Linear Regression and Regression Trees predicted 96% on Sao Paulo dataset. Such kind of analysis of the data would help to flourish the restaurant business models in Sao Paulo. Please check this code on my Kaggle Page

 

Posted in Uncategorized | Leave a comment

Send Multiple WhatsApp messages using Seleinum

 

I made a fun project with selenium. I wanted to prank 5 friends of mine by surprising them with 1000 messages popping up of their WhatsApp. I definitely can’t paste 1000 times* 5, so I started wondering is there a simpler way by coding it on python. Let me break down this simple code and explain how it works. I used Jupiter notebook for this entire fun project.

 

Step 1: # first and foremost, pip install selenium you will also find it here

Import web driver from selenium and time libraries. We shall be using them for this project.

### from selenium import webdriver
###  import time

Step 2: Now, download chrome web drivers from here. This driver is used for operating the web page with selenium.  You can also use firefox by downloading firefox web drivers, but for this project, I am using Chrome 🙂

Note: make sure to have the webdriver.exe and python script in the same folder. 

#### driver = webdriver.Chrome()       #a new chrome tab will open and wait for selinium commands.
#### driver.get(“https://web.whatsapp.com”)  #  whatsapp web will open
#### print(“Scan QR Code in 60 seconds”)         # scan the QR code in 60 seconds to login.
#### time.sleep(60)

When you execute the above code a new webpage pops up waiting for your QR code to scan. Once you finish the scan your notebook will get access to your WhatsApp.

 

Step 3: Now create a list and text you want to send to them. 

#### Now, I created a list of friends A,b,c,d,e.and the text  “hi guys”

#### Contact = [“A”,”B”,”C”,”D”,”E”,”F”]

Step 4: Conventionally, We search our contact list on WhatsApp web, for that we hit on the search box, type the contact name stored in our phone and hit enter. Similarly, we should guide our script to follow the same.

###### search = driver.find_element_by_xpath(“//span[@title='{}’]”.format(contact))                        # this part, looks for search box on whatsapp web and pastes your contact name in it.
###### search.click()                               #This part, Selects the contact name.

 

Step 5: Now this step might vary from system to system, on your webpage hit F12 to see the HTML code, search for “copyable-text selectable-text”. You will find this piece of code ‘//div[@class=”_3FRCZ copyable-text selectable-text”][@contenteditable=”true“][@data-tab=”6“]’  with different keys on your screen. Copy the line or make sure to change the attributes accordingly.

Note: Paste the line in html_link= ___________ below. 

#       html_link = ‘//div[@class=”_3FRCZ copyable-text selectable-text”][@contenteditable=”true”][@data-tab=”6″]’                     # your textbox path is given
#       text_box = driver.find_element_by_xpath(html_link)                                                                                                                      # your textbox path is selected here
#       for i in range(1000):                                                                                                                                                                             # runs loop 1000 times (sends message 1000 times)  we can change the number accordingly.
                   text_box.send_keys(text + Keys.ENTER)                                                                                                                                # under every loop the text we want to send will be sent to our folks. ( here for thousand time)

 

step 6: since we have a contact list of 5 we have to make few changes in the above code to make it work for multiple names. We do it by simply adding a for loop to it.

#       for i in range(len(contact)):                                 
                 search = driver.find_element_by_xpath(“//span[@title='{}’]”.format(contact[i]))
                 search.click()
                 html_link = ‘//div[@class=”_3FRCZ copyable-text selectable-text”][@contenteditable=”true”][@data-tab=”6″]’
                 input_box = driver.find_element_by_xpath(html_link)
                 for i in range(1000): 
                          input_box.send_keys(text + Keys.ENTER)

The entire code is pasted down below.


Conclusion: The above script was built to prank my friends. But this could also be used in serious business situations where few repeated messages must be sent to multiple contact persons on WhatsApp. This would be a hand tool and saves a lot of time.

 

Posted in Uncategorized | Leave a comment