-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d532f1f
commit ab217e1
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { readJSON, writeJSON } from 'https://deno.land/x/flat/mod.ts' | ||
import { cheerio } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
interface Post { | ||
creator?: { | ||
name: string, | ||
url: string, | ||
} | ||
datePublished?: Date, | ||
content?: string, | ||
} | ||
|
||
// The filename is the first invocation argument | ||
const filename = Deno.args[0] // Same name as downloaded_filename | ||
//const data = await readJSON(filename) | ||
const html = await Deno.readTextFile("./dataview-plugin-snippet-showcase.html"); | ||
const $ = cheerio.load(html); | ||
|
||
const posts = $('div[class="topic-body crawler-post"]'); | ||
var rawData: Array<Post> = [] | ||
await posts.each(function(index, data) { | ||
const post = cheerio.load(data); | ||
const creatorName = post('a[itemprop=url] > span[itemprop=name]'); | ||
const creatorUrl = post('span[class=creator] > a[itemprop=url]'); | ||
const publishedDate = post("span[class=crawler-post-infos] > time[itemprop=datePublished]"); | ||
const publishDate = publishedDate.first().attr('datetime')?.toString(); | ||
const content = post('div[class=post]')?.html() || ''; | ||
rawData.push({ | ||
creator: { | ||
url: creatorUrl.first().attr('href')?.toString() || '', | ||
name: creatorName.text(), | ||
}, | ||
datePublished: publishDate ? new Date(publishDate): new Date(), | ||
content, | ||
}) | ||
} | ||
); | ||
const dataviewCodes = rawData.filter(post => post.content?.includes('```dataview')); | ||
for (const codePosts of dataviewCodes){ | ||
const fileName =`${codePosts.creator?.name || ''}_${codePosts.datePublished?.getTime()}.json` | ||
await writeJSON(`./scripts/${fileName}`, codePosts); | ||
} | ||
console.log(JSON.stringify(dataviewCodes));// Pluck a specific key off |
Empty file.