Lots of merchants often like to ask why my store conversion rate suddenly is getting worse and worse. I always like to say your store performance suddenly is going down dramatically. It often is not dealing with your faults in operation and marketing strategy. Don’t take it personal. Sometimes it’s just a very simple reason why the conversion rate is going down, although it was still very outstanding yesterday. It’s your competitor doing something impacting your customer’s final decision. You need a web application facilitating you to monitor them and agility react on the deployment.
In this Python Tutorial, I would introduce you to Flask and Heroku and utilise them to build a web application – Shopify Bot. I would take our Python Tutorial 10 – Shopify Product scraper for example. By the end of this Python Tutorial, you can learn how to build the programming files under the Flask framework and go live the Shopify Bot using Heroku.
- What’s Flask and Heroku
- 1 Structure plus 3 core Ingredients and components – Folder plus Html, CSS and App.py
- Test the Application in Local Host – Flask Run
- Install gunicorn, add Procfile & Requirement.txt
- Connect the Git with Heroku
- Full Version Script of the Shopify Bot Web Application
What’s Flask and Heroku
Flask is a web framework, some people might also have known Django. They are very similar. It’s a Python module that lets you develop web applications easily. Flask has a small and easy-to-extend core. It does have many cool features like url routing, template engine. It is a WSGI web app framework.
We walk you through how to build a Shopify bot fetching your competitor webstore data. You might have a question about how to build a web application and share with others using this scraper. Flask is for the purpose of building a web application. Installing Flask in Mac is very easy, you just need to type
pip3 install flask in terminal. Meanwhile, Heroku is for the purpose of hosting the web application with a URL as a server role.
Heroku is a cloud service for hosting your applications, and the company was acquired by Salesforce in 2011. It is a Platform as a service or we call PaaS with support for auto scaling and deployment. It’s the fastest way going from ideas to URLs. It supports multi programming languages, such as Ruby, Php, Python, Java, Node.js, etc.
Below is the lighter version of shopify bot sponsored by Easy2Digital:
It primarily uses Git for deploying applications. There are some alternative options in the market such as Google App Engine, AppFog, Engine Yard, etc. It uses application source received from git push to generate a language specific build. Heroku uses its own lightweight Linux container called Dyno for running user specified commands.
Creating a Heroku app account is for free, although it has a limited application creation quota. It’s enough already.
1 Structure plus 3 core Ingredients and components – Html, CSS and App.py
Building a web application to publish is basically a web development project. So you need to have a website folder structure. It’s because flask automatically detects the folder name by default, and you can name it so flask can create the web URL paths. For example, templates host the index.html file you code for creating the front end layout and elements.
Static folder hosts the css file which you use to design and decorate your application. Last but not least, the function and core engine of this web application is the app.py.
Shopify Bot HTML Section
As well as building a webpage, you need to create a html and add header, body section connecting with app.py and main.css.
In this Shopify bot, you need to have a form and submit button for users to input the Shopify store URL and submit and download all store product data. Based on these elements needed, above is the coding sample.
Shopify Bot main.CSS
In the static folder, you can create a main.CSS file. In the file, you can design your paragraph font family, color, and the web application background color, image size. What’s more, designing a more engaging form and button.
First thing first, we need to import the flask modules except for the Shopify Bot modules.
from flask import Flask, render_template, request, flash, send_file
from bs4 import BeautifulSoup
import pandas as pd
Then, we need to create a secret_key which is used to integrate with other 3rd party platforms such as Heroku, etc. You can randomly input the secret number as you like.
Last but not least, we need to create and name the app path by using @app.route (). Basically in this route, you can define the post or get method. And under this route, you can create a custom function as well. Here I use flash to deliver the messagings based on the user action. And in the second path, I connect the function with our Shopify bot. Once the user downloads, it can activate the bot to fetch the specific store data and download it.
The core part of Shopify bot python script is the same with the Python Tutorial 10. If you are interested, please check it out.
Test the Application in Local Host – Flask Run
Staging test is indispensable before you upload to Github and activate in Heroku.
In the Mac terminal, you first locate where the web application is by using cd. Then you can input flask run and the terminal result comes up with a local host address, which you can use in the computer browser.
http://127.0.0.1:5000/ + the route name of returning index.html
Thus, you can test and modify accordingly before the web application going live.
Install Gunicorn, Add Procfile and Requirement Files
Before going live with the web application, we need to add two additional files in the application. First thing first, you need to go back to the Mac terminal and cd the application path. Then, installing the gunicorn is by inputting pip3 install gunicorn.
Then, the first file you need to add is the Procfile. You need to input echo > Procfile, which is to add the Procfile in the group folder.
After this, there is one more thing you need to add in Procfile. It’s a line of codes. The purpose is to configure the Heroku Dynos.
The second file you need to add is the requirement file. It’s easy that you just need to go back to the Mac terminal and input
pip3 freeze > requirements.txt
Connect Git with Heroku
Till now, your web application is time to go live. It’s very simple to make it. First thing first, you need to go to your Heroku account and add a new app. Then, in the setting, you need to add the buildpack and use Python.
Last but not least, please go to Heroku and your app interface. Click the deploy and you can select to upload your application folders to Heroku Kit, or by connecting Github. The deployment method is up to you.
After things are ready, you have two options to deploy on Heroku, which are the automatic deploy and the manual deploy. I would recommend you start with the manual deploy in the first time connecting with your application.
Full Version Script of the Shopify Bot Web Application
If you would like to have the full version script of the Shopify Bot Web Application, please subscribe to our newsletter by adding the message Python Tutorial 26. We would send you the script immediately to your mailbox.
So easy, right? I hope you enjoy reading Python Tutorial 26: Create a Shopify Bot Web Application Using Flask and Heroku. If you did, please support us by doing one of the things listed below, because it always helps out our channel.
- Support my channel through PayPal (paypal.me/Easy2digital)
- Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
- Follow and like my page Easy2Digital Facebook page
- Share the article to your social network with the hashtag #easy2digital
- Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
- You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount code on Buyfromlo products and digital software
- Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)