forked from F3Nation-Community/PAXminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigure_PAXminer_Environments.py
executable file
·58 lines (50 loc) · 1.89 KB
/
Configure_PAXminer_Environments.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
#!/usr/bin/env python3
'''
This script was written by Beaker from F3STL. Questions? @srschaecher on twitter or [email protected].
This script joins all required Slack channels and creates the log and plot directories for regions.
'''
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 where active = 1 and firstf_channel IS NOT NULL" # <-- Update this for whatever region is being tested
#sql = "SELECT * FROM paxminer.regions where region = 'Lake_Wylie'" # <-- Update this for whatever region is being tested
cursor.execute(sql)
regions = cursor.fetchall()
regions_df = pd.DataFrame(regions)
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']
firstf = row['firstf_channel']
os.system("./Join_Channels_and_Create_Directories.py " + db + " " + key + " " + region + " " + firstf)
print('----------------- End of Region Configuration -----------------\n')
print('\nPAXminer Configurations Complete.')