-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute_crawler.py
79 lines (58 loc) · 1.83 KB
/
execute_crawler.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
74
75
76
77
78
79
"""
This script crawls a list of the richest bitcoin addresses and their balances
and stores the result in a CSV file.
"""
# Imports
import argparse
import logging
from datetime import date
import pyfiglet
from marx import crawler
# Configuration
DEFAULT_LIMIT = 10000
DATA_PATH = "data/"
DEFAULT_FILE_PATH = DATA_PATH + "bitcoin_balances_ddmmYYYY.csv"
def _parse_cmd_args():
"""
This function parses the command-line arguments of the program.
:return: The parsed command-line arguments.
"""
parser = argparse.ArgumentParser(description='Capture connections')
parser.add_argument(
"--l", help=("limit of crawled bitcoin addresses. Default is " + str(DEFAULT_LIMIT)),
default=DEFAULT_LIMIT
)
parser.add_argument(
"--f", help=("path of destination file. Default is '"
+ str(DEFAULT_FILE_PATH) + "'"),
default=DEFAULT_FILE_PATH
)
args = parser.parse_args()
return args
def _main():
"""
This function executes the script.
:return: None.
"""
# Configuration
logging.basicConfig(
level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
# Parsing command line args
args = _parse_cmd_args()
logging.debug("Command line args: %s", args)
limit = int(args.l)
dest_file = args.f
# Print figlet
banner = pyfiglet.figlet_format("MARX")
print(banner)
# Crawl balances
logging.info("Crawling %d richest bitcoin addresses", limit)
balances = crawler.crawl_richest_addresses(limit=limit)
# Output results
current_date = date.today()
dest_file = dest_file.replace("ddmmYYYY", current_date.strftime("%d%m%Y"))
logging.info("Storing results in: %s", dest_file)
balances.to_csv(dest_file, index=False)
# Main block for execution
if __name__ == "__main__":
_main()