-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (70 loc) · 3.37 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from core import DB, ConfigData, DataPD
import io
all_connections = []
db_obj_result = DB(host='127.0.0.1', user='salkov', password="Artyom.salkov1", database="result", port='3306', conn_name='db_obj_result')
# from Staging
# db2 = DB(host='127.0.0.1', user='completecase', password="fh47gTwdf#8@dfsg", database="completecase", port='3308', conn_name='db2')
# all_connections.append(db2)
# from Divorce online solutions
# db3 = DB(host='127.0.0.1', user='completecase', password="fh47gTwdf#8@dfsg", database="completecase", port='3309', conn_name='db3')
# all_connections.append(db3)
# from DigitalOcean
db4 = DB(host='127.0.0.1', user='salkov', password="Artyom.salkov1", database="DB_local", port='3306', conn_name='db4')
all_connections.append(db4)
# from Linode
db5 = DB(host='127.0.0.1', user='salkov', password="Artyom.salkov1", database="DB_linode", port='3306', conn_name='db5')
all_connections.append(db5)
# from Completecase
db6 = DB(host='127.0.0.1', user='salkov', password="Artyom.salkov1", database="DB_completecase", port='3306', conn_name='db6')
all_connections.append(db6)
# Copy reports
for connection in all_connections:
conf_obj = ConfigData(connection_name=connection.conn_name)
conf_obj.check_config_file_exists()
last_pos = conf_obj.get_report_position()
query_get_reports = f'SELECT * FROM reporting_grandprofitabilityreport WHERE id > {last_pos} ORDER BY id ASC'
connection.execute(query_get_reports)
res = results = query = None
results = connection.get_cursor().fetchall()
for res in results:
query = f"INSERT INTO reporting_grandprofitabilityreport(`id`, `created`, `created_for`, `data`, `type`, `from_server`, `from_id`) " \
f"VALUES (0, \"{res['created']}\", \"{res['created_for']}\", \"{res['data']}\", {res['type']}, " \
f"{int(connection.conn_name[2::])}, {res['id']})"
db_obj_result.execute(query=query)
print(query)
try:
pd_data_obj = DataPD(data=res['data'])
print(pd_data_obj.data_frame)
except Exception:
pass
if isinstance(results, (tuple)):
pass
else:
db_obj_result.get_connection().commit()
conf_obj.set_report_position(val=res['id'])
# ----------------------------/ Copy reports ---------------------------------
# Copy sites
for connection in all_connections:
conf_obj = ConfigData(connection_name=connection.conn_name)
conf_obj.check_config_file_exists()
last_pos = conf_obj.get_sites_position()
query_get_sites = f'SELECT * FROM django_site WHERE id > {last_pos} ORDER BY id ASC'
connection.execute(query_get_sites)
res = results = query = None
results = connection.get_cursor().fetchall()
print(results)
for res in results:
query = f'INSERT INTO reporting_sitesonservers(`id`, `domain`, `name`, `from_server`, `from_id`) ' \
f'VALUES (0, \'{res["domain"]}\', \'{res["name"]}\', \'{int(connection.conn_name[2::])}\', \'{res["id"]}\')'
db_obj_result.execute(query=query)
print(query)
if isinstance(results, (tuple)):
pass
else:
db_obj_result.get_connection().commit()
conf_obj.set_sites_position(val=res['id'])
# --------------------------- /Copy sites ------------------------
all_connections.append(db_obj_result)
for connection in all_connections:
connection.close()
print(f'......end...........')