Пример #1
0
    def register_user(cls, email, password):
        user = Database.find_one('users', {'email': email})

        if user is not None:
            raise UserRegisterError("User already exists!")
        else:
            cls(email, Utils.hash_password(password)).save_to_db()
        return True
Пример #2
0
 def get_by_url(cls, url):
     i = 0
     while i < len(url):
         store_json = Database.find_one('stores', {'url_prefix': {'$regex': '^{}'.format(url[:i+1])}})
         if store_json:
             return cls(**store_json)
         i+=1
     pass
Пример #3
0
    def find_outdated_alerts(cls, timeout=ALERT_TIMEOUT):
        update_limit = datetime.utcnow() - timedelta(minutes=timeout)

        return [
            cls(**alert) for alert in Database.find(
                'alerts', {'last_checked': {
                    '$lte': update_limit
                }})
        ]
Пример #4
0
    def is_login_valid(cls, email, password):
        user = Database.find_one('users', {'email': email})

        if user is None:
            raise UserNotExistsError("User does not exist!")
        else:
            if not Utils.check_hashed_password(password, user['password']):
                raise IncorrectPasswordError("Password not match!")
        return True
Пример #5
0
from src.commons.database import Database
from src.models.alerts.alert import Alert

Database.initialize()

outdated_alerts = Alert.find_outdated_alerts()
print(outdated_alerts)
for alert in outdated_alerts:
    alert.load_item_price()
    alert.send_email_if_price_reached()
Пример #6
0
 def save_to_db(self):
     Database.update('alerts', {'_id': self._id}, self.json())
Пример #7
0
 def get_by_id(cls, _id):
     return cls(**Database.find_one('items', {'_id': _id}))
Пример #8
0
 def save_to_db(self):
     Database.insert('items', self.json())
Пример #9
0
def init_db():
    Database.initialize()
Пример #10
0
 def get_by_url_prefix(cls, prefix: str):
     return cls(**Database.find_one('stores', {'url_prefix': {'$regex': '^{}'.format(prefix)}}))
Пример #11
0
 def get_by_name(cls, name):
     return cls(**Database.find_one('stores', {'name': name}))
Пример #12
0
 def save_to_db(self):
     Database.insert('stores', self.json())