Skip to content

Instantly share code, notes, and snippets.

@RussellDash332
Last active July 28, 2021 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RussellDash332/73ebeddb1228bfd3f07d77f2acaaa8f8 to your computer and use it in GitHub Desktop.
Save RussellDash332/73ebeddb1228bfd3f07d77f2acaaa8f8 to your computer and use it in GitHub Desktop.
index.js for my first Medium post
require('dotenv').config();
const Mustache = require('mustache');
const fetch = require('node-fetch');
const fs = require('fs');
const MUSTACHE_MAIN_DIR = './main.mustache';
let DATA = {
name: 'Russell',
date: new Date().toLocaleDateString('en-GB', {
weekday: 'long',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZoneName: 'short',
timeZone: 'Asia/Singapore',
}),
};
async function setWeatherInformation() {
await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=Singapore&appid=${process.env.OPEN_WEATHER_MAP_KEY}&units=metric`
)
.then(r => r.json())
.then(r => {
DATA.temperature = Math.round(r.main.temp);
DATA.weather = r.weather[0].description;
});
}
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() {
await setWeatherInformation();
await generateReadMe();
}
action();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment