Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdbd committed May 6, 2024
1 parent 85694a5 commit 6bf5a4e
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 164 deletions.
21 changes: 12 additions & 9 deletions scripts/hacker-news/job-links.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { execSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import { debuglog } from 'node:util'
import { fileURLToPath } from 'node:url'
import PrettyError from 'pretty-error'
import defDebug from 'debug'
import yargs from 'yargs'
import { EMOJI, sendOutput } from '../utils.mjs'
import { defRenderTelegramErrorMessage, EMOJI, sendOutput } from '../utils.mjs'

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

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

const __filename = fileURLToPath(import.meta.url)
const splits = __filename.split('/')
const APP_ID = splits[splits.length - 1]
const app_id = splits[splits.length - 1]
const app_version = '0.1.0'

const DEFAULT = {
DESCRIPTION: 'Query description not provided',
QUERY: 'hacker-news-jobs-YC.sql'
}

const renderTelegramErrorMessage = defRenderTelegramErrorMessage({
header: `<b>${EMOJI.Robot} Hacker News job links</b>`,
footer: `<i>Sent by ${app_id} (vers. ${app_version})</i>`
})

const searchJobsOnHackerNews = async () => {
const argv = yargs(process.argv.slice(2))
.usage('node scripts/hacker-news/$0')
Expand Down Expand Up @@ -48,7 +51,7 @@ const searchJobsOnHackerNews = async () => {
const buf = execSync(`steampipe query "${sql}" --output json`)

return {
app_id: APP_ID,
app_id,
description: argv.description,
links: JSON.parse(buf.toString())
}
Expand Down Expand Up @@ -84,5 +87,5 @@ searchJobsOnHackerNews()
.then(renderTelegramMessage)
.then(sendOutput)
.catch((err) => {
console.log(pe.render(err))
sendOutput(renderTelegramErrorMessage(err)).then(console.log)
})
42 changes: 19 additions & 23 deletions scripts/hacker-news/post-ad-on-ask-hn-seeking-freelancer.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { debuglog } from 'node:util'
import defDebug from 'debug'
import { chromium } from 'playwright'
import { EMOJI, jsonSecret, sendOutput, waitMs } from '../utils.mjs'
import { latestPost } from '../hacker-news.cjs'
import {
defRenderTelegramErrorMessage,
EMOJI,
jsonSecret,
sendOutput,
waitMs
} from '../utils.mjs'
import { latestItemByUsername } from './utils.mjs'

const debug = debuglog('hn:post-ad')
const debug = defDebug('hn:post-ad')

const __filename = fileURLToPath(import.meta.url)
const splits = __filename.split('/')
const APP_ID = splits[splits.length - 1]
const app_id = splits[splits.length - 1]

const renderTelegramErrorMessage = defRenderTelegramErrorMessage({
header: `<b>${EMOJI.Robot} ASK HN: Freelancer? Seeking Freelancer?</b>`,
footer: `<i>Sent by ${app_id} (vers. ${app_version})</i>`
})

const renderTelegramSuccessMessage = (d) => {
let s = `<b>${EMOJI.Robot} ASK HN: Freelancer? Seeking Freelancer?</b>`
Expand All @@ -23,28 +34,13 @@ const renderTelegramSuccessMessage = (d) => {
s = s.concat(`<pre>${d.ad}</pre>`)

s = s.concat('\n\n')
s = s.concat(`<i>Sent by ${APP_ID}</i>`)
s = s.concat(`<i>Sent by ${app_id}</i>`)

// we need to add a newline character, otherwise the GitHub workflow will fail
// with this error: "Matching delimiter not found"
return s.concat('\n')
}

const renderTelegramErrorMessage = (err) => {
let s = `<b>${EMOJI.Robot} ASK HN: Freelancer? Seeking Freelancer?</b>`

s = s.concat('\n\n')
const title = err.name || 'Error'
s = s.concat(`<b>${title}</b>`)
s = s.concat('\n')
s = s.concat(`<pre>${err.message}</pre>`)

s = s.concat('\n\n')
s = s.concat(`<i>Sent by ${APP_ID}</i>`)

return s.concat('\n')
}

const postAdOnHackerNews = async ({ browser, hn_item_id }) => {
debug(`will try posting ad on Hacker News item ID ${hn_item_id}`)
let ad = ''
Expand Down Expand Up @@ -154,8 +150,8 @@ const main = async () => {

let hn_item_id = undefined
if (args.length === 0) {
const result = await latestPost()
hn_item_id = result.item_id
const item = await latestItemByUsername()
hn_item_id = item.id
} else if (args.length === 1) {
hn_item_id = args[0]
} else {
Expand Down
4 changes: 2 additions & 2 deletions scripts/hacker-news/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debuglog } from 'node:util'
import defDebug from 'debug'

const debug = debuglog('hn:utils')
const debug = defDebug('hn:utils')

export const userSubmissions = async (username) => {
const api_endpoint = `https://hacker-news.firebaseio.com/v0`
Expand Down
62 changes: 0 additions & 62 deletions scripts/hash.js

This file was deleted.

11 changes: 5 additions & 6 deletions scripts/reddit/post-ad-freelancing.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'node:fs'
import path from 'node:path'
import { debuglog } from 'node:util'
import { fileURLToPath } from 'node:url'
import PrettyError from 'pretty-error'
import defDebug from 'debug'
import snoowrap from 'snoowrap'
import yargs from 'yargs'
import {
Expand All @@ -13,9 +12,7 @@ import {
} from '../utils.mjs'
import { slugify, renderTelegramMessage, userAgent } from './utils.mjs'

const pe = new PrettyError()

const debug = debuglog('reddit:post-ad-freelancing')
const debug = defDebug('reddit:post-ad-freelancing')

const __filename = fileURLToPath(import.meta.url)
const splits = __filename.split('/')
Expand Down Expand Up @@ -149,4 +146,6 @@ const submitRedditPost = async () => {
submitRedditPost()
.then(renderTelegramMessage)
.then(sendOutput)
.catch((err) => renderTelegramErrorMessage(err).then(sendOutput))
.catch((err) => {
sendOutput(renderTelegramErrorMessage(err)).then(console.log)
})
8 changes: 5 additions & 3 deletions scripts/reddit/post-ad-smallbusiness.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { debuglog } from 'node:util'
import defDebug from 'debug'
import { fileURLToPath } from 'node:url'
import snoowrap from 'snoowrap'
import yargs from 'yargs'
Expand All @@ -12,7 +12,7 @@ import {
} from '../utils.mjs'
import { userAgent } from './utils.mjs'

const debug = debuglog('reddit:post-ad-smallbusiness')
const debug = defDebug('reddit:post-ad-smallbusiness')

const __filename = fileURLToPath(import.meta.url)
const splits = __filename.split('/')
Expand Down Expand Up @@ -156,4 +156,6 @@ const renderTelegramMessage = (d) => {
submitRedditPost()
.then(renderTelegramMessage)
.then(sendOutput)
.catch((err) => renderTelegramErrorMessage(err).then(sendOutput))
.catch((err) => {
sendOutput(renderTelegramErrorMessage(err)).then(console.log)
})
8 changes: 5 additions & 3 deletions scripts/reddit/post-ad-website-audit.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { debuglog } from 'node:util'
import defDebug from 'debug'
import { fileURLToPath } from 'node:url'
import snoowrap from 'snoowrap'
import yargs from 'yargs'
Expand All @@ -12,7 +12,7 @@ import {
} from '../utils.mjs'
import { slugify, renderTelegramMessage, userAgent } from './utils.mjs'

const debug = debuglog('reddit:post-ad-website-audit')
const debug = defDebug('reddit:post-ad-website-audit')

const __filename = fileURLToPath(import.meta.url)
const splits = __filename.split('/')
Expand Down Expand Up @@ -128,4 +128,6 @@ const submitRedditPost = async () => {
submitRedditPost()
.then(renderTelegramMessage)
.then(sendOutput)
.catch((err) => renderTelegramErrorMessage(err).then(sendOutput))
.catch((err) => {
sendOutput(renderTelegramErrorMessage(err)).then(console.log)
})
8 changes: 5 additions & 3 deletions scripts/reddit/search.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { fileURLToPath } from 'node:url'
import { debuglog } from 'node:util'
import defDebug from 'debug'
import yargs from 'yargs'
import { defRenderTelegramErrorMessage, EMOJI, sendOutput } from '../utils.mjs'
import { defSnoowrap } from './utils.mjs'

const debug = debuglog('reddit:search')
const debug = defDebug('reddit:search')

const __filename = fileURLToPath(import.meta.url)
const splits = __filename.split('/')
Expand Down Expand Up @@ -160,4 +160,6 @@ const renderTelegramMessage = (d) => {
searchOnReddit()
.then(renderTelegramMessage)
.then(sendOutput)
.catch((err) => renderTelegramErrorMessage(err).then(sendOutput))
.catch((err) => {
sendOutput(renderTelegramErrorMessage(err)).then(console.log)
})
4 changes: 2 additions & 2 deletions scripts/reddit/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os from 'node:os'
import { debuglog } from 'node:util'
import defDebug from 'debug'
import snoowrap from 'snoowrap'
import { jsonSecret } from '../utils.mjs'

const debug = debuglog('reddit:utils')
const debug = defDebug('reddit:utils')

export const slugify = (title) => {
return title
Expand Down
20 changes: 16 additions & 4 deletions scripts/stripe/renew-promotion-codes.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { debuglog } from 'node:util'
import defDebug from 'debug'
import PrettyError from 'pretty-error'
import Stripe from 'stripe'

import yargs from 'yargs'
import { jsonSecret, sendOutput, userAgent } from '../utils.js'
import {
defRenderTelegramErrorMessage,
EMOJI,
jsonSecret,
sendOutput,
userAgent
} from '../utils.js'
import { STRIPE_CONFIG } from './constants.js'
import { createOrUpdatePromotionCode, expiresInDays } from './utils.js'

const debug = debuglog('renew-promotion-codes')
const debug = defDebug('stripe:renew-promotion-codes')
const pe = new PrettyError()

const splits = new URL(import.meta.url).pathname.split('/')
const app_id = splits[splits.length - 1]
const app_version = '0.1.0'

const renderTelegramErrorMessage = defRenderTelegramErrorMessage({
header: `<b>${EMOJI.Robot} Stripe renew Promotion Codes</b>`,
footer: `<i>Sent by ${app_id} (vers. ${app_version})</i>`
})

interface Argv {
'expires-in-days': number
Expand Down Expand Up @@ -168,5 +180,5 @@ main()
.then(renderTelegramMessage)
.then(sendOutput)
.catch((err) => {
console.log(pe.render(err))
sendOutput(renderTelegramErrorMessage(err)).then(console.log)
})
45 changes: 0 additions & 45 deletions scripts/style-tags-contents.js

This file was deleted.

Loading

0 comments on commit 6bf5a4e

Please sign in to comment.