Novadotgg commited on
Commit
e2923c5
·
1 Parent(s): 7bc46fb

Security: Refactor to map API keys and sensitive tokens to environment variables using dotenv

Browse files
Files changed (3) hide show
  1. .gitignore +3 -0
  2. executable_code/app.py +7 -3
  3. requirements.txt +1 -0
.gitignore CHANGED
@@ -27,3 +27,6 @@ Thumbs.db
27
  *.txt
28
  logs hf
29
  !requirements.txt
 
 
 
 
27
  *.txt
28
  logs hf
29
  !requirements.txt
30
+
31
+ # Secrets
32
+ .env
executable_code/app.py CHANGED
@@ -1,5 +1,9 @@
1
  import os
2
  import re
 
 
 
 
3
  import csv
4
  import json
5
  import warnings
@@ -87,7 +91,7 @@ crop_durations = {
87
  }
88
 
89
  def fetch_weather_data(location):
90
- api_key = '3b0880537a825f35ec5cc49574db842e'
91
  base_url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric'
92
  try:
93
  response = requests.get(base_url, timeout=5)
@@ -260,7 +264,7 @@ def recommend_crop(user_message):
260
  try:
261
  # Market Data API call... (kept same logic)
262
  url = "https://api.data.gov.in/resource/35985678-0d79-46b4-9ed6-6f13308a1d24"
263
- api_key = "579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b"
264
  params = {"api-key": api_key, "format": "json", "limit": "50", "filters[Commodity]": crop, "filters[District]": district, "filters[State]": state}
265
  res = requests.get(url, params=params, timeout=5)
266
  records = res.json().get("records", [])
@@ -362,7 +366,7 @@ def handle_soil_conditions(user_message):
362
  if __name__ == '__main__':
363
  # Initialize Ngrok for exposure (Optional)
364
  # Get your token from: https://dashboard.ngrok.com/get-started/your-authtoken
365
- token = "2jB3oS2xptgkYHLMldb5uNwjHEF_3k3Q4UuBthT1xD6nyitXA" # From notebook
366
  if token:
367
  try:
368
  ngrok.set_auth_token(token)
 
1
  import os
2
  import re
3
+ from dotenv import load_dotenv
4
+
5
+ # Load secret keys from .env file
6
+ load_dotenv()
7
  import csv
8
  import json
9
  import warnings
 
91
  }
92
 
93
  def fetch_weather_data(location):
94
+ api_key = os.environ.get('WEATHER_API_KEY')
95
  base_url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric'
96
  try:
97
  response = requests.get(base_url, timeout=5)
 
264
  try:
265
  # Market Data API call... (kept same logic)
266
  url = "https://api.data.gov.in/resource/35985678-0d79-46b4-9ed6-6f13308a1d24"
267
+ api_key = os.environ.get('MARKET_API_KEY')
268
  params = {"api-key": api_key, "format": "json", "limit": "50", "filters[Commodity]": crop, "filters[District]": district, "filters[State]": state}
269
  res = requests.get(url, params=params, timeout=5)
270
  records = res.json().get("records", [])
 
366
  if __name__ == '__main__':
367
  # Initialize Ngrok for exposure (Optional)
368
  # Get your token from: https://dashboard.ngrok.com/get-started/your-authtoken
369
+ token = os.environ.get('NGROK_TOKEN')
370
  if token:
371
  try:
372
  ngrok.set_auth_token(token)
requirements.txt CHANGED
@@ -17,3 +17,4 @@ matplotlib
17
  plotly
18
  scipy
19
  torch
 
 
17
  plotly
18
  scipy
19
  torch
20
+ python-dotenv