-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPAXminer_Daily_Execution.py
executable file
·59 lines (51 loc) · 1.8 KB
/
PAXminer_Daily_Execution.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
#!/usr/bin/env python3
'''
This script was written by Beaker from F3STL. Questions? @srschaecher on twitter or [email protected].
This script executes the daily PAXminer backblast queries and data updates for all F3 regions using PAXminer.
'''
from slacker import Slacker
import pandas as pd
import pymysql.cursors
import configparser
import os
# Set the working directory to the directory of the script
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# Configure AWS credentials
config = configparser.ConfigParser();
config.read('../config/credentials.ini');
# Configure AWS Credentials
host = config['aws']['host']
port = int(config['aws']['port'])
user = config['aws']['user']
password = config['aws']['password']
db = config['aws']['db']
#Define AWS Database connection criteria
mydb1 = pymysql.connect(
host=host,
port=port,
user=user,
password=password,
db=db,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
# Get list of regions and Slack tokens for PAXminer execution
try:
with mydb1.cursor() as cursor:
sql = "SELECT * FROM paxminer.regions"
cursor.execute(sql)
regions = cursor.fetchall()
regions_df = pd.DataFrame(regions, columns={'region', 'slack_token', 'schema_name'})
finally:
print('Getting list of regions that use PAXminer...')
for index, row in regions_df.iterrows():
region = row['region']
key = row['slack_token']
db = row['schema_name']
print('Executing user updates for region ' + region)
os.system("./F3SlackUserLister.py " + db + " " + key)
os.system("./F3SlackChannelLister.py " + db + " " + key)
os.system("./BDminer.py " + db + " " + key)
os.system("./PAXminer.py " + db + " " + key)
print('----------------- End of Region Update -----------------\n')