Skip to content

Commit 7dae014

Browse files
author
meghost77
committed
add price
1 parent af32788 commit 7dae014

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

config.py

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class Settings(BaseSettings):
3636
commentCount
3737
tags
3838
authorUsername
39+
price {
40+
formattedPrice
41+
}
3942
}
4043
pageInfo {
4144
hasNextPage

db/models.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
from datetime import datetime
22
from typing import List, Optional, Union
33

4-
from pydantic import BaseModel
4+
from pydantic import BaseModel, Field
55

66
# Base model for a post
77

88

9+
class Price(BaseModel):
10+
formattedPrice: Optional[str] = Field(
11+
None, description="Formatted price of the item")
12+
13+
914
class Post(BaseModel):
1015
id: Union[str, int] # ID can be either string or integer
1116
bodyHTML: str # HTML content of the post
@@ -18,6 +23,7 @@ class Post(BaseModel):
1823
commentCount: int # Number of comments on the post
1924
tags: Optional[List[str]] = None
2025
authorUsername: Optional[str] = None
26+
price: Optional[Price] = None
2127
# Detailed model for a post extending the base Post model
2228

2329

utils/services.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ async def parse_and_store_posts(search_query: str, city: Optional[str] = None):
115115
'firstImage': item['imagesList'][0] if item['imagesList'] else None,
116116
'commentCount': item.get('commentCount', 0),
117117
'tags': item.get('tags', []),
118-
'authorUsername': item.get('authorUsername')
118+
'authorUsername': item.get('authorUsername'),
119+
'price': {
120+
'formattedPrice': item.get('price', {}).get('formattedPrice')
121+
} if item.get('price') else None
119122
}
120123
logger.debug(f"Storing post {post_data['id']}")
121124
await update_one(collection_name, {'id': post_data['id']}, {'$set': post_data}, upsert=True)

0 commit comments

Comments
 (0)