-
Notifications
You must be signed in to change notification settings - Fork 9.4k
feat(route): Add routes for ebay #21323
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
Open
phoeagon
wants to merge
10
commits into
DIYgod:master
Choose a base branch
from
phoeagon:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−0
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cfc0cab
add ebay user/search routes
phoeagon d3ff772
updated ebay routes according to standard
phoeagon f5ad403
update ebay routes according to presubmit finding
phoeagon 449def2
update import order
phoeagon ec93a56
updates according to autofindings
phoeagon 878edce
clean up .DS_Store
phoeagon edf35d0
fix category
phoeagon 826359a
update ebay routes according to review comments
phoeagon a99c86c
fix ebay/search parsing
phoeagon 1233ae7
minor changes to radar config, ebay/search extraction, etc
phoeagon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This 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 characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'eBay', | ||
| url: 'ebay.com', | ||
| categories: ['shopping'], | ||
| description: 'eBay search results and user listings.', | ||
| }; |
This 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 characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { Route } from '@/types'; | ||
|
||
| import { load } from 'cheerio'; | ||
|
||
| import ofetch from '@/utils/ofetch'; | ||
| import logger from '@/utils/logger'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/search/:keywords', | ||
| categories: ['shopping'], | ||
| example: '/ebay/search/sodimm+ddr4+16gb', | ||
| parameters: { keywords: 'Keywords for search' }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['ebay.com/sch/i.html'], | ||
| target: (params, url) => { | ||
| const searchKeywords = new URL(url).searchParams.get('_nkw'); | ||
| return `/search/${searchKeywords}`; | ||
| }, | ||
| }, | ||
| ], | ||
| name: 'Search Results', | ||
| maintainers: ['phoeagon'], | ||
| handler: async (ctx) => { | ||
| const { keywords } = ctx.req.param(); | ||
| const url = `https://www.ebay.com/sch/i.html?_nkw=${encodeURIComponent(keywords)}&_sop=10&_ipg=240`; | ||
|
|
||
| logger.info(`Fetching eBay search results: ${url}`); | ||
TonyRL marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const response = await ofetch(url); | ||
| logger.info(`eBay response status: ${response instanceof Response ? response.status : 'unknown'}`); | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const $ = load(response); | ||
|
|
||
| const items = $('.s-item, .s-card, .s-item__wrapper.clearfix') | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .toArray() | ||
| .map((item) => { | ||
| const $item = $(item); | ||
| const titleElement = $item.find('.s-item__title, .s-card__title, .s-item__title--has-tags'); | ||
| const title = titleElement.text().replace(/^New Listing/i, '').trim(); | ||
| const link = $item.find('.s-item__link, .s-card__link').attr('href'); | ||
| const price = $item.find('.s-item__price, .s-card__price').text().trim(); | ||
| const image = | ||
| $item.find('.s-item__image-img img, img.s-item__image-img').attr('src') || | ||
| $item.find('.s-item__image-wrapper img').attr('src') || | ||
| $item.find('.s-card__image-img img').attr('src') || | ||
| $item.find('.s-item__image img').attr('src'); | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!title || !link || title.toLowerCase().includes('shop on ebay') || price === '') { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| title: `${title} - ${price}`, | ||
| link, | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: `<img src="${image}"><br>Price: ${price}`, | ||
| category: 'eBay Search', | ||
| }; | ||
| }) | ||
| .filter(Boolean); | ||
|
|
||
| logger.info(`Found ${items.length} items on eBay`); | ||
|
|
||
| return { | ||
| title: `eBay Search: ${keywords}`, | ||
| link: url, | ||
| item: items, | ||
| }; | ||
| }, | ||
| }; | ||
This 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 characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { Route } from '@/types'; | ||
|
||
| import { load } from 'cheerio'; | ||
|
||
| import ofetch from '@/utils/ofetch'; | ||
|
|
||
| export const route: Route = { | ||
| path: ['/usr/:username', '/user/:username'], | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| categories: ['shopping'], | ||
| example: '/ebay/usr/m.trotters', | ||
| parameters: { username: 'Username of the seller' }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['ebay.com/usr/:username'], | ||
| target: '/user/:username', | ||
| }, | ||
| ], | ||
| name: 'User Listings', | ||
| maintainers: ['phoeagon'], | ||
| handler: async (ctx) => { | ||
| const { username } = ctx.req.param(); | ||
| const url = `https://www.ebay.com/usr/${username}`; | ||
|
|
||
| const response = await ofetch(url); | ||
| const $ = load(response); | ||
|
|
||
| const items = $('article.str-item-card.StoreFrontItemCard') | ||
| .toArray() | ||
| .map((item) => { | ||
| const $item = $(item); | ||
| const title = $item.find('.str-card-title .str-text-span').first().text().trim(); | ||
| const link = $item.find('.str-item-card__link').attr('href'); | ||
| const price = $item.find('.str-item-card__property-displayPrice').text().trim(); | ||
| const image = $item.find('.str-image img').attr('src'); | ||
|
|
||
| if (!title || !link) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| title: `${title} - ${price}`, | ||
| link, | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: `<img src="${image}"><br>Price: ${price}`, | ||
| author: username, | ||
| }; | ||
| }) | ||
| .filter(Boolean); | ||
|
|
||
| return { | ||
| title: `eBay User: ${username}`, | ||
| link: url, | ||
| item: items, | ||
| }; | ||
| }, | ||
| }; | ||
phoeagon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This 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 characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { CheerioAPI, Element } from 'cheerio'; | ||
|
||
|
|
||
| /** | ||
| * Transforms an eBay image URL to prefer WebP format if it's a JPG/JPEG. | ||
| * @param url The original image URL. | ||
| * @returns The transformed URL. | ||
| */ | ||
| export const transformImage = (url?: string): string | undefined => { | ||
| if (!url) { | ||
| return undefined; | ||
| } | ||
| // eBay images often look like https://i.ebayimg.com/images/g/.../s-l500.jpg | ||
| // Replacing .jpg with .webp usually works if s-lXXX is used. | ||
| return url.replace(/\.jpe?g$/i, '.webp'); | ||
| }; | ||
|
|
||
| /** | ||
| * Common item structure for eBay routes. | ||
| */ | ||
| export interface eBayItem { | ||
| title: string; | ||
| link: string; | ||
| description: string; | ||
| category?: string; | ||
| author?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Helper to extract common data from an eBay item element. | ||
| * Note: Since selectors vary, this might be less useful than specific logic in each route, | ||
| * but let's provide a way to standardize the output. | ||
| */ | ||
| export const createItem = (title: string, price: string, link: string, image?: string): eBayItem => ({ | ||
| title: `${title} - ${price}`, | ||
| link, | ||
| description: `<img src="${transformImage(image)}"><br>Price: ${price}`, | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.