runner.py 1.0 KB

123456789101112131415161718192021222324252627282930
  1. from app.bnet_retriever.profile import Profile, RemoteProfile, DBProfile
  2. from app.bnet_retriever.credential import CredentialManager
  3. from app.bnet_retriever.stat import CompetitiveStat
  4. from app.utils.db import Mongo
  5. from bson import ObjectId
  6. class Runner:
  7. callbacks = []
  8. def __init__(self, username: str):
  9. record = Mongo.db.user.find_one({'username': username})
  10. if not record:
  11. raise Exception('No Such User')
  12. self.username: str = username
  13. self._id: ObjectId = record['_id']
  14. # Plugs
  15. # self.profile: Profile = Profile(self)
  16. self.new_profile = RemoteProfile(self)
  17. self.latest_profile = DBProfile(self)
  18. self.credential: CredentialManager = CredentialManager(self)
  19. self.competitive_stat = CompetitiveStat(self)
  20. def run(self):
  21. self.new_profile.refresh()
  22. self.latest_profile.refresh()
  23. if self.new_profile > self.latest_profile:
  24. Mongo.db.profile.insert(self.new_profile.to_db_record())
  25. self.competitive_stat.calc()