-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (48 loc) · 2.05 KB
/
main.py
File metadata and controls
65 lines (48 loc) · 2.05 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import glob
import shutil
import datafunctions as df
from tkinter import filedialog
import concurrent.futures
# from colorama import Fore, Style
# ------------------------------------ Setup
timeStart = df.get_time("Starting Date (dd/mm/yyyy): ")
while True:
timeEnd = df.get_time("Ending Date (dd/mm/yyyy): ")
if timeEnd > timeStart:
break
print("Ending date must be after starting date. Please try again.")
print("\nSelect tab-delimited text file with tickers")
ticker_filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])
with open(ticker_filename, "r") as file:
tickerList = [line.strip().upper() for line in file if line.strip() != ""]
print("\nGenerating URLs for " + str(len(tickerList)) + " tickers.\n")
# Multithreaded data fetching
def fetch_ticker_data(ticker):
print(f"Fetching data for ticker: {ticker}")
df.fetchData(ticker, timeStart, timeEnd)
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(fetch_ticker_data, tickerList)
# ------------------------------------ Merge Data
# Get the csv files in the /temp directory
csv_files = glob.glob("./temp/*.csv")
combinedDataframe = df.mergeData(csv_files)
# Validate dateOrder input
while True:
dateOrder = input("\nEnter 'a' or 'd' to choose ascending or descending order: ")
if dateOrder.lower() in ['a', 'd']:
break
print("Invalid input. Please enter 'a' for ascending or 'd' for descending order.")
# Validate closeType input
while True:
closeType = input("Enter 'a' or 'c' to choose adjusted close or close: ")
if closeType.lower() in ['a', 'c']:
break
print("Invalid input. Please enter 'a' for adjusted close or 'c' for close.")
# print("\n" + Fore.BLUE + "Merging" + Style.RESET_ALL + " .csv files...")
print("\n" + "Merging" + " .csv files...")
df.pivotData(combinedDataframe, closeType, ticker_filename, dateOrder)
if os.path.exists("./temp"):
shutil.rmtree("./temp")
# print("\n" + Fore.GREEN + "Finished!" + Style.RESET_ALL + " Output saved to ./out.csv \n")
print("\n" + "Finished!")