Skip to content
Permalink
Browse files

Change default review count and update demo

  • Loading branch information...
grikomsn committed Feb 13, 2019
1 parent 7c86719 commit 4c0ad3393d6d5781135da864af2064687e25b1db
Showing with 22 additions and 21 deletions.
  1. +1 −1 README.md
  2. +4 −3 demo/index.js
  3. +0 −11 demo/now.json
  4. +10 −0 now.json
  5. +7 −6 src/index.ts
@@ -139,7 +139,7 @@ Example queries:

- [`rotten-lambda.now.sh/?q=spider%20verse`](https://rotten-lambda.now.sh/?q=spider%20verse) to search titles
- [`rotten-lambda.now.sh/?s=m/venom_2018`](https://rotten-lambda.now.sh/?s=m/venom_2018) to scrape reviews
- [`rotten-lambda.now.sh/?s=m/venom_2018&c=3`](https://rotten-lambda.now.sh/?s=m/venom_2018) to scrape only 3 first reviews
- [`rotten-lambda.now.sh/?s=m/venom_2018&c=3`](https://rotten-lambda.now.sh/?s=m/venom_2018&c=3) to scrape only 3 first reviews

You can view the source code for the deployment on the [demo directory](demo) or on the [deployment source page](https://rotten-lambda.now.sh/_src).

@@ -7,9 +7,9 @@ const { searchByQuery, scrapeReviews } = require('rotten-reviews')
*/
module.exports = async (req, res) => {
const { query } = parse(req.url, true)
const { s = null, c = 10, q = null } = query
const { s = null, q = null, c = undefined } = query

if (s && c) {
if (s) {
const results = await scrapeReviews(s, c)
res.end(JSON.stringify(results, null, 2))
return
@@ -22,7 +22,8 @@ module.exports = async (req, res) => {
}

res.writeHead(301, {
Location: 'https://github.com/ninetwenty-one/rotten-reviews',
Location:
'https://github.com/ninetwenty-one/rotten-reviews#lambda-deployment',
})
res.end()
}

This file was deleted.

@@ -0,0 +1,10 @@
{
"version": 2,
"name": "rotten-lambda",
"alias": ["rotten-lambda.now.sh", "rotten-reviews.now.sh"],
"builds": [{ "src": "demo/index.js", "use": "@now/node" }],
"github": { "enabled": true, "autoAlias": true },
"public": true,
"regions": ["all"],
"routes": [{ "src": "/.*", "dest": "/demo" }]
}
@@ -115,15 +115,16 @@ export async function scrapeFromPageUrl(url: string) {
export async function scrapeReviews(slug: string, desiredReviewCount?: number) {
const reviewCount =
typeof desiredReviewCount === 'undefined'
? MAX_REVIEWS_PER_PAGE
: Math.max(
MAX_REVIEWS_PER_PAGE,
Math.min(desiredReviewCount, MAX_TOTAL_REVIEWS)
)
? MAX_TOTAL_REVIEWS
: desiredReviewCount

if (reviewCount <= 0) {
throw new Error('Given review count is invalid')
}

const pageCount = Math.ceil(reviewCount / MAX_REVIEWS_PER_PAGE)

const pagesReviews: ScrapeResult[][] = await Promise.all(
const pagesReviews = await Promise.all(
Array.from(Array(pageCount), (x, i) => {
const url = createUrlFromSlug(slug, i)
return scrapeFromPageUrl(url)

0 comments on commit 4c0ad33

Please sign in to comment.
You can’t perform that action at this time.