Expand error handling and fix runtime issues
This commit is contained in:
1 parent
830158afaf
commit
dde606aabf
1 file changed
+18
-4
@@ -2,7 +2,7 @@ from datetime import datetime
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError, PendingRollbackError
|
||||||
|
|
||||||
from data.database import dal, MegaMillionsDraw, PowerballDraw
|
from data.database import dal, MegaMillionsDraw, PowerballDraw
|
||||||
import lottery_predictor.collect as predictor
|
import lottery_predictor.collect as predictor
|
||||||
@@ -45,6 +45,10 @@ def main():
|
|||||||
session.commit()
|
session.commit()
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
except PendingRollbackError:
|
||||||
|
session.rollback()
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
# sleep between records and years to avoid querying the site too often
|
# sleep between records and years to avoid querying the site too often
|
||||||
sleep(60)
|
sleep(60)
|
||||||
|
|
||||||
@@ -64,6 +68,10 @@ def main():
|
|||||||
session.commit()
|
session.commit()
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
except PendingRollbackError:
|
||||||
|
session.rollback()
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
# sleep between records and years to avoid querying the site too often
|
# sleep between records and years to avoid querying the site too often
|
||||||
sleep(60)
|
sleep(60)
|
||||||
|
|
||||||
@@ -82,6 +90,10 @@ def main():
|
|||||||
session.commit()
|
session.commit()
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
except PendingRollbackError:
|
||||||
|
session.rollback()
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
# sleep between records and years to avoid querying the site too often
|
# sleep between records and years to avoid querying the site too often
|
||||||
sleep(60)
|
sleep(60)
|
||||||
|
|
||||||
@@ -89,7 +101,7 @@ def main():
|
|||||||
session.commit()
|
session.commit()
|
||||||
else:
|
else:
|
||||||
most_recent = session.query(func.max(PowerballDraw.draw_date)).first()
|
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
|
# loop over the years needed and gather records
|
||||||
for year in range(start_year, end_year + 1):
|
for year in range(start_year, end_year + 1):
|
||||||
print(f"\tCollecting {year}...")
|
print(f"\tCollecting {year}...")
|
||||||
@@ -102,11 +114,13 @@ def main():
|
|||||||
session.commit()
|
session.commit()
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
except PendingRollbackError:
|
||||||
|
session.rollback()
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
# sleep between records and years to avoid querying the site too often
|
# sleep between records and years to avoid querying the site too often
|
||||||
sleep(60)
|
sleep(60)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mm_count = session.query(MegaMillionsDraw).count()
|
mm_count = session.query(MegaMillionsDraw).count()
|
||||||
pb_count = session.query(PowerballDraw).count()
|
pb_count = session.query(PowerballDraw).count()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user