Skip to content

Commit 4c8e85a

Browse files
👩‍💻 dx(cineonu): Migrate scripts to a bun package.
1 parent ba8ee26 commit 4c8e85a

File tree

11 files changed

+318
-120
lines changed

11 files changed

+318
-120
lines changed

.bin/bun/bun.lock

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env -S bun run
2+
3+
const fs = require("fs");
4+
const jsdom = require('jsdom') ;
5+
const { JSDOM } = jsdom ;
6+
7+
const SELECTOR_TITLE = ".article-inside h3" ;
8+
const SELECTOR_DATETIME_AND_LOCATION = ".article-inside > table > tbody > tr:nth-child(1) > td:nth-child(1) > p";
9+
const SELECTOR_RUNTIME = ".article-inside > table > tbody > tr:nth-child(1) > td:nth-child(2) > p";
10+
const SELECTOR_IMG = [
11+
'.article-inside img[title*="poster"]',
12+
'.article-inside img[title*="cover"]',
13+
'.article-inside img[title*="image"]',
14+
'.article-inside img[alt*="poster"]',
15+
'.article-inside img[alt*="cover"]',
16+
'.article-inside img[alt*="image"]',
17+
'.article-inside img[src*="poster"]',
18+
'.article-inside img[src*="cover"]',
19+
'.article-inside img[src*="image"]',
20+
].join(', ');
21+
const SELECTOR_TRAILER = "div.nice:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > p:nth-child(2) > iframe:nth-child(1)";
22+
const SELECTOR_IMDB = '.article-inside a[href^="https://www.imdb.com"]';
23+
const SELECTOR_FACEBOOK = '.article-inside a[href^="https://www.facebook.com"]';
24+
const SELECTOR_EVENTBRITE = '.article-inside a[href^="https://www.eventbrite.com"]';
25+
const SELECTOR_BOZAR = '.article-inside a[href^="https://brussel.iticketsro.com/Bozar"]';
26+
const SELECTOR_DESCRIPTION = ".article-inside > table:nth-child(3) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1)";
27+
28+
function main ( ) {
29+
30+
const text = fs.readFileSync("/dev/stdin", "utf-8");
31+
const json = parse(text);
32+
const output = JSON.stringify(json) ;
33+
console.log(output) ;
34+
35+
}
36+
37+
function parse ( text ) {
38+
39+
const dom = new JSDOM(text);
40+
const document = dom.window.document;
41+
42+
const get = selector => document.querySelector(selector) || {} ;
43+
44+
const url = document.baseURI;
45+
const year = url.split('/')[4];
46+
const title = get(SELECTOR_TITLE).textContent;
47+
const datetimeAndLocation = get(SELECTOR_DATETIME_AND_LOCATION).textContent;
48+
const runtime = (get(SELECTOR_RUNTIME).textContent || '').split(' ')[1];
49+
const img = get(SELECTOR_IMG).src;
50+
const trailer = get(SELECTOR_TRAILER).src;
51+
const imdb = get(SELECTOR_IMDB).href;
52+
const facebook = get(SELECTOR_FACEBOOK).href;
53+
const eventbrite = get(SELECTOR_EVENTBRITE).href;
54+
const bozar = get(SELECTOR_BOZAR).href;
55+
const description = (get(SELECTOR_DESCRIPTION).textContent || '').trim();
56+
57+
const [date, timeAndlocation] = datetimeAndLocation.split(', ');
58+
const [time, location] = timeAndlocation.slice(0,timeAndlocation.length-1).split(' (');
59+
60+
const json = {
61+
url ,
62+
year ,
63+
title ,
64+
date ,
65+
time ,
66+
location ,
67+
runtime ,
68+
img ,
69+
trailer ,
70+
imdb ,
71+
facebook ,
72+
eventbrite ,
73+
bozar ,
74+
description ,
75+
} ;
76+
77+
return json;
78+
}
79+
80+
main();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"name": "__cineonu-parse-event",
4+
"version": "0.0.1",
5+
"type": "module",
6+
"dependencies": {
7+
"jsdom": "^26.1.0"
8+
},
9+
"devDependencies": {
10+
"@types/node": "^24.2.0",
11+
"typescript": "^5.9.2"
12+
}
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"target": "esnext",
6+
"module": "esnext",
7+
"lib": ["esnext"],
8+
"allowJs": true,
9+
"checkJs": true,
10+
"incremental": true,
11+
12+
"strict": true,
13+
"noImplicitAny": false,
14+
"noImplicitThis": false,
15+
"strictNullChecks": true,
16+
17+
"noImplicitReturns": true,
18+
"noFallthroughCasesInSwitch": true,
19+
"noImplicitOverride": false,
20+
"noPropertyAccessFromIndexSignature": false,
21+
"noUncheckedIndexedAccess": true,
22+
"noUnusedLocals": true,
23+
"noUnusedParameters": true,
24+
25+
"allowUnreachableCode": false,
26+
27+
"moduleResolution": "node",
28+
"resolveJsonModule": true,
29+
"esModuleInterop": true,
30+
"preserveSymlinks": true,
31+
"allowSyntheticDefaultImports": true
32+
}
33+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env -S bun run
2+
3+
const fs = require("fs");
4+
const jsdom = require('jsdom') ;
5+
const { JSDOM } = jsdom ;
6+
7+
const SELECTOR_EVENTS = "#current > ul > li > a"
8+
9+
function main ( ) {
10+
11+
const text = fs.readFileSync("/dev/stdin", "utf-8");
12+
const json = parse(text);
13+
const output = JSON.stringify(json) ;
14+
console.log(output) ;
15+
16+
}
17+
18+
function parse ( text ) {
19+
20+
const dom = new JSDOM(text);
21+
const document = dom.window.document;
22+
23+
const transformEvent = node => ({
24+
url: node.href,
25+
title: node.children[0].textContent,
26+
}) ;
27+
28+
const url = document.baseURI;
29+
const events = [ ...document.querySelectorAll(SELECTOR_EVENTS).values()].map(transformEvent);
30+
31+
const json = {
32+
url ,
33+
events ,
34+
} ;
35+
36+
return json;
37+
}
38+
39+
main();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"name": "__cineonu-parse-list",
4+
"version": "0.0.1",
5+
"type": "module",
6+
"dependencies": {
7+
"jsdom": "^26.1.0"
8+
},
9+
"devDependencies": {
10+
"@types/node": "^24.2.0",
11+
"typescript": "^5.9.2"
12+
}
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"target": "esnext",
6+
"module": "esnext",
7+
"lib": ["esnext"],
8+
"allowJs": true,
9+
"checkJs": true,
10+
"incremental": true,
11+
12+
"strict": true,
13+
"noImplicitAny": false,
14+
"noImplicitThis": false,
15+
"strictNullChecks": true,
16+
17+
"noImplicitReturns": true,
18+
"noFallthroughCasesInSwitch": true,
19+
"noImplicitOverride": false,
20+
"noPropertyAccessFromIndexSignature": false,
21+
"noUncheckedIndexedAccess": true,
22+
"noUnusedLocals": true,
23+
"noUnusedParameters": true,
24+
25+
"allowUnreachableCode": false,
26+
27+
"moduleResolution": "node",
28+
"resolveJsonModule": true,
29+
"esModuleInterop": true,
30+
"preserveSymlinks": true,
31+
"allowSyntheticDefaultImports": true
32+
}
33+
}

.bin/cineonu-parse-event

Lines changed: 0 additions & 80 deletions
This file was deleted.

.bin/cineonu-parse-event

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bun/dist/cineonu-parse-event/bin/parse-event.js

.bin/cineonu-parse-list

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)