Last active
August 2, 2019 09:36
-
-
Save srsbiz/1cd71dbe79369dd1682ddb2b2275a8e2 to your computer and use it in GitHub Desktop.
Skrypt do sprawdzenia statusu płatnika VAT w PhantomJS
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
/** | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions are met: | |
* | |
* * Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* * Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the distribution. | |
* * Neither the name of the <organization> nor the | |
* names of its contributors may be used to endorse or promote products | |
* derived from this software without specific prior written permission. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
"use strict"; | |
/** | |
* https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js | |
*/ | |
function waitFor(testFunction, readyFunction, timeOutMillis) { | |
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, | |
start = new Date().getTime(), | |
condition = false, | |
interval = setInterval(function() { | |
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) { | |
condition = (typeof(testFunction) === "string" ? eval(testFunction) : testFunction()); | |
} else { | |
if(!condition) { | |
phantom.exit(1); | |
} else { | |
typeof(readyFunction) === "string" ? eval(readyFunction) : readyFunction(); | |
clearInterval(interval); | |
} | |
} | |
}, 250); | |
}; | |
var system = require('system'), | |
args = system.args, | |
nip, | |
nieJest = "Podmiot o podanym identyfikatorze podatkowym NIP nie jest zarejestrowany jako podatnik VAT", | |
page = require('webpage').create(); | |
if (1 === args.length) { | |
console.log('NIP is required'); | |
phantom.exit(1); | |
} else { | |
nip = args[1]; | |
} | |
page.open('https://ppuslugi.mf.gov.pl/', function(status) { | |
if (status !== "success") { | |
console.log("Unable to access network"); | |
phantom.exit(); | |
} else { | |
waitFor(function(){ | |
return page.evaluate(function() { return $('#SidebarActions_WebUMn li').length > 0; }); | |
}, function(){ | |
page.evaluate(function() { | |
FWDC.executeAction(1005, null, 'FLOW'); | |
}); | |
waitFor(function(){ | |
return page.evaluate(function() { return $('#b-7').length > 0; }); | |
}, function(){ | |
page.evaluate(function(nip) { | |
$('#b-7').val(nip); | |
$('#b-8').trigger('click'); | |
}, nip); | |
waitFor(function(){ | |
return page.evaluate(function() { return $('#container_b-3').is(':visible'); }); | |
}, function() { | |
var msg = page.evaluate(function() { return $.trim($('#container_b-3').text()); }), | |
date = page.evaluate(function() { return $.trim($('#caption2_b-b').text().split(':')[1]).split('-').reverse().join('-'); }), | |
response = { | |
"nip": nip, | |
"msg": msg, | |
"date": date, | |
"status": msg == nieJest ? false : true | |
}; | |
system.stdout.write(JSON.stringify(response)); | |
phantom.exit(); | |
}); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/mmilch/SprawdzanieStatusuVATPodatnika