Skip to content

Instantly share code, notes, and snippets.

@jhonber
Last active January 16, 2017 04:30
Show Gist options
  • Save jhonber/7c339982f550b07398cbbdaffcc60d18 to your computer and use it in GitHub Desktop.
Save jhonber/7c339982f550b07398cbbdaffcc60d18 to your computer and use it in GitHub Desktop.
Get your Accepted submissions from URI http://www.urionlinejudge.com.br
// Get your Accepted submissions from URI www.urionlinejudge.com.br, the submissions
// are stored in downloads directory
//
// (** Required latest version of Firefox / Google chrome)
//
// Instructions:
// 1) Login www.urionlinejudge.com.br
// 2) Go to https://www.urionlinejudge.com.br/judge/en/runs?answer_id=1
// 3) (** Important **) Configure automatic download in your browser (without ask)
// Otherwise you will need to do click in download popup for every submission
//
// 4) Open the browser console and excecute this code
// 5) After download, if you want to rename the files see 'rename.js'
//
// * The download rate is approximately 1 submission every 2 seconds
//
// Note: The delay in get_url() is necessary because URI blocks many requests
// per second
//
// (If you just want to do a little test, you can set the variable 'pages' equal to 1,
// for download only 1 page)
function downloadURI (uri) {
var link = document.createElement('a');
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function get_url (id, tab, cb) {
var url = 'https://www.urionlinejudge.com.br/judge/en/runs/code/' + id
var newTab = window.open(url, '_blank');
newTab.onload = function () {
var ans = newTab.document.getElementsByClassName('dropbox-saver')[0].href;
tab.opener.downloadURI(ans);
setTimeout(function() {
newTab.close();
cb(null)
},
1000
);
};
}
function fetch_page (page, cb) {
var url = 'https://www.urionlinejudge.com.br/judge/en/runs?answer_id=1&page=' + page;
var newTab = window.open(url, '_blank');
newTab.onload = function () {
var sub_ids = newTab.document.getElementsByClassName('id');
function go (i) {
if (i == sub_ids.length) {
newTab.close();
cb(null)
return;
}
else {
var id = sub_ids[i].innerText;
newTab.opener.get_url(id, newTab, function (err) {
if (!err) {
go(i + 1);
}
else {
return err;
}
});
}
}
go(0)
};
}
function go (i) {
if (i == pages) {
return;
}
else {
fetch_page(i, function (err) {
if (!err) {
setTimeout(
function () {
go(i + 1);
}, 1000);
}
else {
return err;
}
});
}
}
var pages = parseInt(document.getElementById('table-info').innerText.split(' ')[2]);
go (1)
// Rename file like 'UOJ_2235 - (5859660) Accepted.cpp' to '2235.cpp'
var fs = require('fs'),
exec = require('child_process').exec;
fs.readdir('./', function (err, files) {
if (err) console.log(err);
else {
for (var i = 0; i < files.length; ++i) {
var cur = files[i];
var id = cur.split(' ')[0].split('_')[1];
var ext = cur.split('.')[1]
var name = id + '.' + ext;
if (id) {
var cmd = 'mv "' + cur + '" ' + name;
exec(cmd, function (err, stdout, stderr) {
if (err) console.log(err);
});
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment