CCockrum commited on
Commit
4333cf4
·
verified ·
1 Parent(s): 02ccdc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -15,41 +15,46 @@ POLYGON_API_KEY = os.getenv("POLYGON_API_KEY")
15
 
16
  # Helper Functions
17
  def get_company_info(symbol):
18
- api_key = os.getenv(\"POLYGON_API_KEY\")
19
- print(f\"DEBUG: Using API Key: {api_key}\")
20
- url = f\"https://api.polygon.io/v3/reference/tickers/{symbol}?apiKey={api_key}\"
21
- print(f\"DEBUG: Fetching company info URL: {url}\")
22
  try:
23
  response = requests.get(url)
24
- print(f\"DEBUG: Response Status: {response.status_code}\")
25
- print(f\"DEBUG: Response JSON: {response.json()}\")
26
  response.raise_for_status()
27
  data = response.json()['results']
28
  return {
29
  'Name': data.get('name', 'N/A'),
30
  'Industry': data.get('sic_description', 'N/A'),
31
  'Market Cap': data.get('market_cap', 0),
32
- 'Total Revenue': data.get('total_employees', 0) * 100000 # Rough estimate
33
  }
34
  except Exception as e:
35
- print(f\"DEBUG: Error fetching company info: {e}\")
36
  return None
37
 
38
  def get_current_price(symbol):
39
  url = f"https://api.polygon.io/v2/aggs/ticker/{symbol}/prev?adjusted=true&apiKey={POLYGON_API_KEY}"
 
40
  try:
41
  response = requests.get(url)
 
 
42
  response.raise_for_status()
43
  data = response.json()['results'][0]
44
  return float(data['c'])
45
  except Exception as e:
46
- print(f"DEBUG: Error fetching price: {e}")
47
  return None
48
 
49
  def get_dividends(symbol):
50
  url = f"https://api.polygon.io/v3/reference/dividends?ticker={symbol}&apiKey={POLYGON_API_KEY}"
 
51
  try:
52
  response = requests.get(url)
 
 
53
  response.raise_for_status()
54
  data = response.json()['results'][0]
55
  return {
@@ -64,8 +69,11 @@ def get_historical_prices(symbol):
64
  end = datetime.date.today()
65
  start = end - datetime.timedelta(days=365)
66
  url = f"https://api.polygon.io/v2/aggs/ticker/{symbol}/range/1/day/{start}/{end}?adjusted=true&sort=asc&apiKey={POLYGON_API_KEY}"
 
67
  try:
68
  response = requests.get(url)
 
 
69
  response.raise_for_status()
70
  results = response.json()['results']
71
  dates = [datetime.datetime.fromtimestamp(r['t']/1000) for r in results]
@@ -140,4 +148,4 @@ iface = gr.Interface(
140
  )
141
 
142
  if __name__ == "__main__":
143
- iface.launch()
 
15
 
16
  # Helper Functions
17
  def get_company_info(symbol):
18
+ print(f"DEBUG: Using API Key: {POLYGON_API_KEY}")
19
+ url = f"https://api.polygon.io/v3/reference/tickers/{symbol}?apiKey={POLYGON_API_KEY}"
20
+ print(f"DEBUG: Fetching company info URL: {url}")
 
21
  try:
22
  response = requests.get(url)
23
+ print(f"DEBUG: Response Status: {response.status_code}")
24
+ print(f"DEBUG: Response JSON: {response.json()}")
25
  response.raise_for_status()
26
  data = response.json()['results']
27
  return {
28
  'Name': data.get('name', 'N/A'),
29
  'Industry': data.get('sic_description', 'N/A'),
30
  'Market Cap': data.get('market_cap', 0),
31
+ 'Total Revenue': data.get('total_employees', 0) * 100000
32
  }
33
  except Exception as e:
34
+ print(f"DEBUG: Error fetching company info: {e}")
35
  return None
36
 
37
  def get_current_price(symbol):
38
  url = f"https://api.polygon.io/v2/aggs/ticker/{symbol}/prev?adjusted=true&apiKey={POLYGON_API_KEY}"
39
+ print(f"DEBUG: Fetching current price URL: {url}")
40
  try:
41
  response = requests.get(url)
42
+ print(f"DEBUG: Response Status: {response.status_code}")
43
+ print(f"DEBUG: Response JSON: {response.json()}")
44
  response.raise_for_status()
45
  data = response.json()['results'][0]
46
  return float(data['c'])
47
  except Exception as e:
48
+ print(f"DEBUG: Error fetching current price: {e}")
49
  return None
50
 
51
  def get_dividends(symbol):
52
  url = f"https://api.polygon.io/v3/reference/dividends?ticker={symbol}&apiKey={POLYGON_API_KEY}"
53
+ print(f"DEBUG: Fetching dividends URL: {url}")
54
  try:
55
  response = requests.get(url)
56
+ print(f"DEBUG: Response Status: {response.status_code}")
57
+ print(f"DEBUG: Response JSON: {response.json()}")
58
  response.raise_for_status()
59
  data = response.json()['results'][0]
60
  return {
 
69
  end = datetime.date.today()
70
  start = end - datetime.timedelta(days=365)
71
  url = f"https://api.polygon.io/v2/aggs/ticker/{symbol}/range/1/day/{start}/{end}?adjusted=true&sort=asc&apiKey={POLYGON_API_KEY}"
72
+ print(f"DEBUG: Fetching historical prices URL: {url}")
73
  try:
74
  response = requests.get(url)
75
+ print(f"DEBUG: Response Status: {response.status_code}")
76
+ print(f"DEBUG: Response JSON: {response.json()}")
77
  response.raise_for_status()
78
  results = response.json()['results']
79
  dates = [datetime.datetime.fromtimestamp(r['t']/1000) for r in results]
 
148
  )
149
 
150
  if __name__ == "__main__":
151
+ iface.launch()