Skip to content

Instantly share code, notes, and snippets.

@dotcomboom
Last active September 24, 2022 20:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dotcomboom/8a109a227faffbe4cfde378ecf0c80b7 to your computer and use it in GitHub Desktop.
Save dotcomboom/8a109a227faffbe4cfde378ecf0c80b7 to your computer and use it in GitHub Desktop.
Weather rich presence for Discord that uses wttr.in's public api (Weatherbit.io version is in revisions, or check forks)
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)
@alaninnovates
Copy link

javascript pog tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment