Last active
          May 21, 2024 03:45 
        
      - 
      
- 
        Save tdtgit/ca2fa57c0f0aca35235e77b31b53d35d to your computer and use it in GitHub Desktop. 
Revisions
- 
        tdtgit revised this gist May 21, 2024 . 1 changed file with 18 additions and 4 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,9 +33,23 @@ async function fetchOrderDetails(orderID) { // Function to fetch order data from the API async function fetchOrderData() { let orders = []; let searchPage = 1; let hasMoreData = true; while (hasMoreData) { const url = `https://www.uniqlo.com/vn/api/commerce/v3/vi/orders?searchPage=${searchPage}&displayResults=10`; const orderData = await fetchData(url); if (orderData && orderData.orders.length > 0) { orders = [...orders, ...orderData.orders]; searchPage++; } else { hasMoreData = false; } } return orders; } // Function to delay execution @@ -67,4 +81,4 @@ async function processOrderData() { } // Call the function to start processing order data and calculating the total spent processOrderData(); 
- 
        tdtgit revised this gist May 21, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ async function fetchOrderDetails(orderID) { // Function to fetch order data from the API async function fetchOrderData() { const url = `https://www.uniqlo.com/vn/api/commerce/v3/vi/orders?searchPage=1&displayResults=5`; const orderData = await fetchData(url); return orderData ? orderData.orders : []; } 
- 
        tdtgit revised this gist Aug 3, 2023 . 1 changed file with 27 additions and 40 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,54 +6,36 @@ function formatCurrency(amount, currencyCode) { }).format(amount); } // Function to fetch data from a URL and handle errors async function fetchData(url) { try { const response = await fetch(url); if (!response.ok) { throw new Error(`Error fetching data from ${url}`); } const data = await response.json(); if (data.status !== 'ok') { throw new Error(`Error in data response from ${url}`); } return data.result; } catch (error) { console.error('An error occurred:', error); return null; } } // Function to fetch order details using the order ID async function fetchOrderDetails(orderID) { const url = `https://www.uniqlo.com/vn/api/commerce/v3/vi/orders/${orderID}`; const orderDetail = await fetchData(url); return orderDetail ? orderDetail.orderDetail : null; } // Function to fetch order data from the API async function fetchOrderData() { const url = `https://www.uniqlo.com/vn/api/commerce/v3/vi/orders?searchPage=1&displayResults=50`; const orderData = await fetchData(url); return orderData ? orderData.orders : []; } // Function to delay execution @@ -69,14 +51,19 @@ async function processOrderData() { for (const order of orders) { const orderDetails = await fetchOrderDetails(order.no); if (orderDetails) { const orderDate = new Date(orderDetails.createdDatetime * 1000).toLocaleString(); const orderValue = orderDetails.totalAmountTaxIncluded.value; console.log(`Processing order: ${orderDate} - Value: ${formatCurrency(orderValue, 'VND')}`); totalSpent += orderValue; } await delay(500); // Add a delay of 0.5 seconds between requests } const formattedTotalSpent = formatCurrency(totalSpent, 'VND'); console.log(`%cTotal Spent on Uniqlo.com: %c${formattedTotalSpent}`, 'font-weight: bold; font-size: 24px;', 'font-weight: bold; color: green; font-size: 24px;'); } // Call the function to start processing order data and calculating the total spent 
- 
        tdtgit revised this gist Aug 2, 2023 . No changes.There are no files selected for viewing
- 
        tdtgit revised this gist Aug 2, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,7 +76,7 @@ async function processOrderData() { } const formattedTotalSpent = formatCurrency(totalSpent, 'VND'); console.log(`%cTotal Spent on Uniqlo.com: %c${formattedTotalSpent}`, 'font-weight: bold;font-size: 24px', 'font-weight: bold; color: green;font-size: 24px'); } // Call the function to start processing order data and calculating the total spent 
- 
        tdtgit created this gist Aug 2, 2023 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,83 @@ // Function to format a number as currency function formatCurrency(amount, currencyCode) { return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: currencyCode, }).format(amount); } // Function to fetch order details using the order ID async function fetchOrderDetails(orderID) { const url = `https://www.uniqlo.com/vn/api/commerce/v3/vi/orders/${orderID}`; try { const response = await fetch(url); if (response.ok) { const data = await response.json(); if (data.status === 'ok' && data.result && data.result.orderDetail) { return data.result.orderDetail; } else { console.log(`Error parsing order details for order ID ${orderID}`); } } else { console.log(`Error fetching order details for order ID ${orderID}`); } } catch (error) { console.error('An error occurred:', error); } return null; } // Function to fetch order data from the API async function fetchOrderData() { const url = `https://www.uniqlo.com/vn/api/commerce/v3/vi/orders?searchPage=1&displayResults=50`; try { const response = await fetch(url); if (response.ok) { const data = await response.json(); if (data.status === 'ok' && data.result && data.result.orders) { return data.result.orders; } else { console.log('Error parsing order data'); } } else { console.log('Error fetching order data'); } } catch (error) { console.error('An error occurred:', error); } return []; } // Function to delay execution function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // Function to loop through order data, fetch order details, and calculate the total spent async function processOrderData() { const orders = await fetchOrderData(); let totalSpent = 0; for (const order of orders) { const orderDetails = await fetchOrderDetails(order.no); if (orderDetails) { totalSpent += orderDetails.totalAmountTaxIncluded.value; } await delay(500); // Add a delay of 1 second between requests } const formattedTotalSpent = formatCurrency(totalSpent, 'VND'); console.log(`%cTotal Spent on Uniqlo.com: %c${formattedTotalSpent}`, 'font-weight: bold;', 'font-weight: bold; color: green;'); } // Call the function to start processing order data and calculating the total spent processOrderData();