models package

Submodules

models.alert module

This module contains the Alert Model class.

models.alert.logger

The logger used to log information of module.

Type

logging.Logger

class models.alert.Alert(name: str, price_limit: float, user_email: str, item_id: dataclasses.InitVar[typing.Union[str, bson.objectid.ObjectId]], _id: dataclasses.InitVar[typing.Union[str, bson.objectid.ObjectId]] = None)[source]

Bases: models.model.Model

Class that models an Alert.

collection

The database collection name of the Alert class.

Type

str

name

The name of the alert.

Type

str

price_limit

The price limit.

Type

float

user_email

The email of the user the alert corresponds to.

Type

str

item_id

The id of the alert’s corresponding item.

Type

InitVar[Union[str, ObjectId]]

item

The alert’s corresponding item.

Type

Item

_id

The id of the alert.

Type

InitVar[Union[str, ObjectId]]

collection: str = 'alerts'
item_id: dataclasses.InitVar[typing.Union[str, bson.objectid.ObjectId]]
json()dict[source]

Returns the json representation of the alert.

Returns

The json representation of the alert.

Return type

dict

load_item_price()float[source]

Returns the current price of the alert’s corresponding item.

Returns

The current price of the alert’s item.

Return type

float

name: str
notify_if_price_reached()[source]

Notifies a user via email if a price has reached their desired price.

price_limit: float
user_email: str

models.item module

This module contains the Item Model class.

models.item.logger

The logger used to log information of module.

Type

logging.Logger

class models.item.Item(url: str, tag_name: str, query: Dict[str, Any], price: float = None, _id: InitVar[Union[str, ObjectId]] = None)[source]

Bases: models.model.Model

Class that models an item.

collection

The database collection name of the Item class.

Type

str

url

The URL of the webpage on which the item is found.

Type

str

tag_name

The tag for the item.

Type

str

query

The CSS selector used to find the item.

Type

str

price

The maximum desired price for the item.

Type

float

_id

The id of the item.

Type

InitVar[Union[str, ObjectId]]

collection: str = 'items'
json()dict[source]

Returns the json representation of the item.

Returns

The json representation of the item.

Return type

str

load_price()float[source]

Requests the items webpage, then parses it for the item price, and returns the price.

Returns

The item price.

Return type

float

price: float = None
query: Dict[str, Any]
tag_name: str
url: str

models.model module

This module contains the Model model class.

models.model.logger

The logger used to log information of module.

Type

logging.Logger

class models.model.Model(_id: Optional[Union[str, bson.objectid.ObjectId]] = None)[source]

Bases: object

Class that models a generic model.

collection

The database collection name of the class.

Type

str

_id

The id of the model object.

Type

Union[str, ObjectId]

classmethod all() → List[models.model.Model][source]

Finds and returns all the models corresponding to the model’s collection.

Returns

The list of all the models of the model’s collection.

Return type

List[Model]

collection: str
classmethod find_many_by(attribute: str, value: Union[str, dict]) → List[models.model.Model][source]

Finds and returns all the models corresponding to an attribute value query.

Parameters attribute : str

The attribute to query by.

valueUnion[str, dict]

The value of the attribute to query by.

Returns

The list of models corresponding to the query.

Return type

Model

classmethod find_one_by(attribute: str, value: Union[str, dict])models.model.Model[source]

Finds and returns the model corresponding to an attribute value query.

Parameters
  • attribute (str) – The attribute to query by.

  • value (Union[str, dict]) – The value of the attribute to query by.

Returns

The model corresponding to the query.

Return type

Model

classmethod get_by_id(_id: Union[str, bson.objectid.ObjectId])models.model.Model[source]

Finds and returns a model by id from the database.

Parameters

_id (Union[str, ObjectId]) – The id of the model object.

Returns

The model corresponding to the id.

Return type

Model

abstract json()dict[source]

Returns the json representation of the model.

Returns

The json representation of the model

Return type

dict

Raises

NotImplementedError – If the method is called without being implemented.

remove_from_mongo()[source]

Removes the model from the MongoDB database.

save_to_mongo()[source]

Saves the model to the MongoDB database.

models.store module

This module contains the Store Model class.

models.store.logger

The logger used to log information of module.

Type

logging.Logger

class models.store.Store(name: str, url_prefix: str, tag_name: str, query: Dict[str, Any], _id: InitVar[Union[str, ObjectId]] = None)[source]

Bases: models.model.Model

” Class that models a store.

collection

The database collection name of the store class.

Type

str

URL_PREFIX_REGEX

The regex expression used to validate a URL prefix.

Type

str

name

The store name.

Type

str

url_prefix

The store URL prefix.

Type

str

tag_name

The store’s tag name.

Type

str

query

The CSS selector used to find the item.

Type

str

_id

The id of the store.

Type

InitVar[Union[str, ObjectId]]

URL_PREFIX_REGEX: str = '(^https?:\\/\\/.+?\\/$)'
collection: str = 'stores'
classmethod find_by_url(url: str)models.store.Store[source]

Gets a store by URL.

Parameters

url_prefix (str) – The store name.

Returns

The store corresponding to the URL provided.

Return type

Store

classmethod fix_post_url_prefix(url: str)str[source]

Tries to fix post url prefix.

Parameters

url (str) – The URL to be fixed.

Returns

The fixed URL if it was fixed, otherwise the original URL is returned.

Return type

str

classmethod fix_pre_and_post_url_prefix(url: str)str[source]

Tries to fix pre and post url prefix.

Parameters

url (str) – The URL to be fixed.

Returns

The fixed URL if it was fixed, otherwise the original URL is returned.

Return type

str

classmethod fix_pre_url_prefix(url: str)str[source]

Tries to fix the pre url prefix.

Parameters

url (str) – The URL to be fixed.

Returns

The fixed URL if it was fixed, otherwise the original URL is returned.

Return type

str

classmethod fix_url_prefix(url: str)str[source]

Tries to fix the URL prefix.

Parameters

url (str) – The URL to be fixed.

Returns

The fixed URL if it was fixed, otherwise the original URL is returned.

Return type

str

Raises

ValueError – If the URL is invalid or unfixable.

classmethod get_by_name(store_name: str)models.store.Store[source]

Gets a store by name.

Parameters

store_name (str) – The store name.

Returns

The store corresponding to the store name provided.

Return type

Store

classmethod get_by_url_prefix(url_prefix: str)models.store.Store[source]

Gets a store by URL prefix.

Parameters

url_prefix (str) – The store name.

Returns

The store corresponding to the URL prefix provided.

Return type

Store

json()dict[source]

Returns the json representation of the store.

Returns

The json representation of the store.

Return type

dict

name: str
query: Dict[str, Any]
tag_name: str
url_prefix: str
classmethod validate_url_prefix(url: str)bool[source]

Validates a URL prefix.

Parameters

url (str) – The url to be validated.

Returns

True if URL valid, False otherwise.

Return type

bool

Module contents