Skip to content

Commit

Permalink
update: first working release
Browse files Browse the repository at this point in the history
  • Loading branch information
Rooyca committed Mar 13, 2024
1 parent 774026c commit e456858
Show file tree
Hide file tree
Showing 4 changed files with 10,494 additions and 1 deletion.
20 changes: 19 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
name: Build and Deploy
on: [push]
on:
push:
schedule:
- cron: '0 00 * * *' # At 00:00 everyday
workflow_dispatch:

permissions:
contents: write
jobs:
create-current:
# the job runs a js script to create a current.json file
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Create current.json 📝
run: node ./builder/builder.js

- name: Move current.json 📝
run: mv current.json src/current.json

build-and-deploy:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
Expand Down
40 changes: 40 additions & 0 deletions builder/builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Function to generate sequential numbers
function generateSequentialNumbers(startDate, endDate) {
let result = [];
let currentDate = new Date(startDate);

while (currentDate <= endDate) {
result.push(currentDate.getTime());
currentDate.setDate(currentDate.getDate() + 1);
}
return result;
}

function getMovieFromJsonAtIndex(index){
const movies = require('./movies.json');
return movies['movies'][index];
}

// Set the start and end dates
const startDate = new Date('2024-03-13'); // Current date
const endDate = new Date('2027-05-15'); // End date

// Generate sequential numbers
const sequentialNumbers = generateSequentialNumbers(startDate, endDate);

const today = new Date();
const formattedDate = today.toISOString().split('T')[0];

for (let index = 0; index < sequentialNumbers.length; index++) {
const number = sequentialNumbers[index];
const date = new Date(number);
if (date.toISOString().split('T')[0] === formattedDate) {
console.log(`Today's number is: ${index+1}`);
const movieToday = getMovieFromJsonAtIndex(index);
console.log(`Today's movie: ${movieToday}`);
const fs = require('fs');
const content = JSON.stringify(movieToday);
fs.writeFileSync('current.json', content);
break;
}
}
Loading

0 comments on commit e456858

Please sign in to comment.