Expand error handling and fix runtime issues

This commit is contained in:
chris committed 2026-05-24 21:52:17 -04:00
1 parent 830158afaf
commit dde606aabf
1 file changed
+18 -4
+18 -4
View File
@@ -2,7 +2,7 @@ from datetime import datetime
from time import sleep
from sqlalchemy import func
from sqlalchemy.exc import IntegrityError
from sqlalchemy.exc import IntegrityError, PendingRollbackError
from data.database import dal, MegaMillionsDraw, PowerballDraw
import lottery_predictor.collect as predictor
@@ -45,6 +45,10 @@ def main():
session.commit()
except IntegrityError:
pass
except PendingRollbackError:
session.rollback()
finally:
session.close()
# sleep between records and years to avoid querying the site too often
sleep(60)
@@ -64,6 +68,10 @@ def main():
session.commit()
except IntegrityError:
pass
except PendingRollbackError:
session.rollback()
finally:
session.close()
# sleep between records and years to avoid querying the site too often
sleep(60)
@@ -82,6 +90,10 @@ def main():
session.commit()
except IntegrityError:
pass
except PendingRollbackError:
session.rollback()
finally:
session.close()
# sleep between records and years to avoid querying the site too often
sleep(60)
@@ -89,7 +101,7 @@ def main():
session.commit()
else:
most_recent = session.query(func.max(PowerballDraw.draw_date)).first()
start_year = datetime.strptime(most_recent[0], str(date_format)).year
start_year = datetime.strptime(str(most_recent[0]), str(date_format)).year
# loop over the years needed and gather records
for year in range(start_year, end_year + 1):
print(f"\tCollecting {year}...")
@@ -102,11 +114,13 @@ def main():
session.commit()
except IntegrityError:
pass
except PendingRollbackError:
session.rollback()
finally:
session.close()
# sleep between records and years to avoid querying the site too often
sleep(60)
mm_count = session.query(MegaMillionsDraw).count()
pb_count = session.query(PowerballDraw).count()