Skip to content

Fixed Codechef Parser #7

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/parsers/codechef.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
const axios = require('axios');
const cheerio = require('cheerio');

function parseContestDetails($, contestRow) {
const details = $(contestRow).find('td');
const startTime = new Date(details.eq(2).attr("data-starttime")).getTime() / 1000;
const endTime = new Date(details.eq(3).attr("data-endtime")).getTime() / 1000;
function parseContestDetails(object) {
const cname = object.contest_name;
const code = object.contest_code;
const startTime = object.contest_start_date;
const endTime = object.contest_end_date;

return {
name: details.eq(1).text(),
url: `http://www.codechef.com${details.eq(1).find('a').attr('href')}`,
name: cname,
url: `https://www.codechef.com/${code}?itm_campaign=contest_listing`,
platform: 'codechef',
startTime,
endTime,
};
}

const codechef = () => axios.get('http://www.codechef.com/contests', { timeout: 30000 })
const codechef = () => axios.get('https://www.codechef.com/api/list/contests/all?sort_by=END&sorting_order=desc&offset=0', { timeout: 30000 })
.then((response) => {
const $ = cheerio.load(response.data);
const statusdiv = $('table .dataTable');
const headings = $('h2');
const contestTables = { 'Upcoming Coding Contests': [], 'Present Coding Contests': [] };

for (let i = 0; i < headings.length; i++) {
if (headings.eq(i).text() !== 'Past Coding Contests') {
contestTables[headings.eq(i).text()] = statusdiv.eq(i).find('tr').slice(1);
}
}
let contests = contestTables['Present Coding Contests'].map((i, elem) => parseContestDetails($, elem)).get();

contests = contests.concat(contestTables['Upcoming Coding Contests'].map((i, elem) => parseContestDetails($, elem)).get());

return contests;
response.data.present_contests.forEach(element => {
contestTables['Present Coding Contests'].push(parseContestDetails(element));
});
response.data.future_contests.forEach(element => {
contestTables['Upcoming Coding Contests'].push(parseContestDetails(element));
});
return contestTables;
})
.catch((error) => {
console.log('Codechef: ', error.toString());
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy