Skip to content

Instantly share code, notes, and snippets.

@sergiosouzalima
Last active July 10, 2022 08:58
Show Gist options
  • Save sergiosouzalima/59485fe21602c583b7d772774eb41636 to your computer and use it in GitHub Desktop.
Save sergiosouzalima/59485fe21602c583b7d772774eb41636 to your computer and use it in GitHub Desktop.
## Program name........: wttrin_weather_lib.nim
## Program description.: Testing Nim library that fetches weather from wttr.in
## Author..............: Sergio Lima
## Created on..........: Jul, 9 2022
## Install lib
## $ nimble install wttrin -y
## How to compile
## $ nim c -d:ssl wttrin_weather_lib.nim
## How to run
## $ ./wttrin_weather_lib
import wttrin
import std/strformat
const citiesTuple = (
saopaulo: "Sao Paulo-SP",
maringa: "Maringa-PR",
fortaleza: "Fortaleza-CE",
manaus: "Manaus-AM")
proc getWeather(city: string): (string, string, string) =
return ($getTemp(city), $getUnit(city), getCondition(city))
for city, cityName in citiesTuple.fieldPairs:
let (temp, unit, cond) = getWeather(city)
echo cityName & fmt""" {temp}{unit} {cond}"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment