Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dan integrate database #50

Merged
merged 5 commits into from
Mar 18, 2024
Merged
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
33 changes: 33 additions & 0 deletions .github/workflows/react-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI/CD for Frontend (React + CSS)

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies
run: npm install react react-dom react-scripts

- name: Build
run: npm run build

#- name: Run tests
# run: npm test -- --coverage


26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Backend/__pycache__/database.cpython-39.pyc

# Logs
Frontend/app/SPL/logs
Frontend/app/SPL/*.log
Frontend/app/SPL/npm-debug.log*
Frontend/app/SPL/yarn-debug.log*
Frontend/app/SPL/yarn-error.log*
Frontend/app/SPL/pnpm-debug.log*
Frontend/app/SPL/lerna-debug.log*

Frontend/app/SPL/node_modules
Frontend/app/SPL/dist
Frontend/app/SPL/dist-ssr
Frontend/app/SPL/*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
40 changes: 5 additions & 35 deletions Backend/backend.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,14 @@
from flask import Flask, redirect, url_for, render_template, request, session, Response
from database import retrieve
import flask_cors
import requests
import json
import os
import sqlite3

link_lookup_table = {"Laptops and 2-in-1 PC": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sc/laptops",
"XPS": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/xps-laptops",
"Latitude": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/latitude-laptops",
"Inspiron": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/inspiron-laptops",
"Vostro": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/vostro-laptops",
"Alienware": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/alienware-laptops",
"Precision": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/precision-laptops",
"Desktops": "https://www.dell.com/en-ie/shop/desktop-computers/sc/desktops",
"OptiPlex": "https://www.dell.com/en-ie/shop/desktop-computers/sr/desktops/optiplex-desktops",
"Monitors": "https://www.dell.com/en-ie/shop/computer-monitors/ar/8605",
"Docking Stations": "https://www.dell.com/en-ie/shop/docks-and-stands/ar/5441/docking-stations?appliedRefinements=962",
"Audio": "https://www.dell.com/en-ie/shop/audio/ac/8310",
"Keyboards and Mice":"https://www.dell.com/en-ie/shop/keyboards-mice/ar/6591",
"Hard Drives, SSDs and Storage": "https://www.dell.com/en-ie/shop/hard-drives-storage/ar/8496",
"Webcams and Video Conferencing": "https://www.dell.com/en-ie/shop/web-cameras/ar/8332",
"Batteries, Chargers and Power Adapters": "https://www.dell.com/en-ie/shop/pc-accessories/ar/5436/batteries-chargers-power-adapters?appliedRefinements=44426",
"Cables and Adapters": "https://www.dell.com/en-ie/shop/cables/ar/8168/cables-adapters?appliedRefinements=44427",
"Security and Protection": "https://www.dell.com/en-ie/shop/security-protection/ar/7664",
"Parts, Batteries and Upgrades": "https://www.dell.com/en-ie/shop/parts-batteries-upgrades/ar/7566",
"Wi-Fi and Networking": "https://www.dell.com/en-ie/shop/wifi-and-networking/ar/4011",
"Gaming Accessories": "https://www.dell.com/en-ie/shop/gaming-gaming-accessories/ac/6488"
}

app = Flask(__name__)
# after run create_db.py, the database is created
# conn = sqlite3.connect('eneities.db')
# cursor = conn.cursor()
# command = 'insert into entity (Entity_Name,URL,ImagePath) VALUES (Entity_Name,URLString,ImagePath_String)'
# cursor.execute(command)
# cursor.close()
# conn.close()

api_key = os.environ.get("API_KEY")



headers = {
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": api_key
Expand Down Expand Up @@ -88,8 +57,9 @@ def get_task():
categories = set(categories)
links = []
for category in categories:
if category in link_lookup_table.keys():
links.append({"category":category,"link":link_lookup_table[category]})
row = retrieve(category)
if (row != None):
links.append({"category":row[0],"link":row[1]})
return {"category_links":links}
elif response.status_code == 200:
return Response(status=202,response={"response-status":response_status})
Expand Down
105 changes: 96 additions & 9 deletions Backend/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,93 @@

#Creates new database if one with the same name doesn't already exist
def create_table():
link_lookup_table = {
"Laptops and 2-in-1 PC": {
"url" : "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sc/laptops",
"image_path" : "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/page/category/laptop/xps/fy24-family-launch/prod-312204-laptop-xps-16-9640-14-9440-13-9340-sl-800x620.png?fmt=png-alpha&wid=640&hei=496"
},
"XPS": {
"url" : "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/xps-laptops",
"image_path" : "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/notebooks/xps-notebooks/xps-13-9320/media-gallery/xs9320t-cnb-00005ff090-sl-oled.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Latitude": {
"url" : "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/latitude-laptops",
"image_path" : "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/notebooks/latitude-notebooks/latitude-14-3440-laptop/media-gallery/notebook-latitude-14-3440-t-dgpu-ir-gray-gallery-12.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Inspiron": {
"url": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/inspiron-laptops",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/notebooks/inspiron-notebooks/16-7640/media-gallery-ai-key/fpr/laptop-inspiron-16-plus-7640nt-bl-dis-fpr-ai-key-gallery-2.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Vostro": {
"url": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/vostro-laptops",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/notebooks/vostro-notebooks/vostro-15-3520/media-gallery/black/notebook-vostro-15-3520-gallery-3.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Alienware": {
"url": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/alienware-laptops",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/notebooks/alienware-notebooks/alienware-m16-r2-intel/media-gallery/laptop-aw-m16r2-nt-bk-gallery-3.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Precision": {
"url": "https://www.dell.com/en-ie/shop/laptop-computers-2-in-1-pcs/sr/laptops/precision-laptops",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/workstations/mobile-workstations/precision/15-3581/media-gallery/workstation-notebook-precision-15-3581-gray-gallery-2.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Desktops": {
"url": "https://www.dell.com/en-ie/shop/desktop-computers/sc/desktops",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/desktops/optiplex-desktops/optiplex-d13-tower/spi/7010-tower-plus/prod/prod-275100-desktop-optiplex-7010-plus-mt-800x550.png?fmt=png-alpha&wid=800&hei=550"
},
"OptiPlex": {
"url": "https://www.dell.com/en-ie/shop/desktop-computers/sr/desktops/optiplex-desktops",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/page/banners/optiplex-d13-module-banner-desktop-1023x842.png?qlt=95&fit=constrain,1&hei=800&wid=620&fmt=png-alpha"
},
"Monitors": {
"url": "https://www.dell.com/en-ie/shop/computer-monitors/ar/8605",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/page/category/desktop/dbcs-255750-aio-desktop-optiplex-7410-keyboard-mouse-km7321w-inspiron-27-7710-km5221w-800x620.png?fmt=png-alpha&wid=640&hei=496"
},
"Docking Stations": {
"url": "https://www.dell.com/en-ie/shop/docks-and-stands/ar/5441/docking-stations?appliedRefinements=962",
"image_path": "https://i.dell.com/is/image/DellContent//content/dam/images/products/electronics-and-accessories/dell/docks-and-stands/wd19s-130w/wd19s-130w-gnb-shot04-bk-singleusbc.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Audio": {
"url": "https://www.dell.com/en-ie/shop/audio/ac/8310",
"image_path": "https://i.dell.com/is/image/DellContent/bb2303g0045-676544-gl-bb-fy23q4-site-banner-wh5024-wl5024-800x620"
},
"Keyboards and Mice": {
"url": "https://www.dell.com/en-ie/shop/keyboards-mice/ar/6591",
"image_path": "https://i.dell.com/is/image/DellContent//content/dam/ss2/product-images/peripherals/input-devices/dell/keyboards/km7321w/pdp/dell-keyboard-mouse-km7321w-pdp-campaign-hero-504x350.jpg?fmt=jpg&wid=504&hei=350"
},
"Hard Drives, SSDs and Storage": {
"url": "https://www.dell.com/en-ie/shop/hard-drives-storage/ar/8496",
"image_path": "https://snpi.dell.com/snp/images/products/large/en-ie~400-BKFK_V1/400-BKFK_V1.jpg"
},
"Webcams and Video Conferencing": {
"url": "https://www.dell.com/en-ie/shop/web-cameras/ar/8332",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/dell-client-products/peripherals/webcams/wb5023-dell-pro-webcam/media-gallery/webcam-wb5023-black-gallery-1-zoom.psd?qlt=90,0&op_usm=1.75,0.3,2,0&resMode=sharp&pscan=auto&fmt=png-alpha&hei=500"
},
"Batteries, Chargers and Power Adapters": {
"url": "https://www.dell.com/en-ie/shop/pc-accessories/ar/5436/batteries-chargers-power-adapters?appliedRefinements=44426",
"image_path": "https://snpi.dell.com/snp/images/products/large/en-ie~492-BBSC_V3/492-BBSC_V3.jpg"
},
"Cables and Adapters": {
"url": "https://www.dell.com/en-ie/shop/cables/ar/8168/cables-adapters?appliedRefinements=44427",
"image_path": "https://snpi.dell.com/snp/images/products/large/en-ie~470-AEGY/470-AEGY.jpg"
},
"Security and Protection": {
"url": "https://www.dell.com/en-ie/shop/security-protection/ar/7664",
"image_path": "https://snpi.dell.com/snp/images/products/large/en-ie~461-AAFB_V2/461-AAFB_V2.jpg"
},
"Parts, Batteries and Upgrades": {
"url": "https://www.dell.com/en-ie/shop/parts-batteries-upgrades/ar/7566",
"image_path": "https://snpi.dell.com/snp/images/products/large/en-ie~161-BBUS/161-BBUS.jpg"
},
"Wi-Fi and Networking": {
"url": "https://www.dell.com/en-ie/shop/wifi-and-networking/ar/4011",
"image_path": "https://snpi.dell.com/snp/images/products/large/en-ie~470-AEUP/470-AEUP.jpg"
},
"Gaming Accessories": {
"url": "https://www.dell.com/en-ie/shop/gaming-gaming-accessories/ac/6488",
"image_path": "https://i.dell.com/is/image/DellContent/content/dam/documents-and-videos/dv2/csbg/en/product-launch/alienware/alienware-pro-wireless-gaming-peripherals/site-banners/keyboard/black/cs2404g0010-680531-gl-cs-co-site-banner-aw-pro-keyboard-800x620-bk-right-transparent.png"
}
}

conn = sqlite3.connect('test.db')
cur = conn.cursor()

Expand All @@ -14,6 +101,8 @@ def create_table():
)
'''
cur.execute(sql)
for key, item in link_lookup_table.items():
insert(key,item['url'],item.get('image_path', ''), "")
conn.commit()
conn.close()

Expand All @@ -33,16 +122,14 @@ def retrieve(name):
cur.execute('''SELECT * FROM TestTable WHERE name = ?''', (name,))
row = cur.fetchone()
conn.close()
return row
if row == None : return None
res = []
for element in row:
res.append(element)
return res

if __name__ == "__main__":
create_table()

create_table()

insert("Laptop", "https://examplelaptop.com", "/path/to/image.jpg", "this is a laptop")
insert("Monitor", "https://examplemonitor.com", "/path/to/image2.jpg", "this is a monitor")
insert("Adapter", "https://exampleadapter.com", "/path/to/image3.jpg", "this is an adapter")


TestTable = retrieve("Adapter")
for entity in TestTable:
print(entity)
Binary file modified Backend/test.db
Binary file not shown.
24 changes: 0 additions & 24 deletions Frontend/app/SPL/.gitignore

This file was deleted.

Loading
Loading