Skip to content

Instantly share code, notes, and snippets.

@PotatoCurry
Forked from dotcomboom/weather-rpc.py
Last active May 15, 2021 20:02
Show Gist options
  • Save PotatoCurry/f6f9c696055522825e6a867e4b90f8e7 to your computer and use it in GitHub Desktop.
Save PotatoCurry/f6f9c696055522825e6a867e4b90f8e7 to your computer and use it in GitHub Desktop.
Discord Weather RPC
import os
import time
import requests
from pypresence import Presence
def main():
API_KEY = os.environ["WEATHERBIT_API_KEY"] # get a key at https://www.weatherbit.io/account/create
CLIENT_ID = 704435320808276108
CITY_NAME = os.environ["CITY_NAME"]
url = "https://api.weatherbit.io/v2.0/current?units=I&city={}&key={}".format(CITY_NAME, API_KEY)
discord_rpc = Presence(CLIENT_ID)
discord_rpc.connect()
print("Rich presence connected!")
while True:
response = requests.get(url).json()
data = response['data'][0]
temperature = data['temp']
wind_speed = data['wind_spd']
wind_dir = data['wind_cdir']
weather_icon = data['weather']['icon']
weather_desc = data['weather']['description']
details = f"{temperature}°F, {wind_speed} mph {wind_dir}"
print(details, weather_icon)
discord_rpc.update(details=weather_desc, state=details, large_image=weather_icon, small_image=weather_icon)
time.sleep(3600)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment