Skip to content

Commit

Permalink
update scripts for Hacker News
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdbd committed Jun 3, 2024
1 parent cf324a7 commit 44411ed
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ask-hn-freelancer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
schedule:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
# https://crontab.guru/
- cron: '45 15 5 * *'
- cron: '45 15 5 * *' # UTC time
workflow_dispatch:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# You can trigger this workflow manually using the GitHub CLI:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hn-links-to-telegram.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
schedule:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
# https://crontab.guru/
- cron: '55 10 * * 1'
- cron: '55 10 * * 1' # UTC time
workflow_dispatch:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# You can trigger this workflow manually using the GitHub CLI:
Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# depends on jsdom, which depends on canvas.
# On Linux, canvas requires the shared object file libuuid.so, and we
# must explicitly require the package libuuid otherwise the build fails.
buildInputs = [pkgs.libuuid];
# buildInputs = [pkgs.libuuid];

shellHook = ''
echo "🌐 personal website dev shell"
Expand Down Expand Up @@ -88,7 +88,7 @@
# LD_LIBRARY_PATH the path to that package, so the linker can find
# libuuid.so. On NixOS the path to libuuid.so is not added to the linker,
# so we must add it manually.
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [pkgs.libuuid];
# LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [pkgs.libuuid];
# See also:
# https://discourse.nixos.org/t/node-libuuid-so-1-not-found/34864
# https://github.com/Automattic/node-canvas/issues/1893#issuecomment-1096988007
Expand Down
8 changes: 6 additions & 2 deletions scripts/hacker-news/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Scripts that I use to search and post stuff on Hacker News.

> :warning: **Steampipe on NixOS**
>
> Some scripts use Steampipe and a [Steampipe](https://github.com/turbot/steampipe) plugin to run a query. As explained in [this issue](https://github.com/NixOS/nixpkgs/issues/215945), using Steampipe is a bit of a mess. The easiest way is to run it in Docker.
## Search

### Search jobs on HN
Expand Down Expand Up @@ -36,9 +40,9 @@ Retrieve the item ID of the Hacker News story `Ask HN: Freelancer? Seeking Freel

```sh
# posted this month (there might not be one yet)
node scripts/hacker-news/whoishiring-item-id.cjs
node scripts/hacker-news/whoishiring-item-id.mjs
# posted in June 2023
node scripts/hacker-news/whoishiring-item-id.cjs 'June 2023'
node scripts/hacker-news/whoishiring-item-id.mjs 'June 2023'
```

## Post
Expand Down
16 changes: 13 additions & 3 deletions scripts/hacker-news/job-links.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import path from 'node:path'
import { fileURLToPath } from 'node:url'
import defDebug from 'debug'
import yargs from 'yargs'
import { defRenderTelegramErrorMessage, EMOJI, sendOutput } from '../utils.mjs'
import {
defRenderTelegramErrorMessage,
EMOJI,
sendOutput,
steampipe
} from '../utils.mjs'

const debug = defDebug('hn:job-links')

Expand Down Expand Up @@ -48,7 +53,11 @@ const searchJobsOnHackerNews = async () => {
debug(`use SQL query found at ${filepath}`)
const sql = fs.readFileSync(filepath).toString()
debug(`execute this SQL query with steampipe:\n${sql}`)
const buf = execSync(`steampipe query "${sql}" --output json`)

const buf = execSync(`${steampipe} query "${sql}" --output json`)
// const buf = execSync(
// `${steampipe} query "select title from hackernews_job;"`
// )

return {
app_id,
Expand All @@ -68,9 +77,10 @@ const renderTelegramMessage = (d) => {
s = s.concat('<b>Description</b>')
s = s.concat('\n')
s = s.concat(d.description)
console.log('=== d.links.rows ===', d.links.rows)

s = s.concat('\n\n')
const entries = d.links.map(anchor)
const entries = d.links.rows.map(anchor)
s = s.concat('<b>Job links</b>')
s = s.concat('\n')
s = s.concat(entries.join('\n\n'))
Expand Down
13 changes: 13 additions & 0 deletions scripts/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ export const defRenderTelegramErrorMessage = (
return `${s}\n\n${footer}\n`
}
}

// Running the Steampipe binary on NixOS is a bit of a mess, so on NixOS we run
// it in a Docker container as a workaround.
// https://github.com/NixOS/nixpkgs/issues/215945
export const steampipe =
process.env.HOME === '/home/jack'
? [
`docker run --rm`,
`--mount $"type=bind,source=/home/jack/steampipe/config,target=/home/steampipe/.steampipe/config"`,
`--name steampipe`,
`turbot/steampipe:latest`
].join(' ')
: 'steampipe'

0 comments on commit 44411ed

Please sign in to comment.