jobscraper/server/dist/build/bundle.js
Martin Donnelly f2880b661e JOBSCRAPER-1 Implement a bit of AI
* Moved to mongo
* UI updated to use mongo
* UI is a bit fancier now
* Import sql to mongo
2020-09-10 14:13:08 +01:00

2 lines
16 KiB
JavaScript

var app=function(){"use strict";function t(){}function e(t){return t()}function n(){return Object.create(null)}function o(t){t.forEach(e)}function r(t){return"function"==typeof t}function a(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function s(e,n,o){e.$$.on_destroy.push(function(e,...n){if(null==e)return t;const o=e.subscribe(...n);return o.unsubscribe?()=>o.unsubscribe():o}(n,o))}function c(t,e){t.appendChild(e)}function l(t,e,n){t.insertBefore(e,n||null)}function i(t){t.parentNode.removeChild(t)}function u(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function d(t){return document.createElement(t)}function f(t){return document.createTextNode(t)}function p(){return f(" ")}function m(){return f("")}function h(t,e,n,o){return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o)}function g(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function b(t,e){e=""+e,t.data!==e&&(t.data=e)}let y;function v(t){y=t}const $=[],w=[],x=[],k=[],J=Promise.resolve();let _=!1;function C(t){x.push(t)}let A=!1;const L=new Set;function j(){if(!A){A=!0;do{for(let t=0;t<$.length;t+=1){const e=$[t];v(e),T(e.$$)}for($.length=0;w.length;)w.pop()();for(let t=0;t<x.length;t+=1){const e=x[t];L.has(e)||(L.add(e),e())}x.length=0}while($.length);for(;k.length;)k.pop()();_=!1,A=!1,L.clear()}}function T(t){if(null!==t.fragment){t.update(),o(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(C)}}const M=new Set;function O(t,e){t&&t.i&&(M.delete(t),t.i(e))}function S(t,e,n,o){if(t&&t.o){if(M.has(t))return;M.add(t),(void 0).c.push(()=>{M.delete(t),o&&(n&&t.d(1),o())}),t.o(e)}}function N(t){t&&t.c()}function R(t,n,a){const{fragment:s,on_mount:c,on_destroy:l,after_update:i}=t.$$;s&&s.m(n,a),C(()=>{const n=c.map(e).filter(r);l?l.push(...n):o(n),t.$$.on_mount=[]}),i.forEach(C)}function D(t,e){const n=t.$$;null!==n.fragment&&(o(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function E(t,e){-1===t.$$.dirty[0]&&($.push(t),_||(_=!0,J.then(j)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function H(e,r,a,s,c,l,u=[-1]){const d=y;v(e);const f=r.props||{},p=e.$$={fragment:null,ctx:null,props:l,update:t,not_equal:c,bound:n(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(d?d.$$.context:[]),callbacks:n(),dirty:u};let m=!1;if(p.ctx=a?a(e,f,(t,n,...o)=>{const r=o.length?o[0]:n;return p.ctx&&c(p.ctx[t],p.ctx[t]=r)&&(p.bound[t]&&p.bound[t](r),m&&E(e,t)),n}):[],p.update(),m=!0,o(p.before_update),p.fragment=!!s&&s(p.ctx),r.target){if(r.hydrate){const t=function(t){return Array.from(t.childNodes)}(r.target);p.fragment&&p.fragment.l(t),t.forEach(i)}else p.fragment&&p.fragment.c();r.intro&&O(e.$$.fragment),R(e,r.target,r.anchor),j()}v(d)}class P{$destroy(){D(this,1),this.$destroy=t}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(){}}const q=[];function z(e,n=t){let o;const r=[];function s(t){if(a(e,t)&&(e=t,o)){const t=!q.length;for(let t=0;t<r.length;t+=1){const n=r[t];n[1](),q.push(n,e)}if(t){for(let t=0;t<q.length;t+=2)q[t][0](q[t+1]);q.length=0}}}return{set:s,update:function(t){s(t(e))},subscribe:function(a,c=t){const l=[a,c];return r.push(l),1===r.length&&(o=n(s)||t),a(e),()=>{const t=r.indexOf(l);-1!==t&&r.splice(t,1),0===r.length&&(o(),o=null)}}}}var F=function t(e){function n(t){return function(e,n){return a(e,Object.assign({method:t},n))}}function o(t){return function(e,n,o){return a(e,Object.assign({method:t,data:n},o))}}function r(t,e,n){if(Array.isArray(t))return t.concat(e);if(e&&"object"==typeof e){var o,a={};if(t)for(o in t)a[n?o.toLowerCase():o]=t[o];for(o in e){var s=n?o.toLowerCase():o;"headers"===s&&(n=!0),a[s]=o in a?r(a[s],e[o],n):e[o]}return a}return e}function a(t,n){"string"!=typeof t&&(t=(n=t).url);var o=r(e,n||{}),a=o.data;if(o.transformRequest)for(var s=0;s<o.transformRequest.length;s++){var c=o.transformRequest[s](a,o.headers);void 0!==c&&(a=c)}var l={};if(a&&"object"==typeof a&&(a=JSON.stringify(a),l["Content-Type"]="application/json"),o.xsrfCookieName)for(var i=document.cookie.split(/ *[;=] */),u=0;u<i.length;u+=2)if(i[u]==o.xsrfCookieName){l[o.xsrfHeaderName]=decodeURIComponent(i[u+1]);break}o.auth&&(l.Authorization=o.auth);var d={};return d.config=n,fetch(t,{method:o.method,body:a,headers:r(o.headers,l,!0)}).then((function(t){var e;for(e in t)"function"!=typeof t[e]&&(d[e]=t[e]);return(o.validateStatus?o.validateStatus(t.status):t.ok)?("stream"===o.responseType?Promise.resolve(t.body):t[o.responseType||"text"]()).then((function(t){return d.data=t,d})):Promise.reject(t)}))}return e=e||{},a.request=a,a.get=n("get"),a.delete=n("delete"),a.options=n("options"),a.post=o("post"),a.put=o("put"),a.patch=o("patch"),a.all=Promise.all,a.spread=function(t){return function(e){return t.apply(this,e)}},a.CancelToken=self.AbortController||Object,a.create=t,a}();const I=`${location.protocol}//${location.hostname}`,V={jobs:I.concat("/v2/jobs"),apply:I.concat("/apply"),readall:I.concat("/readall"),kill:I.concat("/kill"),upvote:I.concat("/vote/up"),downvote:I.concat("/vote/down")},W=z([]),B=z({}),U={getJobList(){F.get(V.jobs).then(t=>{const e=JSON.parse(t.data);W.set(e)}).catch(t=>{console.error("getJobList",t)})},loadJobDetail(t){if(console.log("loadJobDetail: "+t),t){const e=`${V.jobs}/${t}`;F.get(e).then(t=>{const e=JSON.parse(t.data);B.set(e)}).catch(t=>{console.error("loadJobDetail",t)})}},async touchJob(t){if(console.log("touchJob: "+t),t){const e=`${V.jobs}/${t}`;await F.put(e).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("touchJob",t)}),W.update(e=>(e.map(e=>{if(e._id===t)return e.read=(new Date).getTime(),e}),e))}},async appliedJob(t){console.log("touchJob: "+t);const e=(new Date).getTime();if(t){console.log("Applying..");const n=`${V.apply}/${t}`;await F.put(n).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("appliedJob",t)});const o=parseInt(t,10);W.update(t=>(t.map(t=>{if(t._id===o)return t.a=e,t}),t)),B.update(t=>(t.a=e,t))}},async markAllRead(){console.log(">> markAllRead");const t=""+V.readall;await F.put(t).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("markAllRead",t)}),this.getJobList()},killWord(t){console.log(">> killword:"+t);const e=`${V.kill}/${t}`;F.put(e).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("killword",t)})},upVote(t){console.log(">> upvote:"+t);const e=`${V.upvote}/${t}`;F.put(e).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("upvote",t)})},downVote(t){console.log(">> downvote:"+t);const e=`${V.downvote}/${t}`;F.put(e).then(t=>{200!==t.status&&console.error(t)}).catch(t=>{console.error("downvote",t)})}};function G(t,e,n){const o=t.slice();return o[4]=e[n],o[6]=n,o}function K(t){let e,n,o,r,a,s,u,m,y,v,$,w,x,k,J,_,C=t[4].title+"",A=t[4].site+"",L=X(t[4].company)+"",j=tt(t[4].timestamp)+"";return{c(){e=d("tr"),n=d("td"),o=f(C),r=p(),a=d("td"),s=f(A),u=p(),m=d("td"),y=f(L),v=p(),$=d("td"),w=f(j),x=p(),g(n,"class","noOverflow svelte-15500pg"),g(e,"class",k="dataRow "+Y(t[4])+" "+Z(t[4])+" svelte-15500pg"),g(e,"data-id",J=t[4]._id)},m(i,d,f){var p;l(i,e,d),c(e,n),c(n,o),c(e,r),c(e,a),c(a,s),c(e,u),c(e,m),c(m,y),c(e,v),c(e,$),c($,w),c(e,x),f&&_(),_=h(e,"click",(p=t[1],function(t){return t.stopPropagation(),p.call(this,t)}))},p(t,n){1&n&&C!==(C=t[4].title+"")&&b(o,C),1&n&&A!==(A=t[4].site+"")&&b(s,A),1&n&&L!==(L=X(t[4].company)+"")&&b(y,L),1&n&&j!==(j=tt(t[4].timestamp)+"")&&b(w,j),1&n&&k!==(k="dataRow "+Y(t[4])+" "+Z(t[4])+" svelte-15500pg")&&g(e,"class",k),1&n&&J!==(J=t[4]._id)&&g(e,"data-id",J)},d(t){t&&i(e),_()}}}function Q(e){let n,o,r,a,s,f=e[0],m=[];for(let t=0;t<f.length;t+=1)m[t]=K(G(e,f,t));return{c(){n=d("div"),o=d("table"),r=d("thead"),r.innerHTML='<tr><th class="col-5">\n Title\n </th> \n <th class="col-2">\n Site\n </th> \n <th class="col-3">\n Company\n </th> \n <th class="col-2">\n Date\n </th></tr>',a=p(),s=d("tbody");for(let t=0;t<m.length;t+=1)m[t].c();g(o,"class",""),g(n,"class","lister svelte-15500pg")},m(t,e){l(t,n,e),c(n,o),c(o,r),c(o,a),c(o,s);for(let t=0;t<m.length;t+=1)m[t].m(s,null)},p(t,[e]){if(3&e){let n;for(f=t[0],n=0;n<f.length;n+=1){const o=G(t,f,n);m[n]?m[n].p(o,e):(m[n]=K(o),m[n].c(),m[n].m(s,null))}for(;n<m.length;n+=1)m[n].d(1);m.length=f.length}},i:t,o:t,d(t){t&&i(n),u(m,t)}}}function X(t){return t.length<=40?t:t.slice(0,40)+"…"}function Y(t){return 0!==t.read?"read":""}function Z(t){return 0!==t.applied?"applied":""}function tt(t){return new Date(t).toLocaleString()}function et(t,e,n){let o;return s(t,W,t=>n(0,o=t)),[o,function(t){const e=t.target.parentElement.dataset.id;U.loadJobDetail(e),U.touchJob(e)}]}class nt extends P{constructor(t){super(),H(this,t,et,Q,a,{})}}function ot(t,e,n){const o=t.slice();return o[8]=e[n],o[10]=n,o}function rt(t){let e,n,o,r,a,s,m,h,y,v,$,w,x,k,J,_,C,A,L,j,T,M,O,S,N,R,D,E,H,P,q,z,F,I,V,W,B,U,G,K,Q,X,Y=t[3].title+"",Z=t[3].company+"",tt=t[3].location+"",et=t[3].salary+"",nt=t[3].date+"",rt=t[3].site+"",it=t[3].summary+"";function ut(t,e){return 1===t[2]?st:2===t[2]?at:void 0}let dt=ut(t),pt=dt&&dt(t);function mt(t,e){return t[3].a?ct:lt}let ht=mt(t),gt=ht(t),bt=t[3].data.autoclass.words,yt=[];for(let e=0;e<bt.length;e+=1)yt[e]=ft(ot(t,bt,e));return{c(){e=d("div"),n=d("div"),o=d("div"),r=d("div"),a=f(Y),s=p(),pt&&pt.c(),m=p(),h=d("div"),y=d("div"),v=f("Company: "),$=d("span"),w=f(Z),x=p(),k=d("div"),J=f("Location: "),_=d("span"),C=f(tt),A=p(),L=d("div"),j=f("Applied:\n "),gt.c(),T=p(),M=d("div"),O=d("div"),S=f("Salary: "),N=d("span"),R=p(),D=d("div"),E=f("Scraped: "),H=d("span"),P=f(nt),q=p(),z=d("div"),F=f("Site: "),I=d("a"),V=f(rt),B=p(),U=d("div"),G=d("div");for(let t=0;t<yt.length;t+=1)yt[t].c();Q=p(),X=d("blockquote"),g(r,"class","col-12 text-primary lead"),g(o,"class","row svelte-r7f80i"),g($,"class","text-primary"),g(y,"class","col-1-3rd"),g(_,"class","text-primary"),g(k,"class","col-1-3rd"),g(L,"class","col-1-3rd"),g(h,"class","row svelte-r7f80i"),g(N,"class","text-primary"),g(O,"class","col-1-3rd"),g(H,"class","text-primary"),g(D,"class","col-1-3rd"),g(I,"href",W=t[3].url),g(I,"class","text-capitalize"),g(I,"target","_blank"),g(z,"class","col-1-3rd"),g(M,"class","row svelte-r7f80i"),g(G,"class","col-12"),g(U,"class","row svelte-r7f80i"),g(n,"class",K="detailHead bg-light "+(t[1]?"applied":"")+" svelte-r7f80i"),g(e,"class","detail svelte-r7f80i")},m(t,i){l(t,e,i),c(e,n),c(n,o),c(o,r),c(r,a),c(o,s),pt&&pt.m(o,null),c(n,m),c(n,h),c(h,y),c(y,v),c(y,$),c($,w),c(h,x),c(h,k),c(k,J),c(k,_),c(_,C),c(h,A),c(h,L),c(L,j),gt.m(L,null),c(n,T),c(n,M),c(M,O),c(O,S),c(O,N),N.innerHTML=et,c(M,R),c(M,D),c(D,E),c(D,H),c(H,P),c(M,q),c(M,z),c(z,F),c(z,I),c(I,V),c(n,B),c(n,U),c(U,G);for(let t=0;t<yt.length;t+=1)yt[t].m(G,null);c(e,Q),c(e,X),X.innerHTML=it},p(t,e){if(8&e&&Y!==(Y=t[3].title+"")&&b(a,Y),dt!==(dt=ut(t))&&(pt&&pt.d(1),pt=dt&&dt(t),pt&&(pt.c(),pt.m(o,null))),8&e&&Z!==(Z=t[3].company+"")&&b(w,Z),8&e&&tt!==(tt=t[3].location+"")&&b(C,tt),ht===(ht=mt(t))&&gt?gt.p(t,e):(gt.d(1),gt=ht(t),gt&&(gt.c(),gt.m(L,null))),8&e&&et!==(et=t[3].salary+"")&&(N.innerHTML=et),8&e&&nt!==(nt=t[3].date+"")&&b(P,nt),8&e&&rt!==(rt=t[3].site+"")&&b(V,rt),8&e&&W!==(W=t[3].url)&&g(I,"href",W),8&e){let n;for(bt=t[3].data.autoclass.words,n=0;n<bt.length;n+=1){const o=ot(t,bt,n);yt[n]?yt[n].p(o,e):(yt[n]=ft(o),yt[n].c(),yt[n].m(G,null))}for(;n<yt.length;n+=1)yt[n].d(1);yt.length=bt.length}2&e&&K!==(K="detailHead bg-light "+(t[1]?"applied":"")+" svelte-r7f80i")&&g(n,"class",K),8&e&&it!==(it=t[3].summary+"")&&(X.innerHTML=it)},d(t){t&&i(e),pt&&pt.d(),gt.d(),u(yt,t)}}}function at(t){let e;return{c(){e=d("span"),e.textContent="Permanent",g(e,"class","badge badge-danger")},m(t,n){l(t,e,n)},d(t){t&&i(e)}}}function st(t){let e;return{c(){e=d("span"),e.textContent="Contract",g(e,"class","badge badge-success")},m(t,n){l(t,e,n)},d(t){t&&i(e)}}}function ct(e){let n;return{c(){n=f("Applied!")},m(t,e){l(t,n,e)},p:t,d(t){t&&i(n)}}}function lt(e){let n,o;return{c(){n=d("button"),n.textContent="Applied",g(n,"class","btn btn-sm btn-primary")},m(t,r,a){l(t,n,r),a&&o(),o=h(n,"click",e[4])},p:t,d(t){t&&i(n),o()}}}function it(t){let e,n,o,a=t[8]+"";return{c(){e=d("span"),n=f(a),g(e,"class","badge badge-dark")},m(a,s,i){l(a,e,s),c(e,n),i&&o(),o=h(e,"click",(function(){r(ht(t[8]))&&ht(t[8]).apply(this,arguments)}))},p(e,o){t=e,8&o&&a!==(a=t[8]+"")&&b(n,a)},d(t){t&&i(e),o()}}}function ut(t){let e,n,o=t[8]+"";return{c(){e=d("span"),n=f(o),g(e,"class","badge badge-danger")},m(t,o){l(t,e,o),c(e,n)},p(t,e){8&e&&o!==(o=t[8]+"")&&b(n,o)},d(t){t&&i(e)}}}function dt(t){let e,n,o=t[8]+"";return{c(){e=d("span"),n=f(o),g(e,"class","badge badge-success")},m(t,o){l(t,e,o),c(e,n)},p(t,e){8&e&&o!==(o=t[8]+"")&&b(n,o)},d(t){t&&i(e)}}}function ft(t){let e,n,o;function r(t,o){return(null==e||8&o)&&(e=!(-1===t[3].data.autoclass.good.indexOf(t[8]))),e?dt:((null==n||8&o)&&(n=!(-1===t[3].data.autoclass.bad.indexOf(t[8]))),n?ut:it)}let a=r(t,-1),s=a(t);return{c(){s.c(),o=m()},m(t,e){s.m(t,e),l(t,o,e)},p(t,e){a===(a=r(t,e))&&s?s.p(t,e):(s.d(1),s=a(t),s&&(s.c(),s.m(o.parentNode,o)))},d(t){s.d(t),t&&i(o)}}}function pt(e){let n,o=e[0]&&rt(e);return{c(){o&&o.c(),n=m()},m(t,e){o&&o.m(t,e),l(t,n,e)},p(t,[e]){t[0]?o?o.p(t,e):(o=rt(t),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},i:t,o:t,d(t){o&&o.d(t),t&&i(n)}}}function mt(t){for(const e in t)if(t.hasOwnProperty(e))return!1;return!0}function ht(t){console.log(">>kill",t)}function gt(t,e,n){let o;s(t,B,t=>n(3,o=t));let r=!1,a=!1,c=0;return B.subscribe(t=>{n(0,r=!mt(t)),console.log(t)}),t.$$.update=()=>{8&t.$$.dirty&&(mt(o)||(n(1,a="number"==typeof o.data.applied&&1===o.data.applied),n(2,c=o.data.jobtype)))},[r,a,c,o,function(){U.appliedJob(o._id)}]}class bt extends P{constructor(t){super(),H(this,t,gt,pt,a,{})}}function yt(e){let n,o,r,a,s,u,f;return{c(){n=d("header"),o=d("section"),r=d("span"),r.textContent=""+vt,a=p(),s=d("section"),u=d("button"),u.textContent="Mark All Read",g(r,"class","text-bold navbar-brand mx-1 text-uppercase"),g(o,"class","navbar-section"),g(u,"class","btn btn-sm btn-primary"),g(s,"class","navbar-section text-right"),g(n,"class","navbar bg-primary")},m(t,i,d){l(t,n,i),c(n,o),c(o,r),c(n,a),c(n,s),c(s,u),d&&f(),f=h(u,"click",e[0])},p:t,i:t,o:t,d(t){t&&i(n),f()}}}let vt="Jobs";function $t(t){return[function(){U.markAllRead()}]}class wt extends P{constructor(t){super(),H(this,t,$t,yt,a,{})}}function xt(e){let n,o,r,a,s;const u=new wt({}),f=new nt({}),m=new bt({});return{c(){N(u.$$.fragment),n=p(),o=d("div"),r=d("div"),N(f.$$.fragment),a=p(),N(m.$$.fragment),g(r,"class","col-12"),g(o,"class","container fullWidth")},m(t,e){R(u,t,e),l(t,n,e),l(t,o,e),c(o,r),R(f,r,null),c(r,a),R(m,r,null),s=!0},p:t,i(t){s||(O(u.$$.fragment,t),O(f.$$.fragment,t),O(m.$$.fragment,t),s=!0)},o(t){S(u.$$.fragment,t),S(f.$$.fragment,t),S(m.$$.fragment,t),s=!1},d(t){D(u,t),t&&i(n),t&&i(o),D(f),D(m)}}}var kt=1e3,Jt=6e4,_t=60*Jt,Ct=24*_t,At=function(t,e){e=e||{};var n=typeof t;if("string"===n&&t.length>0)return function(t){if((t=String(t)).length>100)return;var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(!e)return;var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*n;case"weeks":case"week":case"w":return 6048e5*n;case"days":case"day":case"d":return n*Ct;case"hours":case"hour":case"hrs":case"hr":case"h":return n*_t;case"minutes":case"minute":case"mins":case"min":case"m":return n*Jt;case"seconds":case"second":case"secs":case"sec":case"s":return n*kt;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}(t);if("number"===n&&isFinite(t))return e.long?function(t){var e=Math.abs(t);if(e>=Ct)return Lt(t,e,Ct,"day");if(e>=_t)return Lt(t,e,_t,"hour");if(e>=Jt)return Lt(t,e,Jt,"minute");if(e>=kt)return Lt(t,e,kt,"second");return t+" ms"}(t):function(t){var e=Math.abs(t);if(e>=Ct)return Math.round(t/Ct)+"d";if(e>=_t)return Math.round(t/_t)+"h";if(e>=Jt)return Math.round(t/Jt)+"m";if(e>=kt)return Math.round(t/kt)+"s";return t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Lt(t,e,n,o){var r=e>=1.5*n;return Math.round(t/n)+" "+o+(r?"s":"")}let jt=0;const Tt=new class extends P{constructor(t){super(),H(this,t,null,xt,a,{})}}({target:document.body});return function t(){U.getJobList();const e=function(t=0){return 36e5-(new Date).getTime()%36e5+t}()+At("10m");console.log("Next:",e),jt=setTimeout(()=>{t()},e)}(),Tt}();