app.py 639 B

123456789101112131415161718192021222324
  1. """General functions module"""
  2. import random
  3. import math
  4. import re
  5. from app import LOGGER, database, api
  6. def update_regions(state_id):
  7. """Update department regions"""
  8. LOGGER.info('"%s": Run update regions', state_id)
  9. current_regions = database.get_current_regions(state_id)
  10. LOGGER.info(
  11. '"%s": Currently has "%s" regions in database',
  12. state_id, len(current_regions)
  13. )
  14. regions = api.get_regions(state_id)
  15. LOGGER.info(
  16. '"%s": Got "%s" regions from API',
  17. state_id, len(regions)
  18. )
  19. database.save_regions(state_id, regions)
  20. LOGGER.info('"%s": saved regions', state_id)