Indomaret is a minimarket retail store from Indonesia that has been active since the 1980s. Until March 2023, Indomaret have had more than 21.000 stores spread across the country. Indomaret has become a dominant place for customers to fulfill their daily wants and needs. As technology progresses, customers can also buy products from Indomaret through online means, specifically from their official website: https://www.klikindomaret.com.
In this repository, I have provided the program to scrape and store the data from the website, specifically the https://www.klikindomaret.com/category/sarapan tab that contains all breakfast products. Each item on the page has its own name, final price, name of the warehouse that stores it, image, and discount (if there is any). And if you click on one of the items, you'll get more information like the PLU (which is basically a unique ID for each item), the composition and the description of each item.
I decided to pick the "klikindomaret" site because I understand how important managing the database within a minimarket retail is, especially since there are multiple entities being involved within the management, like the products themselves, the warehouse, the customers, etc. Therefore, taking good care of the gathered data can provide some good insights that can benefit the company, like what items do customers like to buy, what details that come within a single transaction, etc.
This program uses Python 3.11.4 programming language and the BeautifulSoup for the data scraping process. The data is first gathered from the page's HTML file, parsed, transformed, and cleaned before being appended to the array filled with dictionaries, each containing information of an item gathered. Later on, the dictionary is converted into JSON and CSV files which can be seen at Data Scraping/data.
This program uses PostgreSQL as the DBMS for the data storing process. The schema of the database is represented as the ER diagram and the relational diagram. The ER diagram contains the entities involved within a minimarket environment like "product", "cart", "customer", "warehouse", and "payment". The relational diagram is made by transforming the ER diagram (the full process can be seen in Explanation of the ERD to Relational Diagram Process). The only table that is filled with scraped data is the "product" table, while the other tables are left empty. The entire database can be used with the SQL file in Data Storing/export
First of all, please download and extract zip of this repository.
- Open the extracted folder in your preferred terminal
- Change the directory into
Data Scraping/src - Type
python -u web_scraping_sarapan.pyon the terminal - Please wait, it usually takes around +30 seconds to gather the data
- After the process is over, a couple of messages will show up in the terminal telling you that the JSON and CSV files are successfully created.
- You can access them in
Data Scraping/data
- Grab the
indomaret_database.sqlfile inside theData Storing/exportfolder. - Import to your PostgreSQL using the command:
psql -U [username] -d [database_name] < .indomaret_database.sql - Log in to yout PostgreSQL account
- Type
\lin the PostgreSQL prompt to check whether the "indomaret" database is listed within the list of databases in your account. - Use the database using the command
\c indomaret.
The available JSON file in this project comes in the name of products.json which can be found in Data Scraping/data. The file has an array that contains all objects in the form of dictionaries which contain the attributes that come from the data scraping of the Indomaret website page.
Below is the following structure:
[
{
"Key/Column 1": "Value",
"Key/Column 2": "Value",
...
"Key/Column X": "Value",
},
{
"Key/Column 1": "Value",
"Key/Column 2": "Value",
...
"Key/Column X": "Value",
},
...
]
This program uses a database named "Indomaret".
Below is the Entity-Relationship Diagram (ERD) of the "Indomaret" database. "PK" stands for primary key for each entity and "K" stands for regular key.
- Turn strong entities into relations like "Products", "Warehouse, "CartProduct", "Customers", and "Payment"
- Represent multivalued attributes as a separate schema that contains the primary key of the original entity and the multivalued attribute itself
- Make a new schema "Customers_Phone" that contains customer_id and phoneNumber
- Make a new schema "Warehouse_Phone" that contains warehouseName and phone_number
- Represent the "Payment" specialization by forming a schema for each payment method, including the primary key of "Payment" and the local attributes.
- Credit_Card = (payment_id, CCNumber, CV)
- Debit_Card = (payment_id, DCNumber)
- Online_Payment = (payment_id, PaymentPhoneNumber, CompanyName)
- Represent the one-to-one relationships, by picking one of the tables in the relationship (prioritizing the entity in the "total participation" side) to be inserted with an extra attribute corresponding to the two entity sets.
- "CartProduct" and "Customers" have a one-to-one relationship, so add customer_id attribute into the "CartProduct" table since it has a total participation.
- "CartProduct" and "Payment" have a one-to-one relationship, so add payment_id attribute into the "CartProduct" table since it has a total participation.
- Represent the many-to-one relationship by adding an extra attribute to the "many" side, containing the primary key of the "one" side
- "Products" and "Warehouse" have a many-to-one relationship, so add warehouseName to the "Products" table since it's in the "many" side.
- Represent the many-to-many relationship by creating a schema that contains a) both primary keys from the two entities involved and b) additional attributes within the relationship
- "Products" and "CartProduct" have a many-to-many relationship, so add PLU and cart_id into a new schema called "FillingCart" based off of the "Fills" relationship that connects both entities. Also, add the product_quantity attribute as it is the descriptive attribute from the "Fills" relationship.
Data initialization
Inserting PLU and product name into the products table dictionary Inserting the rest of the products attributes into the dictionary Converting dictionary into ```.json``` and ```.csv``` file List of tables in the indomaret database List of product column names An example of selecting products' final price A dummy data of the warehouse table (that has to be filled in, otherwise the foreign key "warehousename" that is referenced by the products table won't work)Below are the libraries I used for this project:
- BeautifulSoup4
- Requests
- JSON
- CSV
Muhammad Farrel Danendra Rachim (13521048)










