|
| 1 | +name: Scrape Codex Links |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - "prompts/**/*.md" |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + scrape: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repo |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Node.js |
| 20 | + uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + node-version: 20 |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + sudo apt-get update |
| 27 | + sudo apt-get install -y xvfb jq |
| 28 | + |
| 29 | +
|
| 30 | + - name: Find new Codex links |
| 31 | + id: find |
| 32 | + run: | |
| 33 | + links=$(grep -Eroh 'https://chatgpt.com/s/[A-Za-z0-9_]+' prompts || true) |
| 34 | + if [ -z "$links" ]; then |
| 35 | + echo "No Codex links found." |
| 36 | + exit 0 |
| 37 | + fi |
| 38 | + echo "links<<EOF" >> $GITHUB_OUTPUT |
| 39 | + echo "$links" >> $GITHUB_OUTPUT |
| 40 | + echo "EOF" >> $GITHUB_OUTPUT |
| 41 | +
|
1 | 42 | - name: Scrape and append prompt text |
2 | 43 | if: steps.find.outputs.links != '' |
3 | 44 | run: | |
4 | | - # Inline Puppeteer scraper |
5 | 45 | cat > scrape.js <<'EOF' |
6 | 46 | import puppeteer from 'puppeteer'; |
7 | 47 | const [,, url] = process.argv; |
|
12 | 52 | }); |
13 | 53 | const page = await browser.newPage(); |
14 | 54 | await page.goto(url, { waitUntil: 'networkidle2', timeout: 120000 }); |
15 | | -
|
16 | | - // Delay for hydration (waitForTimeout removed in newer Puppeteer) |
17 | | - await new Promise(r => setTimeout(r, 5000)); |
18 | | -
|
| 55 | + await new Promise(r => setTimeout(r, 5000)); // delay for hydration |
19 | 56 | const text = await page.evaluate(() => { |
20 | 57 | const container = document.querySelector('main') || document.body; |
21 | 58 | return container.innerText.trim(); |
22 | 59 | }); |
23 | | -
|
24 | 60 | console.log(text.slice(0, 3000)); |
25 | 61 | await browser.close(); |
26 | 62 | })(); |
|
50 | 86 | done |
51 | 87 | done <<< "$(echo "${{ steps.find.outputs.links }}")" |
52 | 88 |
|
53 | | - # Clean up temp files to avoid 'untracked files' noise |
54 | 89 | rm -rf node_modules package-lock.json package.json scrape.js |
| 90 | +
|
| 91 | + - name: Commit and push results |
| 92 | + run: | |
| 93 | + git config user.name "github-actions[bot]" |
| 94 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 95 | + git add prompts |
| 96 | + git commit -m "Auto-scraped Codex prompts" || echo "No new content to commit." |
| 97 | + git push |
0 commit comments