From 233fc87fc71e61481f49a02cf3c8b782743979e7 Mon Sep 17 00:00:00 2001 From: tree Date: Mon, 23 Jan 2023 04:37:12 +0100 Subject: [PATCH] Update sync --- Makefile | 2 +- data/23/events/btcprague/_sync.js | 21 +++++++++++ data/23/events/btcprague/data.json | 56 +++++++++++++++++++++++++++++ data/23/events/btcprague/index.toml | 3 ++ data/23/events/ethprague/index.toml | 1 - utils/engine.js | 3 ++ utils/eventSync.js | 9 +++-- utils/syncTools.js | 10 ++++-- 8 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 data/23/events/btcprague/_sync.js create mode 100644 data/23/events/btcprague/data.json create mode 100644 data/23/events/btcprague/index.toml diff --git a/Makefile b/Makefile index ef82847..89874c7 100644 --- a/Makefile +++ b/Makefile @@ -17,4 +17,4 @@ build: deno run --unstable --allow-read --allow-write utils/exec.js build event-sync: - deno run --unstable --allow-read --allow-write --allow-net utils/eventSync.js + deno run --unstable --allow-read --allow-write --allow-net utils/eventSync.js $(event) diff --git a/data/23/events/btcprague/_sync.js b/data/23/events/btcprague/_sync.js new file mode 100644 index 0000000..9d732f7 --- /dev/null +++ b/data/23/events/btcprague/_sync.js @@ -0,0 +1,21 @@ +function cleanup(str) { + return str.replace(/(\s{2,}|\n)/g, " ").trim(); +} + +export async function data(tools) { + const $ = await tools.loadHtmlUrl("https://www.btcprague.com/"); + const out = { speakers: [] }; + for (const el of $(".speaker").toArray()) { + const value = (path) => cleanup($(path, el).text()); + out.speakers.push({ + name: value("h3"), + photoUrl: $("img", el).attr("src"), + bio: value(".popis"), + twitter: $(".twitter", el).attr("href")?.replace("https://twitter.com/",""), + web: $(".www", el).attr("href") + ? { url: $(".www", el).attr("href") } + : undefined, + }); + } + return out; +} diff --git a/data/23/events/btcprague/data.json b/data/23/events/btcprague/data.json new file mode 100644 index 0000000..80d8ecd --- /dev/null +++ b/data/23/events/btcprague/data.json @@ -0,0 +1,56 @@ +{ + "speakers": [ + { + "name": "Knut Svanholm", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2022/11/btcprague-knutsvanholm-320x320.jpg", + "bio": "Author of the „∞ / 21M” book", + "web": { + "url": "https://www.knutsvanholm.com/" + } + }, + { + "name": "Anita Posch", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2023/01/Anita-Posch-2-320x320.png", + "bio": "Bitcoin educator & author" + }, + { + "name": "Dušan Matuška", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2023/01/Dusan-Matuska-320x320.png", + "bio": "Bitcoin educator & miner" + }, + { + "name": "Roman Reher", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2022/11/btcprague-romanreher-320x320.jpg", + "bio": "Founder of YT channel \"Blocktrainer\"", + "twitter": "blocktrainer", + "web": { + "url": "https://www.blocktrainer.de/" + } + }, + { + "name": "Giacomo Zucco", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2022/11/btcprague-giacomozucco-320x320.jpg", + "bio": "Bitcoin entrepreneur & consultant", + "twitter": "giacomozucco" + }, + { + "name": "Wolf von Laer", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2023/01/Wolf-von-Laer-320x320.jpg", + "bio": "CEO of Students For Liberty" + }, + { + "name": "Benjamin de Waal", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2023/01/Ben-de-Waal.jpg", + "bio": "VP Engineering of Swan Bitcoin" + }, + { + "name": "Stephan Livera", + "photoUrl": "https://www.btcprague.com/wp-content/uploads/2022/10/btcprague-stephanlivera-320x320.jpg", + "bio": "Host of “Stephan Livera Podcast”", + "twitter": "stephanlivera", + "web": { + "url": "https://stephanlivera.com/" + } + } + ] +} \ No newline at end of file diff --git a/data/23/events/btcprague/index.toml b/data/23/events/btcprague/index.toml new file mode 100644 index 0000000..383630b --- /dev/null +++ b/data/23/events/btcprague/index.toml @@ -0,0 +1,3 @@ +# the name of your event +name = "BTC Prague 2023" +shortname = "BTC Prague" \ No newline at end of file diff --git a/data/23/events/ethprague/index.toml b/data/23/events/ethprague/index.toml index 2d0a1ba..317ab03 100644 --- a/data/23/events/ethprague/index.toml +++ b/data/23/events/ethprague/index.toml @@ -1,6 +1,5 @@ # the name of your event name = "ETHPrague 2023" - shortname = "ETHPrague" # the name of the group organizing the event diff --git a/utils/engine.js b/utils/engine.js index 4c84bc7..ddc7a98 100644 --- a/utils/engine.js +++ b/utils/engine.js @@ -133,6 +133,9 @@ class DeConf_Event { // data if (module.data) { const data = await module.data(syncTools); + if (!JSON.stringify(data)) { + return null; + } await _jsonWrite([this.dir, "data.json"].join("/"), data); } } diff --git a/utils/eventSync.js b/utils/eventSync.js index b4a510e..c296530 100644 --- a/utils/eventSync.js +++ b/utils/eventSync.js @@ -7,6 +7,11 @@ await dc.init(); const entry = dc.entries[dc.entries.length - 1]; console.log(`entry=${entry.id}`); -for (const event of entry.data.events) { - await event.sync(); +if (Deno.args[0]) { + const ev = entry.data.events.find((e) => e.id === Deno.args[0]); + await ev.sync(); +} else { + for (const event of entry.data.events) { + await event.sync(); + } } diff --git a/utils/syncTools.js b/utils/syncTools.js index 001828e..0db45fb 100644 --- a/utils/syncTools.js +++ b/utils/syncTools.js @@ -1,5 +1,11 @@ +import cheerio from "https://esm.sh/cheerio"; + export async function loadJSONUrl(url) { const resp = await fetch(url); - const data = await resp.json(); - return data; + return resp.json(); +} + +export async function loadHtmlUrl(url) { + const resp = await fetch(url); + return cheerio.load(await resp.text()); }