diff --git a/package-lock.json b/package-lock.json index 0b2785ea..4583613a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "autoprefixer": "^10.4.17", + "cjs-loader": "^0.1.0", "postcss": "^8.4.41", "postcss-cli": "^11.0.0" }, @@ -238,6 +239,12 @@ "fsevents": "~2.3.2" } }, + "node_modules/cjs-loader": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cjs-loader/-/cjs-loader-0.1.0.tgz", + "integrity": "sha512-WgdnnrdNJT+ffiyU2S1zsrhbDjkDH4qgTbGYHPSN6XBVMSg1LbnSnUrVFMic4pWYypcTwkhoNfBB+GFP/73MHQ==", + "license": "Apache-2" + }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", diff --git a/package.json b/package.json index ea2e137d..4a1c08f2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ }, "dependencies": { "autoprefixer": "^10.4.17", + "cjs-loader": "^0.1.0", "postcss": "^8.4.41", "postcss-cli": "^11.0.0" } -} +} \ No newline at end of file diff --git a/webmention.js b/webmention.js index 49a470ed..ae6dbc27 100644 --- a/webmention.js +++ b/webmention.js @@ -1,17 +1,22 @@ const fs = require("fs"); const https = require("https"); +const path = require('path'); + +function writeFileSyncRecursive(filename, content = '') { + fs.mkdirSync(path.dirname(filename), { recursive: true }) + fs.writeFileSync(filename, content) +} fetchWebmentions().then(webmentions => { webmentions.forEach(webmention => { const slug = webmention["wm-target"] .replace("https://fundor333.com/", "") - .replace(/\/$/, "") - .replace("/", "--"); + .replace(/\/$/, "").split('?')[0]; const filename = `${__dirname}/data/webmentions/${slug}.json`; if (!fs.existsSync(filename)) { - fs.writeFileSync(filename, JSON.stringify([webmention], null, 2)); + writeFileSyncRecursive(filename, JSON.stringify([webmention], null, 2)); return; } @@ -26,11 +31,13 @@ fetchWebmentions().then(webmentions => { }); }); + + function fetchWebmentions() { - const token = process.env.WEBMENTIONS_TOKEN; + const token = "-g5vlz9y3p5llrdS7TmnCg"; const since = new Date(); - since.setDate(since.getDate() - 3); + since.setDate(since.getDate() - 30); const url = "https://webmention.io/api/mentions.jf2" + @@ -61,6 +68,7 @@ function fetchWebmentions() { }); }).then(response => { if (!("children" in response)) { + console.log(response); throw new Error("Invalid webmention.io response."); } diff --git a/webmention.py b/webmention.py new file mode 100644 index 00000000..8f0636e9 --- /dev/null +++ b/webmention.py @@ -0,0 +1,47 @@ +from pathlib import Path +from datetime import datetime, timedelta +import requests +from pprint import pprint +import json +import os + +TOKEN = "-g5vlz9y3p5llrdS7TmnCg" +DOMAIN = "fundor333.com" +PER_PAGE = 999 +SINCE_DAY = 999 + +def elaborate_webmention(webmention:list, site:str, remove_paramas: bool): + for e in webmention["children"]: + slug = e["wm-target"] + + if remove_paramas is True: + slug = slug.split('?')[0] + + print(slug) + + slug = slug.replace(site, "").replace("\\", "") + ids= e['wm-id'] + + filename = os.path.join(f'data/webmentions/{slug}/{ids}.json') + + os.makedirs(os.path.dirname(filename), exist_ok=True) + with open(filename, "w") as f: + json.dump(e, f) + + +def get_webmention(remove_paramas: bool=True): + r = requests.get( + "https://webmention.io/api/mentions.jf2", + params={'domain': DOMAIN, + 'token':TOKEN, + 'since': datetime.today() - timedelta(days=SINCE_DAY), + 'per-page':PER_PAGE + } + ) + + elaborate_webmention(webmention=r.json(),site=f"https://{DOMAIN}", remove_paramas=remove_paramas) + + + + +get_webmention()