Skip to content

Instantly share code, notes, and snippets.

@lucas-pelton
Created October 6, 2017 17:03
Show Gist options
  • Save lucas-pelton/9415fb843795059665fd158ecbd2a4b5 to your computer and use it in GitHub Desktop.
Save lucas-pelton/9415fb843795059665fd158ecbd2a4b5 to your computer and use it in GitHub Desktop.
Artoo Data Scraper for Oregon Public Records
// include notify tool
!function(){function n(n,t){for(property in t)t.hasOwnProperty(property)&&(n[property]=t[property]);return n}function t(n,t){var e=document.createElement("div");e.className="notyf__toast";var o=document.createElement("div");o.className="notyf__wrapper";var i=document.createElement("div");i.className="notyf__icon";var a=document.createElement("i");a.className=t;var r=document.createElement("div");r.className="notyf__message",r.innerHTML=n,i.appendChild(a),o.appendChild(i),o.appendChild(r),e.appendChild(o);var c=this;return setTimeout(function(){e.className+=" notyf--disappear",e.addEventListener(c.animationEnd,function(n){n.target==e&&c.container.removeChild(e)});var n=c.notifications.indexOf(e);c.notifications.splice(n,1)},c.options.delay),e}function e(){var n,t=document.createElement("fake"),e={transition:"animationend",OTransition:"oAnimationEnd",MozTransition:"animationend",WebkitTransition:"webkitAnimationEnd"};for(n in e)if(void 0!==t.style[n])return e[n]}this.Notyf=function(){this.notifications=[];var t={delay:2e3,alertIcon:"notyf__icon--alert",confirmIcon:"notyf__icon--confirm"};arguments[0]&&"object"==typeof arguments[0]?this.options=n(t,arguments[0]):this.options=t;var o=document.createDocumentFragment(),i=document.createElement("div");i.className="notyf",o.appendChild(i),document.body.appendChild(o),this.container=i,this.animationEnd=e()},this.Notyf.prototype.alert=function(n){var e=t.call(this,n,this.options.alertIcon);e.className+=" notyf--alert",this.container.appendChild(e),this.notifications.push(e)},this.Notyf.prototype.confirm=function(n){var e=t.call(this,n,this.options.confirmIcon);e.className+=" notyf--confirm",this.container.appendChild(e),this.notifications.push(e)}}(),function(){"function"==typeof define&&define.amd?define("Notyf",function(){return Notyf}):"undefined"!=typeof module&&module.exports?module.exports=Notyf:window.Notyf=Notyf}();var style=document.createElement("style");style.type="text/css",style.innerHTML='@-webkit-keyframes a{0%{opacity:0;bottom:-15px;max-height:0;max-width:0;margin-top:0}30%{opacity:.8;bottom:-3px}to{opacity:1;bottom:0;max-height:200px;margin-top:12px;max-width:400px}}@keyframes a{0%{opacity:0;bottom:-15px;max-height:0;max-width:0;margin-top:0}30%{opacity:.8;bottom:-3px}to{opacity:1;bottom:0;max-height:200px;margin-top:12px;max-width:400px}}@-webkit-keyframes b{0%{opacity:1;bottom:0}30%{opacity:.2;bottom:-3px}to{opacity:0;bottom:-15px}}@keyframes b{0%{opacity:1;bottom:0}30%{opacity:.2;bottom:-3px}to{opacity:0;bottom:-15px}}@-webkit-keyframes c{0%{opacity:0}30%{opacity:.5}to{opacity:.6}}@keyframes c{0%{opacity:0}30%{opacity:.5}to{opacity:.6}}@-webkit-keyframes d{0%{opacity:.6}30%{opacity:.1}to{opacity:0}}@keyframes d{0%{opacity:.6}30%{opacity:.1}to{opacity:0}}.notyf__icon--alert,.notyf__icon--confirm{height:21px;width:21px;background:#fff;border-radius:50%;display:block;margin:0 auto;position:relative}.notyf__icon--alert:after,.notyf__icon--alert:before{content:"";background:#18D4F6;display:block;position:absolute;width:3px;border-radius:3px;left:9px}.notyf__icon--alert:after{height:3px;top:14px}.notyf__icon--alert:before{height:8px;top:4px}.notyf__icon--confirm:after,.notyf__icon--confirm:before{content:"";background:#3dc763;display:block;position:absolute;width:3px;border-radius:3px}.notyf__icon--confirm:after{height:6px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);top:9px;left:6px}.notyf__icon--confirm:before{height:11px;-webkit-transform:rotate(45deg);transform:rotate(45deg);top:5px;left:10px}.notyf__toast{display:block;overflow:hidden;-webkit-animation:a .3s forwards;animation:a .3s forwards;box-shadow:0 1px 3px 0 rgba(0,0,0,.45);position:relative;padding-right:13px}.notyf__toast.notyf--alert{background:#18D4F6}.notyf__toast.notyf--confirm{background:#3dc763}.notyf__toast.notyf--disappear{-webkit-animation:b .3s 1 forwards;animation:b .3s 1 forwards;-webkit-animation-delay:.25s;animation-delay:.25s}.notyf__toast.notyf--disappear .notyf__message{opacity:1;-webkit-animation:b .3s 1 forwards;animation:b .3s 1 forwards;-webkit-animation-delay:.1s;animation-delay:.1s}.notyf__toast.notyf--disappear .notyf__icon{opacity:1;-webkit-animation:d .3s 1 forwards;animation:d .3s 1 forwards}.notyf__wrapper{display:table;width:100%;padding-top:20px;padding-bottom:20px;padding-right:15px;border-radius:3px}.notyf__icon{width:20%;text-align:center;font-size:1.3em;-webkit-animation:c .5s forwards;animation:c .5s forwards;-webkit-animation-delay:.25s;animation-delay:.25s}.notyf__icon,.notyf__message{display:table-cell;vertical-align:middle;opacity:0}.notyf__message{width:80%;position:relative;-webkit-animation:a .3s forwards;animation:a .3s forwards;-webkit-animation-delay:.15s;animation-delay:.15s}.notyf{position:fixed;bottom:20px;right:30px;width:30%;color:#fff;z-index:1}@media only screen and (max-width:736px){.notyf__container{width:90%;margin:0 auto;display:block;right:0;left:0}}',document.getElementsByTagName("head")[0].appendChild(style);var notyf=new Notyf;
// fill form with dates
if (null !== document.getElementById("CaseSearchValue")) {
var today = new Date,
year = today.getFullYear(),
month = today.getMonth() + 1,
day = today.getDate(),
yesterday = month + "/" + (1 == today.getDay() ? day - 3 : day - 1) + "/" + year,
search = year.toString().slice(2, 4) + "LT*";
document.getElementById("CaseSearchValue").setAttribute("value", search), document.getElementById("DateFiledOnAfter").setAttribute("value", yesterday), document.getElementById("DateFiledOnBefore").setAttribute("value", yesterday), document.getElementById("SearchSubmit").click()
} else {
var t = {},
e = !0;
if ("object" == typeof this.artoo && (artoo.settings.reload || (artoo.log.verbose("Scraping data now"), artoo.loadSettings(t), artoo.exec(), e = !1)), e) {
var o = document.getElementsByTagName("body")[0];
o || (o = document.createElement("body"), document.documentElement.appendChild(o));
var a = document.createElement("script");
console.log("artoo.js is loading..."), a.src = "//medialab.github.io/artoo/public/dist/artoo-latest.min.js", a.type = "text/javascript", a.id = "artoo_injected_script", a.setAttribute("settings", JSON.stringify(t)), o.appendChild(a), notyf.confirm("Tool Loaded. Click again to scrape!")
} else notyf.confirm("Scraping Data"), scrapingNow = setInterval(function() {
notyf.confirm("Scraping Data")
}, 1e3), artoo.ajaxSpider(function(i) {
return jQuery("table:nth-child(5) a").eq(i).attr("href")
}, {
concat: !0,
scrape: {
iterator: 'table:eq(7) tr[height="25"]+tr, table:eq(7) tr:eq(1)',
data: {
county: function($) {
return $(this).closest("table").siblings("table").eq(2).find(".ssTableHeaderLabel + td:eq(2)").text()
},
"case": function($) {
return $(this).closest("table").prev().prev().find("span").text()
},
firstName: {
sel: "th:nth-child(2), td:first-child",
method: function($) {
return $(this).text().indexOf(", ") > -1 ? $(this).text().split(", ")[1] : ""
}
},
lastName: {
sel: "th:nth-child(2), td:first-child",
method: function($) {
return $(this).text().split(", ")[0]
}
},
address: function($) {
return $(this).next().find("td:first-child").length ? $(this).next().find("td:first-child").html() : void 0
},
who: {
sel: "th:nth-child(1)",
method: "text"
}
}
}
}, function(data) {
var download = [],
today = new Date,
filename = "Case Data " + today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + ".csv";
window.clearTimeout(scrapingNow), notyf.alert("Data Scraped.<br /><strong>" + filename + "</strong><br />has been downloaded."), data.forEach(function(currentValue, index, array) {
void 0 !== currentValue.address && (currentValue.address = currentValue.address.replace(/(.*0{5,})/g, "").replace(/<nobr>[^<]*<\/nobr><br ?\/?>/g, "").replace(/(&nbsp;)/g, "").replace(/(<br ?\/?>)(?!$)/g, "\n").replace(/(<br ?\/?>)/g, "").trim().replace(/ {2,}/, " ").replace(/ (?=,)/, "")), void 0 !== currentValue.firstName && (currentValue.firstName = currentValue.firstName.replace(/&nbsp;/, " ").replace(/ +/g, " ").replace(/<\/?[^>]*>/, "")), void 0 !== currentValue.lastName && (currentValue.lastName = currentValue.lastName.replace(/&nbsp;/, " ").replace(/ +/g, " ").replace(/<\/?[^>]*>/, "")), "" !== currentValue.address && "Defendant" == currentValue.who && (delete currentValue.who, download.push(currentValue))
}), artoo.saveCsv(download, filename)
})
}
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment