-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.ts
291 lines (278 loc) · 7.71 KB
/
seed.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import { Database } from "bun:sqlite";
import { client } from "./client";
import e from "./dbschema/edgeql-js";
const db = new Database("./memes.db");
const res = db.query("SELECT * FROM combines").all();
const query = e.params({ items: e.json }, (params) => {
return e.for(e.json_array_unpack(params.items), (item) => {
return e
.insert(e.Meme, {
description: e.cast(e.str, item.desc),
name: e.cast(e.str, item.title),
slug: e.cast(e.str, item.slug),
nsfw: e.cast(e.bool, item.nsfw),
shortId: e.cast(e.int64, item.short_id),
idx: e.cast(e.int64, item.idx),
origin: e.cast(e.str, item.origin),
stars: e.cast(e.int64, item.stars),
views: e.cast(e.int64, item.views),
year: e.cast(e.int64, item.year),
tags: e.cast(e.array(e.str), item.tags),
type: e.cast(e.str, item.type),
partOf: e.cast(e.str, item.part_of),
})
.unlessConflict((meme) => ({
on: meme.slug,
else: e.update(meme, () => ({
set: {
description: e.cast(e.str, item.desc),
name: e.cast(e.str, item.title),
slug: e.cast(e.str, item.slug),
nsfw: e.cast(e.bool, item.nsfw),
shortId: e.cast(e.int64, item.short_id),
idx: e.cast(e.int64, item.idx),
origin: e.cast(e.str, item.origin),
stars: e.cast(e.int64, item.stars),
views: e.cast(e.int64, item.views),
year: e.cast(e.int64, item.year),
tags: e.cast(e.array(e.str), item.tags),
type: e.cast(e.str, item.type),
partOf: e.cast(e.str, item.part_of),
},
})),
}));
});
});
const foundSlugs: string[] = [];
function splitArray(array: any[], chunkSize: number) {
const result = [];
for (let i = 0; i < array.length; i += chunkSize) {
result.push(array.slice(i, i + chunkSize));
}
return result;
}
function verySmartOriginSanitizer(origin: string): string {
if (!origin) return "Unknown";
const lowerCaseOrigin = origin.toLowerCase();
if (lowerCaseOrigin.includes("youtube")) {
return "youtube";
}
if (lowerCaseOrigin.includes("twitter")) {
return "X";
}
if (lowerCaseOrigin.includes("reddit")) {
return "reddit";
}
if (lowerCaseOrigin.includes("/r/")) {
return "reddit";
}
if (lowerCaseOrigin.includes("4chan")) {
return "4chan";
}
const chanTopics = [
"/a/",
"/b/",
"/co/",
"/fa/",
"/int/",
"/leftypol/",
"/mu/",
"/pol/",
"/r9k/",
"/sp/",
"/tv/",
"/v/",
];
if (chanTopics.some((x) => lowerCaseOrigin.includes(x))) {
return "4chan";
}
if (lowerCaseOrigin.includes("amazon")) {
return "amazon";
}
if (lowerCaseOrigin.includes("avengers")) {
return "avengers";
}
if (lowerCaseOrigin.includes("instagram")) {
return "instagram";
}
if (lowerCaseOrigin.includes("game of thrones")) {
return "game of thrones";
}
if (lowerCaseOrigin.includes("grand theft")) {
return "grand theft auto";
}
if (lowerCaseOrigin.includes("harry potter")) {
return "harry potter";
}
if (lowerCaseOrigin.includes("gravity falls")) {
return "gravity falls";
}
if (lowerCaseOrigin.replaceAll(" ", "").includes("bodybuilding")) {
return "body building";
}
if (lowerCaseOrigin.includes("it's always sunny")) {
return "it's always sunny in philadelphia";
}
if (lowerCaseOrigin.replaceAll(" ", "").includes("dragonball")) {
return "dragonball";
}
if (lowerCaseOrigin.includes("jojo's")) {
return "jojo's bizarre adventure";
}
if (lowerCaseOrigin.includes("Jurassic")) {
return "jurassic park";
}
if (lowerCaseOrigin.includes("minecraft")) {
return "minecraft";
}
if (lowerCaseOrigin.includes("pokemon")) {
return "pokemon";
}
if (lowerCaseOrigin.includes("spongebob")) {
return "spongebob";
}
if (lowerCaseOrigin.includes("star wars")) {
return "star wars";
}
if (lowerCaseOrigin.includes("star trek")) {
return "star trek";
}
if (lowerCaseOrigin.includes("the simpsons")) {
return "the simpsons";
}
if (lowerCaseOrigin.includes("titanic")) {
return "titanic";
}
if (lowerCaseOrigin.includes("king of the")) {
return "king of the hill";
}
if (lowerCaseOrigin.includes("tiktok")) {
return "tiktok";
}
if (lowerCaseOrigin.includes("kuvalauta")) {
return "kuvalauta";
}
if (lowerCaseOrigin.includes("final fantasy")) {
return "final fantasy";
}
if (lowerCaseOrigin.includes("washington")) {
return "washington";
}
if (lowerCaseOrigin.includes("Warhammer")) {
return "warhammer";
}
if (lowerCaseOrigin.includes("Usenet")) {
return "usenet";
}
if (lowerCaseOrigin.includes("Unknown")) {
return "unknown";
}
if (lowerCaseOrigin.includes("tumblr")) {
return "tumblr";
}
if (lowerCaseOrigin.includes("toonhole")) {
return "toonhole";
}
if (
lowerCaseOrigin.includes("tim and eric") ||
lowerCaseOrigin.includes("tim & eric")
) {
return "tim and eric";
}
if (lowerCaseOrigin.includes("thomas the tank")) {
return "Thomas the Tank Engine";
}
if (lowerCaseOrigin.includes("thor: ragnarok")) {
return "thor: ragnarok";
}
if (lowerCaseOrigin.includes("impsons")) {
return "The Simpsons";
}
if (lowerCaseOrigin.includes("the legend of zelda")) {
return "the legend of zelda";
}
if (lowerCaseOrigin.includes("the dark knight")) {
return "the dark knight";
}
if (lowerCaseOrigin.includes("television")) {
return "Television";
}
if (lowerCaseOrigin.includes("the office")) {
return "the office";
}
if (lowerCaseOrigin.includes("south park")) {
return "south park";
}
if (lowerCaseOrigin.includes("sonic")) {
return "sonic";
}
if (lowerCaseOrigin.includes("lord of the r")) {
return "lord of the rings";
}
if (lowerCaseOrigin.includes("bbc")) {
return "BBC";
}
if (lowerCaseOrigin.includes("naruto")) {
return "Naruto";
}
if (origin.includes("Monty Python")) {
return "Monty Python";
}
if (lowerCaseOrigin.includes("Fate")) {
return "Fate";
}
if (lowerCaseOrigin.includes("doom")) {
return "Doom";
}
if (lowerCaseOrigin.includes("doctor strange")) {
return "Doctor Strange";
}
if (lowerCaseOrigin.includes("twitch")) {
return "twitch";
}
if (lowerCaseOrigin.includes("anime")) {
return "anime";
}
const cleanerdOrigin = origin.replaceAll("<i>", "").replaceAll("</i>", "");
return cleanerdOrigin;
}
for (const smallerArray of splitArray(res, 500) as any[]) {
smallerArray.forEach((element) => {
delete element["content"];
});
const result = await query.run(client, {
items: smallerArray
.map((x: any) => ({
...x,
slug: x.href.split("/").at(-1),
tags: x.tags.split(",").map((x: string) => x.trim()),
nsfw: x.nsfw ? true : false,
short_id: parseInt(x.short_id),
year: parseInt(x.year),
idx: parseInt(x.idx),
stars: parseInt(x.stars),
views: parseInt(x.views.replaceAll(".", "")),
origin: verySmartOriginSanitizer(x.origin) ?? null,
part_of: x.part_of?.split(",")?.[0]?.split(" / ")?.[0] ?? null,
type: x.type?.split(",")?.[0] ?? null,
}))
.filter((x: any) => {
if (foundSlugs.includes(x.slug)) {
return false;
} else {
foundSlugs.push(x.slug);
return true;
}
}),
});
}
// e.insert(e.Meme, )
// const query = e.select(e.Card, (movie) => ({
// id: true,
// title: true,
// actors: { name: true },
// num_actors: e.count(movie.actors),
// filter_single: e.op(movie.title, "=", "Dune"),
// }));
// const result = await query.run(client);
// result.actors[0].name; // => Timothee Chalamet