Skip to content

Instantly share code, notes, and snippets.

@rxw1
Created July 9, 2020 22:16
Show Gist options
  • Save rxw1/6cecca1848a992b2532fce77274a8544 to your computer and use it in GitHub Desktop.
Save rxw1/6cecca1848a992b2532fce77274a8544 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import asyncio
import httpx
import json
import sys
lt = {
16: 99,
17: 93,
18: 88,
19: 83,
20: 78,
21: 74,
22: 70,
23: 66,
24: 62,
25: 59,
26: 56,
27: 53,
28: 50,
29: 47,
30: 45,
31: 43,
32: 40,
33: 38,
34: 36,
35: 35,
36: 33,
37: 31
}
city_id = "2906143"
openweathermap_api_key = "f62c513cc8061791d311920bbe712af9"
url = "https://api.openweathermap.org/data/2.5/weather?id={}&appid={}&units=metric".format(
city_id, openweathermap_api_key
)
async def main():
async with httpx.AsyncClient() as client:
res = await client.get(url)
res_data = json.loads(res.read())
t = res_data["main"]["temp"]
h = res_data["main"]["humidity"]
hs = lt[round(t)]
print("{}->{} {}->{} {}\n".format(t, round(t), h, hs, h - hs))
print(round(t), round(h))
print(h - hs)
if __name__ == "__main__":
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment