Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/08/21 in Posts

  1. const fetch = require('node-fetch'); const url = 'http://api.weatherapi.com/v1/current.json?key=c5aab2441e9248e49ee81903201910&q=bucharest'; setInterval(() => { fetch(url) .then(res => res.json()) .then(json => { let code = json.current.condition.code; switch (code) { case 1000: mp.world.weather = 'EXTRASUNNY' break; case 1003: mp.world.weather = 'CLOUDS' break; case 1006: mp.world.weather = 'CLOUDS' break; case 1066: mp.world.weather = 'SNOW' break; case 1135: mp.world.weather = 'FOGGY' break; case 1183: mp.world.weather = 'RAIN' break; case 1189: mp.world.weather = 'RAIN' break; case 1273: mp.world.weather = 'THUNDER' break; default: mp.world.weather = 'CLEAR' } console.log("[WEATHER-SYNC] Server weather is synced with Bucharest (" + json.current.condition.text + ")"); }) .catch(function(err){ console.log("There was an error running the weather.js script ! ", err) }); }, 600000) Requirements: npm i request npm i request-promise In the API call change the 'q' parameter to the city you want to sync to, and provide your API key from WeatherAPI The script syncs the weather once evry 10 minutes, you can change that by modifying the 'setInterval' loop.
    1 point
  2. Más información no estaría de más. - Qué tenéis hasta la fecha - Qué expectativas tenéis
    1 point
  3. Seeing how the request and request-promise packages are now deprecated, has anyone attempted using the node-fetch package with this yet? Edit: I was able to make it work with the node-fetch package using your code with slight modifications: const fetch = require('node-fetch'); const url = 'http://api.weatherapi.com/v1/current.json?key=c5aab2441e9248e49ee81903201910&q=bucharest'; setInterval(() => { fetch(url) .then(res => res.json()) .then(json => { let code = json.current.condition.code; switch (code) { case 1000: mp.world.weather = 'EXTRASUNNY' break; case 1003: mp.world.weather = 'CLOUDS' break; case 1006: mp.world.weather = 'CLOUDS' break; case 1066: mp.world.weather = 'SNOW' break; case 1135: mp.world.weather = 'FOGGY' break; case 1183: mp.world.weather = 'RAIN' break; case 1189: mp.world.weather = 'RAIN' break; case 1273: mp.world.weather = 'THUNDER' break; default: mp.world.weather = 'CLEAR' } console.log("[WEATHER-SYNC] Server weather is synced with Bucharest (" + json.current.condition.text + ")"); }) .catch(function(err){ console.log("There was an error running the weather.js script ! ", err) }); }, 600000) (I had to convert it back to your format, as I made modifications for my own usage, so if something is broken, please let me know). Additionally, instead of using the deprecated request and request-promise packages, I used the node-fetch package instead: npm i node-fetch Hopefully this helps! Edit #2: For the new people, please change the key in the URL to your own!
    1 point
  4. Sorry for my ignorance, but this script goes in packages right?
    0 points
×
×
  • Create New...