Skip to content

Commit

Permalink
Added scraped prices from Wikipedia
Browse files Browse the repository at this point in the history
Wrote a script and scraped the prices from the Wikipedia page.
  • Loading branch information
UltimateDoge5 committed May 3, 2023
1 parent 17c1c7c commit 081870a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
45 changes: 45 additions & 0 deletions src/util/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,51 @@ export const AMD_PRODUCTS = [
{ name: "AMD EPYC 7251", url: "https://www.amd.com/en/product/2006" },
];

/**
* Scraped list of all AMD Ryzen cpu prices from Wikipedia.
*/

export const AMD_PRICES =
{
"ryzen 5 1600x": 249,
"ryzen 5 1600": 219,
"ryzen 5 1500x": 189,
"ryzen 5 1400": 169,
"ryzen 3 1300x": 129,
"ryzen 3 1200": 109,
"ryzen 3 2200g": 99,
"ryzen 5 2600x": 229,
"ryzen 5 2600": 199,
"ryzen 5 1600 (af)": 85,
"ryzen 7 3800xt": 399,
"ryzen 7 3800x": 399,
"ryzen 7 3700x": 399,
"ryzen 5 3600xt": 399,
"ryzen 5 3600x": 399,
"ryzen 5 3600": 399,
"ryzen 5 3500x": 399,
"ryzen 5 3500": 399,
"ryzen 3 3300x": 399,
"ryzen 3 3100": 399,
"ryzen threadripper 3990x": 3990,
"ryzen threadripper 3970x": 1999,
"ryzen threadripper 3960x": 1399,
"ryzen 3 4100": 99,
"ryzen 5 4600g": 154,
"ryzen 7 5800x3d": 449,
"ryzen 7 5800x": 449,
"ryzen 7 5700x": 299,
"ryzen 5 5600x": 299,
"ryzen 5 5600": 299,
"ryzen 5 5500": 299,
"ryzen 5 5600g": 259,
"ryzen 7 7800x3d": 449,
"ryzen 7 7700x": 399,
"ryzen 7 7700": 329,
"ryzen 5 7600x": 299,
"ryzen 5 7600": 229,
}

/**
* Scraped list of all Intel core cpus from Wikipedia.
*/
Expand Down
13 changes: 9 additions & 4 deletions src/util/scrapers/amd.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CheerioAPI } from "cheerio";
import { load } from "cheerio";
import type { CPU, Memory } from "../../../CPU";
import { AMD_PRODUCTS } from "../products";
import { AMD_PRICES, AMD_PRODUCTS } from "../products";
import { normaliseMarket } from "../formatting";
import elementSelector from "../selectors";
import { Redis } from "@upstash/redis";
Expand Down Expand Up @@ -30,6 +30,9 @@ const scrapeAMD = async (model: string, noCache: boolean) =>
url: url,
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36",
gotoOptions: {
waitUntil: "domcontentloaded",
},
}),
headers: {
"Content-Type": "application/json",
Expand All @@ -48,12 +51,14 @@ const scrapeAMD = async (model: string, noCache: boolean) =>
// eslint-disable-next-line prefer-const
$ = load(await specsPage.text());

// Get the msrp before model name change
const msrp = AMD_PRICES[model.replace("amd", "").trim() as keyof typeof AMD_PRICES] || null;
model = model.replace(/ /g, "-").toLowerCase();

cpu = {
name: $(".section-title").text().trim(),
manufacturer: "amd",
MSRP: null,
MSRP: msrp,
marketSegment: normaliseMarket(getParameter("Platform")),
cores: {
total: getFloatParameter("# of CPU Cores"),
Expand Down Expand Up @@ -123,9 +128,9 @@ const getLaunchDate = (string: string) => {
if (!string) return "Unknown";
if (/Q\d \d{4}/.test(string)) return string;

// 7/2020
// Format: 7/2020
// https://www.amd.com/en/product/9936
if(/\d\/\d{4}/.test(string)) {
if (/\d\/\d{4}/.test(string)) {
const [month, year] = string.split("/");
const quarter = Math.floor((parseInt(month) + 1) / 3) + 1;
return `Q${quarter}'${year.substring(2)}`;
Expand Down
2 changes: 1 addition & 1 deletion tests/cpus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ test(
const cpu = await scrapeAMD("amd ryzen 5 3600", true);
expect(cpu != null).toBe(true);
},
{ timeout: 10000 }
{ timeout: 15000 }
);

1 comment on commit 081870a

@vercel
Copy link

@vercel vercel bot commented on 081870a May 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.