-
Notifications
You must be signed in to change notification settings - Fork 4
/
weather.py
executable file
·37 lines (32 loc) · 1.01 KB
/
weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/python
# -*- coding: utf-8 -*-
# Procedure
# Surf to https://openweathermap.org/city
# Fill in your CITY
# e.g. Antwerp Belgium
# Check url
# https://openweathermap.org/city/2803138
# you will the city code at the end
# create an account on this website
# create an api key (free)
# LANG included thanks to krive001 on discord
import requests
CITY = "YOUR LOCATION HERE"
API_KEY = "EDIT YOUR API KEY HERE!"
UNITS = "imperial"
#UNIT_KEY = "C"
UNIT_KEY = "F"
LANG = "en"
#LANG = "nl"
#LANG = "hu"
REQ = requests.get("http://api.openweathermap.org/data/2.5/weather?id={}&lang={}&appid={}&units={}".format(CITY, LANG, API_KEY, UNITS))
try:
# HTTP CODE = OK
if REQ.status_code == 200:
CURRENT = REQ.json()["weather"][0]["description"].capitalize()
TEMP = int(float(REQ.json()["main"]["temp"]))
print("{}, {} °{}".format(CURRENT, TEMP, UNIT_KEY))
else:
print("Error: BAD HTTP STATUS CODE " + str(REQ.status_code))
except (ValueError, IOError):
print("Error: Unable print the data")