Skip to content

Commit

Permalink
Packeges update, npmignore changed
Browse files Browse the repository at this point in the history
  • Loading branch information
AleshaOleg committed May 1, 2018
1 parent 4a2e7fa commit d4f006b
Show file tree
Hide file tree
Showing 4 changed files with 2,339 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.gitignore
.eslintrc
.npmignore

node_modules/
npm-debug.log

.idea/
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const request = require('request')

const apiKey = 'f2d5b989dfafdab237be56401ef53185'

const fahrenheitCountries = ['KY', 'BS', 'BZ', 'PW', 'US', 'PR', 'GU', 'UM']
const imperialCountries = ['KY', 'BS', 'BZ', 'PW', 'US', 'PR', 'GU', 'UM']

extIP.get().then(ip => {
const geo = geoip.lookup(ip)
const isFahrenheitCountry = fahrenheitCountries.indexOf(geo.country) > -1
const req = 'http://api.openweathermap.org/data/2.5/weather?'
request(`${req}lat=${geo.ll[0]}&lon=${geo.ll[1]}&appid=${apiKey}&units=metric`,
const isImperialCountry = imperialCountries.indexOf(geo.country) > -1
const baseUrl = 'http://api.openweathermap.org/data/2.5/weather?'
const units = isImperialCountry ? 'imperial' : 'metric'
request(`${baseUrl}lat=${geo.ll[0]}&lon=${geo.ll[1]}&appid=${apiKey}&units=${units}`,
(err, res, body) => {
if (!err) {
const response = JSON.parse(body)
const temp = isFahrenheitCountry ? (response.main.temp * (9 / 5)) + 32 : response.main.temp
const tempRound = (Math.round(temp * 2) / 2).toFixed(1)
const tempScale = isFahrenheitCountry ? '°F' : '°C'
const tempRound = (Math.round(response.main.temp * 2) / 2).toFixed(1)
const tempScale = isImperialCountry ? '°F' : '°C'
console.log(`Current weather in ${response.name}: ${tempRound}${tempScale}, ${response.weather[0].main}`)
} else {
console.log(`Can't get weather. Try again.\nMore: ${err}`)
Expand Down
Loading

0 comments on commit d4f006b

Please sign in to comment.