summaryrefslogtreecommitdiff
path: root/src/gather.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/gather.ts')
-rw-r--r--src/gather.ts111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/gather.ts b/src/gather.ts
new file mode 100644
index 0000000..7252418
--- /dev/null
+++ b/src/gather.ts
@@ -0,0 +1,111 @@
+
+export interface ProductInfo {
+ productId: string,
+ companyName: string,
+ productName: string,
+ price: number,
+ accessDate: string,
+ picture: string | null
+
+}
+
+interface WooliesResponse {
+ Product: {
+ Stockcode: number,
+ DisplayName: string,
+ Price: number,
+ LargeImageFile: string
+ }
+}
+
+interface ColesResponse {
+ pricing: {
+ now: number,
+ }
+ id: number,
+ name: string,
+ imageUris: [{
+ uri: string
+ }]
+}
+
+// const COLES_ROOT_URL = "apigw.coles.com.au"
+// const WOOLIES_ROOT_URL = "www.woolworths.com.au"
+
+const COLES_ROOT_URL = "localhost:3002"
+const WOOLIES_ROOT_URL = "localhost:3002"
+
+
+
+export async function fetchWooliesProduct(productID: string): Promise<ProductInfo | null> {
+ const options = {
+ method: 'GET',
+ // credentials: 'include',
+ headers: {
+ 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0',
+ "Cookie": '_abck=8D926507FE8BB3E2030100E0A40908AD~-1~YAAQDV8wF4yrp+WKAQAAcBa1+QqOLH6Cr1PPGhoBK6dzldNoO6fT9E5Yh2JWjug69wmscVVDCxTl3AtqhLO700yB1l/aMekoSEMfXWdB1vAkiaNMKVPNjc+x4hh7Yon6NLceF4NYulFEKqcjo1BEgGtnYYv8xgJW0jcO0i4kIdNAZaszCrXxefAMTskVsvWcZvmAuqcLr72EmDY6BNBSCQgzm2KX4uAM7D79DQVKY5TDR79ITzKmCZghdYGdNrXtSxksNB8rllTWUT+5UD45fpB13jYdxmwy6Lu51gBNuYrQ/lmQuJdFIzc3czVYvQI64uDlWbA17Swz/9En3cCF0/IGtuAUx/6PfJVfAdFyfZrcD3d7Sl+vdzlhiZ3smo/1/ocITzZggDurPckyVMvy5DPmZDx1mwvkn83yOt0cP7c=~-1~-1~-1;'
+ }
+
+
+ };
+
+ const url = `http://${WOOLIES_ROOT_URL}/apis/ui/product/detail/${productID}?isMobile=false&useVariant=false`
+ const response = fetch(url, options)
+ // .json()
+ // .then(response => console.log(response))
+ .then(response => response.json())
+ .then(x => {console.log(url, x); return x})
+ .then(data => data as WooliesResponse)
+ .then(formatWooliesProduct)
+ // .catch(err => console.error(err));
+
+ return response
+}
+
+export async function fetchColesProduct(productID: string): Promise<ProductInfo | null> {
+ const options = {
+ method: 'GET',
+ headers: {
+ 'Ocp-Apim-Subscription-Key': 'dd6ae58532d743978508555a59a199ac',
+ 'User-Agent': 'okhttp/4.10.0'
+ }
+ };
+
+ const url = `https://${COLES_ROOT_URL}/digital/colesappbff/v3/api/2/products/${productID}?type=sku&storeId=697&shoppingMethod=clickAndCollect&includeLiquor=true`
+ // const url = `http://localhost:3002/apis/ui/product/detail/${productID}?isMobile=false&useVariant=false`
+ const response = fetch(url, options)
+ // .json()
+ // .then(response => console.log(response))
+ .then(x => {console.log(x); return x})
+ .then(response => response.json())
+ .then(data => data as WooliesResponse)
+ .then(formatWooliesProduct)
+ // .catch(err => console.error(err));
+
+ return response
+}
+
+
+function formatWooliesProduct(json: WooliesResponse): ProductInfo {
+ const data = json.Product
+ return {
+ "productId": String(data.Stockcode),
+ "companyName": "Woolies",
+ "productName": data.DisplayName,
+ "price": data.Price,
+ "accessDate": String(Date.now()),
+ "picture": data.LargeImageFile
+ }
+}
+
+
+function formatColesProduct(json: ColesResponse): ProductInfo {
+ return {
+ "productId": String(json.id),
+ "companyName": "Coles",
+ "productName": json.name,
+ "price": json.pricing.now,
+ "accessDate": String(Date.now()),
+ "picture": json.imageUris[0]?.uri
+ }
+} \ No newline at end of file