-
-
Save PotatoCurry/f6f9c696055522825e6a867e4b90f8e7 to your computer and use it in GitHub Desktop.
Discord Weather RPC
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
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