Spaces:
Runtime error
Runtime error
Merge branch 'main' of https://huggingface.co/spaces/XicoC/AIM-Endpoint-Assignment
Browse files- .gitattributes +1 -0
- data/paul-graham-to-kindle/.gitignore +32 -0
- data/paul-graham-to-kindle/README.md +25 -0
- data/paul-graham-to-kindle/jsconfig.json +7 -0
- data/paul-graham-to-kindle/lib/metadata.xml +6 -0
- data/paul-graham-to-kindle/lib/pg.js +104 -0
- data/paul-graham-to-kindle/metadata.xml +6 -0
- data/paul-graham-to-kindle/package.json +14 -0
- data/paul-graham-to-kindle/paul_graham_essays.epub +3 -0
- data/paul-graham-to-kindle/paul_graham_essays.txt +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
data/paul-graham-to-kindle/paul_graham_essays.epub filter=lfs diff=lfs merge=lfs -text
|
data/paul-graham-to-kindle/.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
| 2 |
+
|
| 3 |
+
# dependencies
|
| 4 |
+
/node_modules
|
| 5 |
+
/.pnp
|
| 6 |
+
.pnp.js
|
| 7 |
+
|
| 8 |
+
# testing
|
| 9 |
+
/coverage
|
| 10 |
+
|
| 11 |
+
# next.js
|
| 12 |
+
/.next/
|
| 13 |
+
/out/
|
| 14 |
+
|
| 15 |
+
# production
|
| 16 |
+
/build
|
| 17 |
+
|
| 18 |
+
# misc
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.pem
|
| 21 |
+
|
| 22 |
+
# debug
|
| 23 |
+
npm-debug.log*
|
| 24 |
+
yarn-debug.log*
|
| 25 |
+
yarn-error.log*
|
| 26 |
+
.pnpm-debug.log*
|
| 27 |
+
|
| 28 |
+
# local env files
|
| 29 |
+
.env*.local
|
| 30 |
+
|
| 31 |
+
# vercel
|
| 32 |
+
.vercel
|
data/paul-graham-to-kindle/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PaulG to Kindle
|
| 2 |
+
|
| 3 |
+
Hackers and Painters was amazing, but I wanted to read the rest of Paul's essays on my Kindle. I couldn't find a way to do this, so I wrote a script to convert the essays to epub format.
|
| 4 |
+
|
| 5 |
+
Make sure you have pandoc installed.
|
| 6 |
+
|
| 7 |
+
`brew install pandoc`
|
| 8 |
+
|
| 9 |
+
Then run the script:
|
| 10 |
+
|
| 11 |
+
`npm i && npm run generate`
|
| 12 |
+
|
| 13 |
+
Either email the generated `paul_graham_essays.epub` file to your Kindle email address as an attachment OR send to your kindle from [amazon.com/sendtokindle](https://www.amazon.com/sendtokindle).
|
| 14 |
+
|
| 15 |
+
## How to find Kindle email address
|
| 16 |
+
|
| 17 |
+
1. Go to [Manage Your Content and Devices](https://www.amazon.com/gp/digital/fiona/manage)
|
| 18 |
+
|
| 19 |
+
2. Click on the device you want to send the email to
|
| 20 |
+
|
| 21 |
+
3. Click on the `Settings` tab
|
| 22 |
+
|
| 23 |
+
4. Scroll down to `Send-to-Kindle Email Settings`
|
| 24 |
+
|
| 25 |
+
5. Copy the email address
|
data/paul-graham-to-kindle/jsconfig.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"paths": {
|
| 4 |
+
"@/*": ["./*"]
|
| 5 |
+
}
|
| 6 |
+
}
|
| 7 |
+
}
|
data/paul-graham-to-kindle/lib/metadata.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<metadata xmlns="http://purl.org/dc/elements/1.1/">
|
| 3 |
+
<dc:title>Paul Graham Essays</dc:title>
|
| 4 |
+
<dc:creator>Paul Graham</dc:creator>
|
| 5 |
+
<dc:language>en</dc:language>
|
| 6 |
+
</metadata>
|
data/paul-graham-to-kindle/lib/pg.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const axios = require('axios');
|
| 2 |
+
const cheerio = require('cheerio');
|
| 3 |
+
const { spawn } = require('child_process');
|
| 4 |
+
const fs = require('fs');
|
| 5 |
+
const TurndownService = require('turndown');
|
| 6 |
+
|
| 7 |
+
const turndownService = new TurndownService();
|
| 8 |
+
|
| 9 |
+
const essaysListUrl = 'http://www.paulgraham.com/articles.html';
|
| 10 |
+
|
| 11 |
+
async function main() {
|
| 12 |
+
try {
|
| 13 |
+
const essays = await getEssayLinks();
|
| 14 |
+
essays.reverse();
|
| 15 |
+
const essayTexts = await Promise.all(essays.map((essay) => getEssayText(essay)));
|
| 16 |
+
|
| 17 |
+
const combinedText = essayTexts.join('\n\n');
|
| 18 |
+
console.log('Combined text:', combinedText);
|
| 19 |
+
fs.writeFileSync('paul_graham_essays.txt', combinedText);
|
| 20 |
+
|
| 21 |
+
const outputFile = 'paul_graham_essays.epub';
|
| 22 |
+
await generateEpub('paul_graham_essays.txt', outputFile);
|
| 23 |
+
console.log(`EPUB file generated: ${outputFile}`);
|
| 24 |
+
} catch (error) {
|
| 25 |
+
console.error('Error:', error);
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function generateEpub(inputFile, outputFile) {
|
| 30 |
+
return new Promise((resolve, reject) => {
|
| 31 |
+
const pandoc = spawn('pandoc', [
|
| 32 |
+
inputFile,
|
| 33 |
+
'-o',
|
| 34 |
+
outputFile,
|
| 35 |
+
'--toc',
|
| 36 |
+
'--toc-depth=1',
|
| 37 |
+
'--metadata',
|
| 38 |
+
'title="Paul Graham Essays"'
|
| 39 |
+
]);
|
| 40 |
+
|
| 41 |
+
pandoc.stdout.on('data', (data) => {
|
| 42 |
+
console.log(`stdout: ${data}`);
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
pandoc.stderr.on('data', (data) => {
|
| 46 |
+
console.error(`stderr: ${data}`);
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
pandoc.on('close', (code) => {
|
| 50 |
+
if (code === 0) {
|
| 51 |
+
resolve();
|
| 52 |
+
} else {
|
| 53 |
+
reject(new Error(`pandoc exited with code ${code}`));
|
| 54 |
+
}
|
| 55 |
+
});
|
| 56 |
+
});
|
| 57 |
+
}
|
| 58 |
+
const baseUrl = 'http://www.paulgraham.com/';
|
| 59 |
+
|
| 60 |
+
async function getEssayLinks() {
|
| 61 |
+
const response = await axios.get(essaysListUrl);
|
| 62 |
+
const $ = cheerio.load(response.data);
|
| 63 |
+
|
| 64 |
+
const links = [];
|
| 65 |
+
|
| 66 |
+
$('a').each((_, link) => {
|
| 67 |
+
const url = $(link).attr('href');
|
| 68 |
+
if (url && url.endsWith('.html')) {
|
| 69 |
+
links.push(baseUrl + url);
|
| 70 |
+
}
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
return links;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
async function getEssayText(url) {
|
| 77 |
+
try {
|
| 78 |
+
const response = await axios.get(url);
|
| 79 |
+
const $ = cheerio.load(response.data);
|
| 80 |
+
|
| 81 |
+
$('script').remove();
|
| 82 |
+
$('img').remove();
|
| 83 |
+
|
| 84 |
+
const title = $('title').text();
|
| 85 |
+
const htmlContent = $('body').html();
|
| 86 |
+
const markdownContent = turndownService.turndown(htmlContent);
|
| 87 |
+
|
| 88 |
+
return `\n\n# ${title}\n\n${markdownContent}`;
|
| 89 |
+
} catch (error) {
|
| 90 |
+
console.error(`Error fetching essay: ${url}\n${error}`);
|
| 91 |
+
return '';
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
main().then(() => {
|
| 96 |
+
const outputFile = 'paul_graham_essays.epub';
|
| 97 |
+
generateEpub('paul_graham_essays.txt', outputFile, (error) => {
|
| 98 |
+
if (error) {
|
| 99 |
+
console.error('Error generating EPUB file:', error);
|
| 100 |
+
return;
|
| 101 |
+
}
|
| 102 |
+
console.log(`EPUB file generated: ${outputFile}`);
|
| 103 |
+
});
|
| 104 |
+
});
|
data/paul-graham-to-kindle/metadata.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<metadata xmlns="http://purl.org/dc/elements/1.1/">
|
| 3 |
+
<dc:title>Paul Graham Essays</dc:title>
|
| 4 |
+
<dc:creator>Paul Graham</dc:creator>
|
| 5 |
+
<dc:language>en</dc:language>
|
| 6 |
+
</metadata>
|
data/paul-graham-to-kindle/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "paulg-to-kindle",
|
| 3 |
+
"version": "0.1.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"scripts": {
|
| 6 |
+
"generate": "node ./lib/pg.js"
|
| 7 |
+
},
|
| 8 |
+
"dependencies": {
|
| 9 |
+
"axios": "^1.3.5",
|
| 10 |
+
"cheerio": "^1.0.0-rc.12",
|
| 11 |
+
"html-to-text": "^9.0.5",
|
| 12 |
+
"turndown": "^7.1.2"
|
| 13 |
+
}
|
| 14 |
+
}
|
data/paul-graham-to-kindle/paul_graham_essays.epub
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:051f282341cab2a14b11bf77cf2f858fdc51700136b617a95577e6b529734c64
|
| 3 |
+
size 1364157
|
data/paul-graham-to-kindle/paul_graham_essays.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|