3434
3535"""
3636```julia
37- function get_quarterly_filings (
37+ function download_filings (
3838 metadata_file::String;
3939 dest="./data/"::String,
4040 filing_types=["10-K", ]::Vector{String},
4141 download_rate=10::Int,
42- skip_file=true::Bool
42+ skip_file=true::Bool,
43+ pbar=ProgressBar()::pbar,
44+ stop_pbar=true::Bool,
45+ pbar_desc="Downloading Filings"::string,
46+ running_tests=false::Bool
4347)
4448```
4549
46- Get quarterly filings from https://www.sec.gov/Archives/ using a metadata file
50+ Download quarterly filings from https://www.sec.gov/Archives/ using a metadata file
4751
4852Parameters
4953* `metadata_file`: CSV file with filing metadata
5054* `dest`: Destination folder for downloaded filings
5155* `filing_types`: Types of filings to download (eg. ["10-K", "10-Q"])
5256* `download_rate`: Number of filings to download every second (limit=10)
5357* `skip_file`: If true, existing files will be skipped
58+ * `pbar`: ProgressBar (Term.jl)
59+ * `stop_pbar`: If false, progress bar will not be stopped
60+ * `pbar_desc`: pbar Description
61+ * `runnings_tests`: If true, only downloads one file
5462"""
55- function get_quarterly_filings (
63+ function download_filings (
5664 metadata_file:: String ;
5765 dest = " ./data/" :: String ,
5866 filing_types = [" 10-K" ]:: Vector{String} ,
5967 download_rate = 10 :: Int ,
6068 skip_file = true :: Bool ,
69+ pbar = ProgressBar ():: pbar ,
70+ stop_pbar = true :: Bool ,
71+ pbar_desc = " Downloading Filings" :: string ,
72+ running_tests = false :: Bool ,
6173)
6274
6375 # verify download_rate is valid (less than 10 requests per second, more than 0)
@@ -70,8 +82,6 @@ function get_quarterly_filings(
7082 )
7183 end
7284
73- println (" Metadata: " * metadata_file)
74-
7585 df = CSV. File (metadata_file, delim = " |" ) |> DataFrame
7686 df = df[∈ (filing_types). (df[! , " Form Type" ]), :]
7787
@@ -82,8 +92,12 @@ function get_quarterly_filings(
8292
8393 # download filings at 10 requests per second
8494 sleep_time = 1 / download_rate
85- @showprogress 1 " Downloading Filings..." for row in eachrow (df)
8695
96+ # setup progress bar
97+ job = addjob! (pbar; N = size (df, 1 ), description = pbar_desc)
98+ start! (pbar)
99+ for row in eachrow (df)
100+ update! (job)
87101 # check if filing already has been downloaded
88102 full_file = joinpath (dest, replace (row[" Filename" ], " edgar/data/" => " " ))
89103 if isfile (full_file) && skip_file
@@ -95,15 +109,22 @@ function get_quarterly_filings(
95109
96110 # rest to throttle api hits to around 10/second
97111 sleep (sleep_time)
112+ render (pbar)
113+
114+ if running_tests
115+ break
116+ end
117+ end
118+ if stop_pbar
119+ stop! (pbar)
98120 end
99121
100122 return
101123end
102124
103-
104125"""
105126```julia
106- function get_quarterly_filings (
127+ function download_filings (
107128 start_year::Int,
108129 end_year::Int;
109130 quarters=[1,2,3,4]::Vector{Int},
@@ -112,11 +133,12 @@ function get_quarterly_filings(
112133 download_rate=10::Int,
113134 metadata_dest="./metadata/"::String,
114135 skip_file=true::Bool,
115- skip_metadata_file=true::Bool
136+ skip_metadata_file=true::Bool,
137+ running_tests=false::Bool
116138)
117139```
118140
119- Get quarterly filings from https://www.sec.gov/Archives/
141+ Download quarterly filings from https://www.sec.gov/Archives/
120142
121143Parameters
122144* `start_year`: First year to download filings
@@ -128,8 +150,9 @@ Parameters
128150* `metadata_dest`: Directory to store metadata files
129151* `skip_file`: If true, existing files will be skipped
130152* `skip_metadata_file`: If true, existing metadata files will be skipped
153+ * `runnings_tests`: If true, only downloads one file
131154"""
132- function get_quarterly_filings (
155+ function download_filings (
133156 start_year:: Int ,
134157 end_year:: Int ;
135158 quarters = [1 , 2 , 3 , 4 ]:: Vector{Int} ,
@@ -139,6 +162,7 @@ function get_quarterly_filings(
139162 metadata_dest = " ./metadata/" :: String ,
140163 skip_file = true :: Bool ,
141164 skip_metadata_file = true :: Bool ,
165+ running_tests = false :: Bool ,
142166)
143167
144168 # get current year, quarter to prevent errors trying to get future data
@@ -163,26 +187,36 @@ function get_quarterly_filings(
163187 start_year,
164188 end_year;
165189 quarters = quarters,
166- # download_rate = download_rate,
167190 dest = metadata_dest,
168191 skip_file = skip_metadata_file,
169192 )
170193
171194
172195 # download all quarterly filings
173- file_paths = [
174- joinpath (metadata_dest, string (t[1 ]) * " -QTR" * string (t[2 ]) * " .tsv" ) for
175- t in time_periods
176- ]
177- for file in file_paths
178- get_quarterly_filings (
196+ pbar = ProgressBar (columns = progress_bar_columns)
197+ job = addjob! (
198+ pbar;
199+ N = size (time_periods, 1 ),
200+ description = " Iterating Over Time Periods..." ,
201+ )
202+ start! (pbar)
203+ for t in time_periods
204+ update! (job)
205+ file = joinpath (metadata_dest, string (t[1 ]) * " -QTR" * string (t[2 ]) * " .tsv" )
206+ download_filings (
179207 file;
180208 dest = dest,
181209 filing_types = filing_types,
182210 download_rate = download_rate,
183211 skip_file = skip_file,
212+ pbar = pbar,
213+ stop_pbar = false ,
214+ pbar_desc = " Downloading $(t[1 ]) Q$(t[2 ]) Filings" ,
215+ running_tests = running_tests,
184216 )
217+ render (pbar)
185218 end
219+ stop! (pbar)
186220
187221 return
188222end
0 commit comments