feat: add ability to load env vars from file
This commit is contained in:
13
pyvis.py
13
pyvis.py
@@ -2,6 +2,13 @@ import discord
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# load environment variables
|
||||||
|
load_dotenv()
|
||||||
|
DISCORD_BOT_TOKEN = os.getenv('DISCORD_BOT_TOKEN')
|
||||||
|
DISCORD_GUILD = os.getenv('DISCORD_GUILD')
|
||||||
|
LUNAR_CRUSH_API_KEY = os.getenv('LUNAR_CRUSH_API_KEY')
|
||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
@@ -22,11 +29,11 @@ async def on_message(message):
|
|||||||
await message.channel.send("Some resources for you here!")
|
await message.channel.send("Some resources for you here!")
|
||||||
|
|
||||||
# Crypto command
|
# Crypto command
|
||||||
if msg_str == "!crypto":
|
if msg_str.startswith("!crypto"):
|
||||||
symbols = ["BTC", "ETH", "LTC"]
|
symbols = ["BTC", "ETH", "LTC"]
|
||||||
|
|
||||||
# make the call for prices
|
# make the call for prices
|
||||||
http_response = requests.get("https://api.lunarcrush.com/v2?data=assets&key=" + os.getenv("LUNAR_CRUSH_API_KEY") + "&symbol=" + ",".join(symbols))
|
http_response = requests.get("https://api.lunarcrush.com/v2?data=assets&key=" + LUNAR_CRUSH_API_KEY + "&symbol=" + ",".join(symbols))
|
||||||
data = json.loads(http_response.text)
|
data = json.loads(http_response.text)
|
||||||
|
|
||||||
# extract prices
|
# extract prices
|
||||||
@@ -42,4 +49,4 @@ async def on_message(message):
|
|||||||
|
|
||||||
await message.channel.send(msg_response)
|
await message.channel.send(msg_response)
|
||||||
|
|
||||||
client.run(os.getenv("DISCORD_BOT_TOKEN")) # pass the bot token here
|
client.run(DISCORD_BOT_TOKEN)
|
||||||
@@ -7,6 +7,7 @@ charset-normalizer==2.0.3
|
|||||||
discord.py==1.7.3
|
discord.py==1.7.3
|
||||||
idna==3.2
|
idna==3.2
|
||||||
multidict==5.1.0
|
multidict==5.1.0
|
||||||
|
python-dotenv==0.19.0
|
||||||
requests==2.26.0
|
requests==2.26.0
|
||||||
typing-extensions==3.10.0.0
|
typing-extensions==3.10.0.0
|
||||||
urllib3==1.26.6
|
urllib3==1.26.6
|
||||||
|
|||||||
Reference in New Issue
Block a user