forked from thmsgbrt/thmsgbrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (70 loc) · 1.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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-GB', {
weekday: 'long',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZoneName: 'short',
timeZone: 'Europe/Stockholm',
}),
};
async function setWeatherInformation() {
await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=stockholm&appid=${process.env.OPEN_WEATHER_MAP_KEY}&units=metric`
)
.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-GB', {
hour: '2-digit',
minute: '2-digit',
timeZone: 'Europe/Stockholm',
});
DATA.sun_set = new Date(r.sys.sunset * 1000).toLocaleString('en-GB', {
hour: '2-digit',
minute: '2-digit',
timeZone: 'Europe/Stockholm',
});
});
}
async function setInstagramPosts() {
const instagramImages = await puppeteerService.getLatestInstagramPostsFromAccount('visitstockholm', 3);
DATA.img1 = instagramImages[0];
DATA.img2 = instagramImages[1];
DATA.img3 = instagramImages[2];
}
async function generateReadMe() {
await fs.readFile(MUSTACHE_MAIN_DIR, (err, data) => {
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();