2023-02-05 16:40:22 +00:00
|
|
|
import pymongo.collection
|
|
|
|
import typing as t
|
|
|
|
import bson
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class MongoReview(t.TypedDict):
|
|
|
|
"""
|
|
|
|
A review as it is stored on MongoDB.
|
|
|
|
|
|
|
|
.. warning:: Do not instantiate: this is only for type hints!
|
|
|
|
"""
|
|
|
|
_id: bson.ObjectId
|
|
|
|
reviewerID: str
|
|
|
|
asin: str
|
|
|
|
reviewerName: str
|
|
|
|
helpful: tuple[int, int]
|
|
|
|
reviewText: str
|
|
|
|
overall: float
|
|
|
|
summary: str
|
|
|
|
unixReviewTime: int
|
|
|
|
reviewTime: str
|
|
|
|
|
|
|
|
|
|
|
|
def reviews_collection(db: pymongo.MongoClient) -> pymongo.collection.Collection[MongoReview]:
|
|
|
|
"""
|
2023-02-13 17:58:39 +00:00
|
|
|
Create a new MongoDB client, access the ``reviews`` collection in the ``reviews`` database, and return it.
|
2023-02-05 16:40:22 +00:00
|
|
|
"""
|
|
|
|
log.debug("Accessing the reviews collection...")
|
2023-02-08 09:54:14 +00:00
|
|
|
collection: pymongo.collection.Collection[MongoReview] = db.reviews.reviews
|
|
|
|
log.debug("Collection accessed successfully: %s", collection.name)
|
2023-02-05 16:40:22 +00:00
|
|
|
return collection
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
"MongoReview",
|
|
|
|
"reviews_collection",
|
|
|
|
)
|