-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs.ts
executable file
·115 lines (92 loc) · 2.27 KB
/
jobs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { config } from "https://deno.land/x/dotenv/mod.ts";
import { ats } from './ats.ts';
const ENV = config();
let text: string = "";
let html: string = "";
const emails = [
"ettinger@gmail.com",
"leo@finalresort.org",
];
const sites = ats;
const keywords = [
"svelte",
"vue",
"deno",
];
const positive = [
"javascript",
"typescript",
];
const negative = [
"react",
"reactjs",
"angular",
"angularjs",
];
async function getSerps(q: string): Promise<any> {
let txt: string = "";
let htm: string = "";
const res = await fetch(
`https://api.scaleserp.com/search?api_key=74BEEFF70A2645618A2BB3845408B96A&q=${q}&gl=us&hl=en&time_period=last_week&num=100`,
);
const data = await res.json();
console.log("fetching:", q);
if (!data.organic_results?.length) return { txt, htm };
htm += `
<h1><a href="https://google.com/search?q=${q}" target="_new">${q}</a></h1>
<ol>
`;
txt += `
==========================
${q}
==========================`;
data.organic_results.map((item: any) => {
const { title, link, snippet } = item;
txt += `
${title}
${link}
${snippet}
--------------------`;
htm += `
<li><a href="${link}" target="_new">${title}</a><p>${snippet}</p></li>
`;
});
htm += "</ol>";
return { txt, htm };
}
async function sendEmail(email: string, txt: string, htm: string) {
const auth = btoa(`api:${ENV.MAILGUN_API_KEY}`);
const form = new FormData();
form.append("from", `Anthony Ettinger ${ENV.META_EMAIL}`);
form.append("to", email);
form.append("subject", `remote jobs`);
form.append("text", txt);
form.append("html", `<html>${htm}</html>`);
const res = await fetch(
"https://api.mailgun.net/v3/mg.startworkingremotely.com/messages",
{
method: "POST",
headers: {
Authorization: `Basic ${auth}`,
},
body: form,
},
);
if (!res.ok) {
console.error(await res.text());
}
return await res.json();
}
for (const site of sites) {
for (const kw of keywords) {
const neg = negative.map((n) => " -" + n).join("");
const pos = positive.map((p) => " " + p).join("");
const q = `${site} ${kw}${neg}${pos}`;
const { txt, htm } = await getSerps(q);
text += txt;
html += htm;
}
}
for (const email of emails) {
await sendEmail(email, text, html);
}