2021-08-03 15:05:50 -04:00
|
|
|
require('dotenv').config();
|
|
|
|
const Mustache = require('mustache');
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
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',
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
async function setWeatherInformation() {
|
|
|
|
await fetch(
|
2022-02-07 23:19:59 -05:00
|
|
|
`https://api.openweathermap.org/data/2.5/weather?q=fenton%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',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate README
|
|
|
|
*/
|
|
|
|
await generateReadMe();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fermeture de la boutique 👋
|
|
|
|
*/
|
|
|
|
await puppeteerService.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
action();
|