app.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """General application logic"""
  2. from app import LOGGER, api, database
  3. def print_players(players):
  4. """Print professors"""
  5. for player in players:
  6. print('{:20} {:30} {:30}'.format(
  7. player['id'],
  8. player['name'],
  9. player['nation'],
  10. ))
  11. def update_citizens(state_ids, region_ids):
  12. """Update citizens"""
  13. regions = database.get_regions(region_ids)
  14. for state_id in state_ids:
  15. regions += database.get_state_regions(state_id)
  16. LOGGER.info('update citizens for "%s" regions', len(regions))
  17. for region in regions:
  18. LOGGER.info('regio %6s: get citizens', region.id)
  19. citizens = api.get_citizens(region.id)
  20. LOGGER.info('regio %6s: "%s" citizens', region.id, len(citizens))
  21. # print_players(citizens)
  22. database.save_citizens(region.id, citizens)
  23. LOGGER.info('regio %6s: done saving citizens', region.id)
  24. def update_residents(state_ids, region_ids):
  25. """Update residents"""
  26. regions = database.get_regions(region_ids)
  27. for state_id in state_ids:
  28. regions += database.get_state_regions(state_id)
  29. LOGGER.info('update residents for "%s" regions', len(regions))
  30. for region in regions:
  31. LOGGER.info('regio %6s: get residents', region.id)
  32. residents = api.get_residents(region.id)
  33. LOGGER.info('regio %6s: "%s" residents ', region.id, len(residents))
  34. # print_players(residents)
  35. database.save_residents(region.id, residents)
  36. LOGGER.info('regio %6s: done saving residents', region.id)
  37. def update_work_permits(state_ids):
  38. """Update work permits"""
  39. LOGGER.info('update work permits for "%s" states', len(state_ids))
  40. for state_id in state_ids:
  41. LOGGER.info('state %6s: get work permits ', state_id)
  42. work_permits = api.get_work_permits(state_id)
  43. LOGGER.info('state %6s: "%s" work permits', state_id, len(work_permits))
  44. # print_players(work_permits)
  45. database.save_work_permits(state_id, work_permits)
  46. LOGGER.info('state %6s: done saving work_permits', state_id)