From 6a6a002e7492394cf6b2f6d231667b164cf41d06 Mon Sep 17 00:00:00 2001 From: jasta Date: Sat, 17 Aug 2024 18:42:37 +0900 Subject: [PATCH 1/3] add links of tweets --- api/birdxplorer_api/routers/data.py | 4 ++++ common/birdxplorer_common/models.py | 1 + 2 files changed, 5 insertions(+) diff --git a/api/birdxplorer_api/routers/data.py b/api/birdxplorer_api/routers/data.py index 418cbd6..2959dbc 100644 --- a/api/birdxplorer_api/routers/data.py +++ b/api/birdxplorer_api/routers/data.py @@ -123,6 +123,10 @@ def get_posts( total_count = len(posts) paginated_posts = posts[offset : offset + limit] + for post in paginated_posts: + post.link = f"https://x.com/{post.x_user.name}/status/{post.post_id}" + + base_url = str(request.url).split("?")[0] next_offset = offset + limit prev_offset = max(offset - limit, 0) diff --git a/common/birdxplorer_common/models.py b/common/birdxplorer_common/models.py index 7e3ab8e..5b74fdd 100644 --- a/common/birdxplorer_common/models.py +++ b/common/birdxplorer_common/models.py @@ -678,6 +678,7 @@ class XUser(BaseModel): class Post(BaseModel): + link: HttpUrl post_id: PostId x_user_id: UserId x_user: XUser From 223fc0b6be3be57456162a34e01d7c4b9b1b8bcf Mon Sep 17 00:00:00 2001 From: jasta Date: Sun, 18 Aug 2024 10:43:57 +0900 Subject: [PATCH 2/3] fix: HttpUrl type specified --- api/birdxplorer_api/routers/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/birdxplorer_api/routers/data.py b/api/birdxplorer_api/routers/data.py index 2959dbc..18e86a5 100644 --- a/api/birdxplorer_api/routers/data.py +++ b/api/birdxplorer_api/routers/data.py @@ -3,6 +3,7 @@ from dateutil.parser import parse as dateutil_parse from fastapi import APIRouter, HTTPException, Query, Request +from pydantic import HttpUrl from birdxplorer_common.models import ( BaseModel, @@ -124,8 +125,7 @@ def get_posts( total_count = len(posts) paginated_posts = posts[offset : offset + limit] for post in paginated_posts: - post.link = f"https://x.com/{post.x_user.name}/status/{post.post_id}" - + post.link = HttpUrl(f"https://x.com/{post.x_user.name}/status/{post.post_id}") base_url = str(request.url).split("?")[0] next_offset = offset + limit From 88a7c075d1e279097fd041f3de748a7dcdff1ec5 Mon Sep 17 00:00:00 2001 From: yu23ki14 Date: Sun, 18 Aug 2024 11:02:33 +0900 Subject: [PATCH 3/3] fix post link --- common/birdxplorer_common/models.py | 2 +- common/tests/conftest.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common/birdxplorer_common/models.py b/common/birdxplorer_common/models.py index 5b74fdd..72052dd 100644 --- a/common/birdxplorer_common/models.py +++ b/common/birdxplorer_common/models.py @@ -678,8 +678,8 @@ class XUser(BaseModel): class Post(BaseModel): - link: HttpUrl post_id: PostId + link: Optional[HttpUrl] = None x_user_id: UserId x_user: XUser text: str diff --git a/common/tests/conftest.py b/common/tests/conftest.py index 71ab36d..22e34cc 100644 --- a/common/tests/conftest.py +++ b/common/tests/conftest.py @@ -205,6 +205,7 @@ def post_samples(post_factory: PostFactory, x_user_samples: List[XUser]) -> Gene posts = [ post_factory.build( post_id="2234567890123456781", + link=None, x_user_id="1234567890123456781", x_user=x_user_samples[0], text="text11", @@ -216,6 +217,7 @@ def post_samples(post_factory: PostFactory, x_user_samples: List[XUser]) -> Gene ), post_factory.build( post_id="2234567890123456791", + link=None, x_user_id="1234567890123456781", x_user=x_user_samples[0], text="text12", @@ -227,6 +229,7 @@ def post_samples(post_factory: PostFactory, x_user_samples: List[XUser]) -> Gene ), post_factory.build( post_id="2234567890123456801", + link=None, x_user_id="1234567890123456782", x_user=x_user_samples[1], text="text21",