| 123456789101112131415161718192021222324252627282930313233343536373839 |
- from .profile import RemoteProfile, DBProfile
- from .credential import CredentialManager
- from .stat import CompetitiveStat
- from .utils.db import Mongo
- from bson import ObjectId
- import logging
- logger = logging.getLogger(__name__)
- class Runner:
- callbacks = []
- def __init__(self, _id: ObjectId):
- self._id: ObjectId = _id
- # Plugs
- # self.profile: Profile = Profile(self)
- self.new_profile = RemoteProfile(self)
- self.latest_profile = DBProfile(self)
- self.credential: CredentialManager = CredentialManager(self)
- self.competitive_stat = CompetitiveStat(self)
- def run(self):
- self.new_profile.refresh()
- self.latest_profile.refresh()
- if self.new_profile > self.latest_profile:
- logger.info("[%s] Found New Profile!", self._id)
- Mongo.db.profile.insert(self.new_profile.to_db_record())
- self.competitive_stat.calc()
- class RunnerProxy(Runner):
- def __init__(self, username: str):
- record = Mongo.db.user.find_one({'username': username})
- if not record:
- raise Exception('No Such User')
- self.username: str = username
- super(RunnerProxy, self).__init__(record['_id'])
|