Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ db.sqlite3

*.bak
*.env
.idea/
26 changes: 26 additions & 0 deletions .idea/Distributed-project-backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ typing_extensions==4.11.0
uritemplate==4.1.1
uvicorn==0.29.0
whitenoise==6.6.0
pandas~=2.2.2
Empty file added store/management/__init__.py
Empty file.
Empty file.
91 changes: 91 additions & 0 deletions store/management/commands/upload_products.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
import random
import re

import pandas as pd
from django.core.management.base import BaseCommand

from store.models import Category, Product


class Command(BaseCommand):
help = "Upload initial data to database"
# SELLERS = {"Ali", "Amazon", "eBay", "Etsy", "Walmart", "Shopify", "Magento", "WooCommerce", "PrestaShop",
# "BigCommerce", "OpenCart", "Volusion", "Wix", "Squarespace", "Weebly", "3dcart", "Big Cartel",
# "Ecwid", "Gumroad"}

def add_arguments(self, parser):
parser.add_argument("filepath", nargs=1, action="store", type=str)

def handle(self, *args, **options):
filepath = options["filepath"][0]

# check file
if not os.path.exists(filepath):
self.stderr.write(f"File '{filepath}' does not exist.")
return

df = pd.read_excel(filepath)

category_name = os.path.basename(filepath).split("Data")[0]
# _ for the returned tuple
category, _ = Category.objects.get_or_create(name=category_name)

for index, row in df.iterrows():
if row["Price"] and row["Name"]:
price = float(re.findall(r"\d+\.\d+", str(row["Price"]))[0])
Product.objects.create(
name=row["Name"],
price=price,
category=category,
# seller=self.generate_random_seller(),
quantity=self.generate_random_quantity(),
description="Producer : "
+ row["Producer"]
+ "\n"
+ "Vram: "
+ row["Vram"]
+ "\n"
+ "Boost Clock: "
+ row["Boost Clock"]
+ "\n"
+ "TDP: "
+ row["TDP"]
+ "\n"
+ "Memory Clock :"
+ row["Memory Clock"]
+ "\n"
+ "DisplayPort: "
+ row["DisplayPort"]
+ "\n"
+ "HDMI: "
+ row["HDMI"]
+ "\n"
+ "Slots"
+ row["Slots"]
+ "\n"
+ "Length: "
+ row["Length"]
+ "\n"
+ "Width: "
+ row["Width"]
+ "\n"
+ "Height: "
+ row["Height"]
+ "\n"
+ "Weight: "
+ row["Weight"]
+ "\n"
+ "Warranty: "
+ row["Warranty"]
+ "\n"
+ "Price: "
+ row["Price"],
)

# def generate_random_seller(self):
# return random.choice(list(self.SELLERS))

@staticmethod
def generate_random_quantity():
return random.randint(1, 100)