Last active
September 24, 2022 20:02
Weather rich presence for Discord that uses wttr.in's public api (Weatherbit.io version is in revisions, or check forks)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypresence import Presence | |
import requests | |
import json | |
import time | |
client_id = 704435320808276108 | |
city = 'Minneapolis, MN' | |
url = 'https://wttr.in/{}?format=j1'.format(city) | |
RPC = Presence(client_id) | |
RPC.connect() | |
print('Rich presence connected!') | |
while True: | |
r = requests.get(url).json()['current_condition'][0] | |
w = r['weatherDesc'][0]['value'] # e.g. "Partly cloudly". also used for icons | |
display_state = '{}Β° F ({}Β° C)'.format(r['temp_F'], r['temp_C']) | |
icon = "π΄" | |
# https://github.com/chubin/wttr.in/blob/e0cc061a64ba86cda1380f0409203a0fb8ae889c/lib/constants.py | |
icons = { | |
"Cloudy": "β", | |
"Overcast": "β", | |
"Fog": "π«", | |
"Haze": "π«", | |
"Heavy rain": "π§", | |
"Heavy showers": "π§", | |
"Heavy snow": "β", | |
"Heavy snow showers": "β", | |
"Light rain": "π¦", | |
"Light showers": "π¦", | |
"Light sleet": "π§", | |
"Light sleet showers": "π§", | |
"Light snow": "π¨", | |
"Light snow showers": "π¨", | |
"Partly cloudy": "β οΈ", | |
"Sunny": "β", | |
"Thundery heavy rain": "π©", | |
"Thundery showers": "β", | |
"Thundery snow showers": "β", | |
"Very cloudy": "β" | |
} | |
if w in icons.keys(): | |
icon = icons[w] | |
local_observation_time = r["localObsDateTime"].split(' ')[1] + ' ' + r["localObsDateTime"].split(' ')[2] | |
display_wtr = '{} {} at {}'.format(icon, w, local_observation_time) | |
print('\n{0}'.format(w)) | |
print(display_state) | |
RPC.update(buttons=[{"label": 'πΊ {} Forecast'.format(city), "url": "https://wttr.in/{}".format(city.replace(' ', '%20'))}, {"label": "β¨ GitHub Gist", "url": "https://gist.github.com/dotcomboom/8a109a227faffbe4cfde378ecf0c80b7"}], details=display_wtr, state=display_state, large_image=w, small_image=w) | |
time.sleep(3600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javascript pog tho