Skip to content

Commit

Permalink
adding month/year inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
IDCs committed Jul 24, 2024
1 parent 17bfa8b commit 785bdad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
39 changes: 33 additions & 6 deletions .github/workflows/add-mods-of-the-month.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,37 @@ on:
default: ''
required: true
type: string
date:
description: 'UNIX timestamp (optional, used instead of current date)'
default: ''
required: false
type: string
month:
description: 'Month of video'
required: true
default: 'January'
type: choice
options:
- 'January'
- 'February'
- 'March'
- 'April'
- 'May'
- 'June'
- 'July'
- 'August'
- 'September'
- 'October'
- 'November'
- 'December'
year:
description: 'Year of video'
required: true
default: '2024'
type: choice
options:
- '2024'
- '2025'
- '2026'
- '2027'
- '2028'
- '2029'
- '2030'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand All @@ -28,7 +54,8 @@ jobs:

env:
EXT_MOTM_LINK: ${{ inputs.link }}
EXT_MOTM_DATE: ${{ inputs.date }}
EXT_MOTM_MONTH: ${{ inputs.month }}
EXT_MOTM_YEAR: ${{ inputs.year }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
39 changes: 27 additions & 12 deletions src/add-mods-of-month.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,34 @@ const MOTM_ARCHIVE_PATH: string = path.join(REPO_ROOT_PATH, 'archive');

// env variables
const EXT_MOTM_LINK = process.env.EXT_MOTM_LINK || '';
const EXT_MOTM_DATE = process.env.EXT_MOTM_DATE || '';
const EXT_MOTM_MONTH = process.env.EXT_MOTM_MONTH || '';
const EXT_MOTM_YEAR = process.env.EXT_MOTM_YEAR || '';

const MONTH_DICT: { [key: string]: number } = {
'January': 1,
'February': 2,
'March': 3,
'April': 4,
'May': 5,
'June': 6,
'July': 7,
'August': 8,
'September': 9,
'October': 10,
'November': 11,
'December': 12
}

async function start() {

console.log('Start Program');

if (EXT_MOTM_LINK === '') {
console.error('No EXT_MOTM_LINK found in env');
process.exit(1);
}

if (EXT_MOTM_DATE !== '' && isNaN(+EXT_MOTM_DATE)) {
console.error('EXT_MOTM_DATE is not a unix timestamp number');
process.exit(1);
}
[EXT_MOTM_LINK, EXT_MOTM_MONTH, EXT_MOTM_YEAR].forEach((envVar) => {
if (envVar === '') {
console.error(`No ${envVar} found in env`);
process.exit(1);
}
});

const driver = new Driver();
await driver.process();
Expand Down Expand Up @@ -70,11 +83,13 @@ class Driver {


public async process() {
console.log('main env variables', { EXT_MOTM_LINK, EXT_MOTM_DATE });
console.log('main env variables', { EXT_MOTM_LINK, EXT_MOTM_MONTH, EXT_MOTM_YEAR });
console.log('Processing MOTM...');
this.mEntries = await this.readMOTMFile();
const timestampMS = new Date(+EXT_MOTM_YEAR, MONTH_DICT[EXT_MOTM_MONTH]).getTime();
const date = Math.floor(timestampMS / 1000);
const newEntry: IMOTMEntry = {
date: !!EXT_MOTM_DATE ? +EXT_MOTM_DATE : Date.now(),
date,
id: nanoid.nanoid(),
videoid: this.extractVideoIdFromYouTubeUrl(EXT_MOTM_LINK)
}
Expand Down

0 comments on commit 785bdad

Please sign in to comment.