2021-08-03 15:05:50 -04:00
|
|
|
require('dotenv').config();
|
|
|
|
const Mustache = require('mustache');
|
|
|
|
const fetch = require('node-fetch');
|
2024-09-23 23:26:47 -04:00
|
|
|
const RssParser = require('rss-parser');
|
2021-08-03 15:05:50 -04:00
|
|
|
const fs = require('fs');
|
|
|
|
const puppeteerService = require('./services/puppeteer.service');
|
|
|
|
|
|
|
|
const MUSTACHE_MAIN_DIR = './main.mustache';
|
|
|
|
|
|
|
|
let DATA = {
|
|
|
|
refresh_date: new Date().toLocaleDateString('en-US', {
|
|
|
|
weekday: 'long',
|
|
|
|
month: 'long',
|
|
|
|
day: 'numeric',
|
|
|
|
hour: 'numeric',
|
|
|
|
minute: 'numeric',
|
|
|
|
timeZoneName: 'short',
|
|
|
|
timeZone: 'America/Detroit',
|
|
|
|
}),
|
2024-09-23 23:26:47 -04:00
|
|
|
posts: []
|
2021-08-03 15:05:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
async function setWeatherInformation() {
|
|
|
|
await fetch(
|
2024-09-23 23:26:47 -04:00
|
|
|
`https://api.openweathermap.org/data/2.5/weather?q=grand%20blanc%2C%20michigan&appid=${process.env.OPEN_WEATHER_MAP_KEY}&units=imperial`
|
2021-08-03 15:05:50 -04:00
|
|
|
)
|
|
|
|
.then(r => r.json())
|
|
|
|
.then(r => {
|
|
|
|
DATA.city_temperature = Math.round(r.main.temp);
|
|
|
|
DATA.city_weather = r.weather[0].description;
|
|
|
|
DATA.city_weather_icon = r.weather[0].icon;
|
|
|
|
DATA.sun_rise = new Date(r.sys.sunrise * 1000).toLocaleString('en-US', {
|
|
|
|
timeZone: 'America/Detroit',
|
|
|
|
});
|
|
|
|
DATA.sun_set = new Date(r.sys.sunset * 1000).toLocaleString('en-US', {
|
|
|
|
timeZone: 'America/Detroit',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-09-23 23:26:47 -04:00
|
|
|
async function setRssFeed() {
|
|
|
|
const parser = new RssParser()
|
|
|
|
await parser.parseURL("https://srp.life/feed")
|
|
|
|
.then(r => r.items.map(val => { if (!val.title.includes("Daily Orthodox") && val !== undefined) { return val; }}))
|
|
|
|
.then(r => {
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
if (r[i]) {
|
|
|
|
DATA.posts.push({ "title": r[i].title, "desc": r[i].summary, "link": r[i].link});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-03 15:05:50 -04:00
|
|
|
async function setInstagramPosts() {
|
|
|
|
const instagramImages = await puppeteerService.getLatestInstagramPostsFromAccount('orthodoxyforyou', 3);
|
|
|
|
DATA.img1 = instagramImages[0];
|
|
|
|
DATA.img2 = instagramImages[1];
|
|
|
|
DATA.img3 = instagramImages[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function generateReadMe() {
|
2021-08-03 15:11:12 -04:00
|
|
|
await fs.readFile(MUSTACHE_MAIN_DIR, (err, data) => {
|
2021-08-03 15:05:50 -04:00
|
|
|
if (err) throw err;
|
|
|
|
const output = Mustache.render(data.toString(), DATA);
|
|
|
|
fs.writeFileSync('README.md', output);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function action() {
|
|
|
|
/**
|
|
|
|
* Fetch Weather
|
|
|
|
*/
|
|
|
|
await setWeatherInformation();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get pictures
|
|
|
|
*/
|
|
|
|
await setInstagramPosts();
|
|
|
|
|
2024-09-23 23:26:47 -04:00
|
|
|
await setRssFeed();
|
|
|
|
|
2021-08-03 15:05:50 -04:00
|
|
|
/**
|
|
|
|
* Generate README
|
|
|
|
*/
|
|
|
|
await generateReadMe();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fermeture de la boutique 👋
|
|
|
|
*/
|
|
|
|
await puppeteerService.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
action();
|