-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (22 loc) · 747 Bytes
/
main.py
File metadata and controls
30 lines (22 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3
import requests
import os
import mysql.connector
import stocks_database as sdb
# Fetch mySQL password from env variable
sql_pass = os.environ['MYSQL_PASSWORD']
# Fetch IEX api key from env variable
iex_api_key = os.environ['IEX_API_KEY']
# Create list with ticker stocks to make the requests
tickers = ['URTH', 'AAPL', 'MSFT', 'AMZN', 'GOOGL', 'TSLA', 'FB', 'NVDA']
# Create database connection
conn = mysql.connector.connect(
host="localhost",
user="calvinho",
passwd=sql_pass
)
# Loop through tickers, make the API request and insert the data into the corresponding table
for t in tickers:
sdb.db_insert_real_time(connection=conn, ticker=t, iex_api_key=iex_api_key)
# Close the connection
conn.close()