-
Notifications
You must be signed in to change notification settings - Fork 0
/
Filer.py
54 lines (43 loc) · 1.06 KB
/
Filer.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
import datetime
import os
from dotenv import load_dotenv
from db_connect import *
from dataclasses import dataclass
@dataclass
class Filer:
FilerId: int
load_dotenv()
connection = db_connect(os.getenv('CALACCESSDB'))
cursor = connection.cursor()
# get all filers
filerIds = []
cursor.execute("""
SELECT DISTINCT FILER_ID
FROM FILERS_CD
""")
db_filerIds = cursor.fetchall()
print("Unique Filers: ", cursor.rowcount)
for filerId in db_filerIds:
filerIds.append(
filerId[0]
)
cursor.close()
connection.close()
# inset filerIds into db
connection = db_connect(os.getenv('DEVDB'))
cursor = connection.cursor()
insert_query = """
INSERT INTO Filer (FilerId)
VALUES (%s)
"""
data_to_insert = [
(filerId,)
for filerId in filerIds
]
batch_size = 1000
for i in range(0, len(data_to_insert), batch_size):
batch_data = data_to_insert[i:i + batch_size]
cursor.executemany(insert_query, batch_data)
connection.commit()
cursor.close()
connection.close()