Skip to content

Commit

Permalink
Added debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtoszBart committed Jun 10, 2024
1 parent 5b12514 commit 8dd0262
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/app/api/scrape/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export async function GET(req: any) {
const items: Item[] = (await getItems()) as Item[];
const newData: Data[] = [];

console.log(`Scraping ${items.length} items`);
console.log('============================================================');
console.log(`Scraping ${items.length} items:`);
items.forEach((i) => console.log(i.id));
console.log('============================================================');

await Promise.all(
items.map(async (item) => {
Expand Down
1 change: 1 addition & 0 deletions src/repository/postgres/dataRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const insertData = async (data: Data[]) => {
}),`;
});
query = query.replace(/.$/, ';');
console.log(query);

const result = await db.query(query, values);
return result;
Expand Down
5 changes: 5 additions & 0 deletions src/repository/postgres/itemRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const getItems = async (): Promise<Item[]> => {
);
});

console.log('============================================================');
console.log('Repo got items:');
items.forEach((i) => console.log(i.id));
console.log('============================================================');

return items;
};

Expand Down
8 changes: 7 additions & 1 deletion src/utils/scraping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Item from '@/models/Item';
import Vendor from '@/models/Vendor';

export function scrape(item: Item): Promise<Data> {
console.log('Scraping: ', item.id);

switch ((item.vendor as Vendor).id) {
case 1:
return scrapeMorele(item);
Expand All @@ -30,6 +32,7 @@ async function scrapeMorele(item: Item): Promise<Data> {
});

const data: Data = new Data(null, item, new Date(), price, null, null);
console.log(data);

return data;
} catch (error) {
Expand Down Expand Up @@ -103,12 +106,15 @@ async function scrapeAmazon(item: Item): Promise<Data> {
});
const availability: boolean = sum.length > 0;

return new Data(
const data: Data = new Data(
null,
item,
new Date(),
Math.min(...sum),
null,
availability
);
console.log(data);

return data;
}

0 comments on commit 8dd0262

Please sign in to comment.