Created
June 26, 2020 15:37
-
-
Save neolee/1c901f886fbd9ebac6a300e7aff083c8 to your computer and use it in GitHub Desktop.
This file contains 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
require('console-stamp')(console, '[HH:MM:ss.l]') | |
const request = require('request') | |
const categories = [4754, 4755, 4756, 4635, 4634, 4620, 4892, 4621, 4622] | |
function getData(id) { | |
console.log("Started fetching courses in category " + id) | |
let url = `https://www.genshuixue.com/sapi/channel/list?topChannelId=${id}&secondChannelId=${id}&thirdChannelId=all` | |
return new Promise((resolve, reject) => { | |
request(url, (error, response, body) => { | |
if (error) reject(error) | |
if (response.statusCode != 200) { | |
reject(`Response error, status code=<${response.statusCode}>`) | |
} | |
resolve(JSON.parse(body)) | |
}) | |
}) | |
} | |
categories.forEach(function (value, index) { | |
getData(value).then((result) => { | |
total = result.data.pager.total | |
console.log("Completed id=" + value + " and fetched " + total + " courses") | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running result: