32 lines
1009 B
Python
32 lines
1009 B
Python
from database import get_all, Data_table
|
|
from tqdm import tqdm
|
|
import time
|
|
from dotenv import load_dotenv
|
|
import pandas as pd
|
|
|
|
def get_progress(dt):
|
|
query = 'SELECT count(*) from data_table'
|
|
res = pd.read_sql_query(query, dt.con)
|
|
total = res['count'][0]
|
|
query = 'SELECT count(*) from data_table where content_en is not null'
|
|
res = pd.read_sql_query(query, dt.con)
|
|
progress = res['count'][0]
|
|
return progress, total
|
|
|
|
if __name__ == '__main__':
|
|
load_dotenv()
|
|
try:
|
|
with Data_table() as dt:
|
|
# continously update progress bar
|
|
progress, total = get_progress(dt)
|
|
with tqdm(total=total, initial=progress) as pbar:
|
|
while True:
|
|
pbar.n = progress
|
|
pbar.refresh()
|
|
time.sleep(1)
|
|
progress, total = get_progress(dt)
|
|
except Exception as e:
|
|
print(f'error occurred: {e}')
|
|
except KeyboardInterrupt:
|
|
print('KeyboardInterrupt')
|
|
|