Skip to content

Instantly share code, notes, and snippets.

@jhonber
Last active January 16, 2017 04:30
Show Gist options
  • Select an option

  • Save jhonber/7c339982f550b07398cbbdaffcc60d18 to your computer and use it in GitHub Desktop.

Select an option

Save jhonber/7c339982f550b07398cbbdaffcc60d18 to your computer and use it in GitHub Desktop.

Revisions

  1. jhonber revised this gist Jan 16, 2017. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions fetch-uri.js
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    // 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 0,
    // (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) {
    @@ -35,9 +35,10 @@ function get_url (id, tab, cb) {
    newTab.onload = function () {
    var ans = newTab.document.getElementsByClassName('dropbox-saver')[0].href;
    tab.opener.downloadURI(ans);
    newTab.close();
    setTimeout(function() {
    cb(null)},
    newTab.close();
    cb(null)
    },
    1000
    );
    };
    @@ -75,11 +76,11 @@ function fetch_page (page, cb) {
    }

    function go (i) {
    if (i > pages) {
    if (i == pages) {
    return;
    }
    else {
    fetch_page(i + 1, function (err) {
    fetch_page(i, function (err) {
    if (!err) {
    setTimeout(
    function () {
    @@ -94,4 +95,4 @@ function go (i) {
    }

    var pages = parseInt(document.getElementById('table-info').innerText.split(' ')[2]);
    go (0)
    go (1)
  2. jhonber revised this gist Jan 16, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fetch-uri.js
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@
    // 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,
    // (If you just want to do a little test, you can set the variable 'pages' equal to 0,
    // for download only 1 page)

    function downloadURI (uri) {
  3. jhonber revised this gist Jan 15, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions fetch-uri.js
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@
    // 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
    //
  4. jhonber revised this gist Jan 15, 2017. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions rename.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // 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);
    });
    }
    }
    }
    });
  5. jhonber revised this gist Jan 15, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion fetch-uri.js
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,6 @@ function fetch_page (page, cb) {

    }


    function go (i) {
    if (i > pages) {
    return;
  6. jhonber revised this gist Jan 15, 2017. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions fetch-uri.js
    Original file line number Diff line number Diff line change
    @@ -19,9 +19,8 @@
    // (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, name) {
    function downloadURI (uri) {
    var link = document.createElement('a');
    link.setAttribute('download', name);
    link.href = uri;
    document.body.appendChild(link);
    link.click();
    @@ -34,7 +33,7 @@ function get_url (id, tab, cb) {

    newTab.onload = function () {
    var ans = newTab.document.getElementsByClassName('dropbox-saver')[0].href;
    tab.opener.downloadURI(ans, '');
    tab.opener.downloadURI(ans);
    newTab.close();
    setTimeout(function() {
    cb(null)},
  7. jhonber created this gist Jan 15, 2017.
    98 changes: 98 additions & 0 deletions fetch-uri.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,98 @@
    // 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
    //
    // * 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, name) {
    var link = document.createElement('a');
    link.setAttribute('download', name);
    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, '');
    newTab.close();
    setTimeout(function() {
    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 + 1, function (err) {
    if (!err) {
    setTimeout(
    function () {
    go(i + 1);
    }, 1000);
    }
    else {
    return err;
    }
    });
    }
    }

    var pages = parseInt(document.getElementById('table-info').innerText.split(' ')[2]);
    go (0)