-
Notifications
You must be signed in to change notification settings - Fork 79
/
run.py
73 lines (59 loc) · 2.02 KB
/
run.py
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
66
67
68
69
70
71
72
73
from __future__ import print_function
import datetime
import tempfile
import sys
from argparse import ArgumentParser
import logging
import edgar
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
if __name__ == "__main__":
if sys.version_info[0] < 3:
raise Exception("Must be using Python 3")
parser = ArgumentParser()
parser.add_argument(
"-y",
"--from-year",
type=int,
dest="year",
help="The year from which to start downloading "
+ "the filing index. Default to current year",
default=datetime.date.today().year,
)
parser.add_argument(
"-d",
"--directory",
dest="directory",
help="A directory where the filing index files will"
+ "be downloaded to. Default to a temporary directory",
default=tempfile.mkdtemp(),
)
parser.add_argument(
"-ua",
"--user-agent",
dest="ua",
help="The User Agent to set. This must be set properly "
+ "else the SEC may temporarily ban you. See https://www.sec.gov/os/accessing-edgar-data"
)
parser.add_argument(
"-s",
"--skip-all-present-except-last",
action="store_true",
dest="skip",
help="Specify this flag to skip downloading filing index"
+ " files that are already present. Only the most recent"
+ " file is downloaded. If not specified all files are"
+ " downloaded again."
)
args = parser.parse_args()
if args.ua is None:
logger.error("A user agent is required. See https://www.sec.gov/os/accessing-edgar-data")
sys.exit(1)
logger.debug("downloads will be saved to %s" % args.directory)
edgar.download_index(args.directory, args.year, args.ua, args.skip)
logger.info("Files downloaded in %s" % args.directory)