This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM caian/sample-devcontainer:latest AS devcontainer | ||
|
||
ARG DOCKER_DEFAULT_USER=turing | ||
ENV DOCKER_DEFAULT_USER $DOCKER_DEFAULT_USER | ||
|
||
USER ${DOCKER_DEFAULT_USER} | ||
WORKDIR /home/${DOCKER_DEFAULT_USER} | ||
|
||
COPY entrypoint.sh . | ||
RUN sudo chmod +x entrypoint.sh | ||
|
||
|
||
FROM devcontainer AS dependencies | ||
USER root | ||
COPY package.json . | ||
COPY package-lock.json . | ||
|
||
RUN eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" \ | ||
&& npm install --only=production \ | ||
&& rm package.json package-lock.json | ||
|
||
|
||
FROM dependencies AS run | ||
COPY index.js . | ||
RUN chown -R "${DOCKER_DEFAULT_USER}:${DOCKER_DEFAULT_USER}" "/home/${DOCKER_DEFAULT_USER}" | ||
|
||
USER ${DOCKER_DEFAULT_USER} | ||
ENTRYPOINT ["./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" | ||
|
||
node index.js "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const axios = require('axios') | ||
const dayjs = require('dayjs') | ||
|
||
const capitalize = s => s && s[0].toUpperCase() + s.slice(1) | ||
|
||
const getDate = (daysToAdd = 0) => dayjs().add(daysToAdd, 'days').format('YYYY-MM-DD') | ||
|
||
function getCityArg() { | ||
const fallback = 'manhattan' | ||
|
||
const city = (process.argv.length < 3 ? fallback : process.argv[2]).trim() | ||
return city.length > 0 ? city : fallback | ||
} | ||
|
||
async function getWeatherInfoOf(city) { | ||
const { data } = await axios.get(`https://goweather.herokuapp.com/weather/${city}`) | ||
const forecast = [{ day: '0', temperature: data.temperature, wind: data.wind }, ...data.forecast] | ||
|
||
return forecast.map((f) => ({ day: parseInt(f.day), temp: f.temperature, wind: f.wind })) | ||
} | ||
|
||
async function main() { | ||
const city = getCityArg() | ||
const forecast = await getWeatherInfoOf(city) | ||
|
||
console.log(`Weather forecast for ${capitalize(city)} city\n`) | ||
for (const weather of forecast) { | ||
console.log(` | ${getDate(weather.day)} ~ ${weather.temp}, ${weather.wind}`) | ||
} | ||
} | ||
|
||
main().catch((e) => console.error(e)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "node-weather-app", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"author": "Caian Ertl <[email protected]>", | ||
"license": "CC0-1.0", | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"dayjs": "^1.11.2" | ||
} | ||
} |