Skip to content

Commit 3667856

Browse files
fix all open issues
1 parent 38df013 commit 3667856

5 files changed

Lines changed: 256 additions & 82 deletions

File tree

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
paths:
8+
- "**/*.py"
9+
- "requirements.txt"
10+
- "pyproject.toml"
11+
- ".github/workflows/test.yml"
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- name: Free disk space
23+
run: |
24+
sudo rm -rf /usr/share/dotnet || true
25+
sudo rm -rf /usr/local/lib/android || true
26+
sudo rm -rf /opt/ghc || true
27+
sudo rm -rf /usr/local/share/boost || true
28+
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
29+
30+
- name: Set up Python 3.11
31+
uses: actions/setup-python@v6
32+
with:
33+
python-version: "3.11"
34+
cache: "pip"
35+
cache-dependency-path: |
36+
requirements.txt
37+
requirements-dev.txt
38+
39+
- name: Install dependencies
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -e . -r requirements.txt
43+
44+
- name: Run tests
45+
run: |
46+
pytest tests/ -v --tb=long

curl_example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Replace all contents of this file with the following:
44
3. On the home timeline (click on following) press F12, this will open devtools in Chrome
55
4. Go to the Network section
66
5. Locate HomeTimeline or HomeLatestTimeline (when using Following tab)
7+
You can filter on XHR and use the search bar to quickly find it. Try a refresh if you do not see it.
78
6. Right click on HomeTimeline, copy
89
Chrome: copy as cURL (bash)
910
Firefox: copy as cURL (posix)

src/tweet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Tweet:
6262
replies: int = 0
6363
views: int = 0
6464
is_update: bool = False
65+
is_subscriber_only: bool = False
6566
quoted_tweet: Tweet | None = None
6667

6768
def to_dict(self) -> dict:

src/xclient.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,12 @@ def _load_curl(self) -> None:
236236
self._req = {}
237237

238238
def _log_request_health_hint(self) -> None:
239-
headers = {str(k).lower(): str(v) for k, v in self._req.get("headers", {}).items()}
240-
cookies = {str(k).lower(): str(v) for k, v in self._req.get("cookies", {}).items()}
239+
headers = {
240+
str(k).lower(): str(v) for k, v in self._req.get("headers", {}).items()
241+
}
242+
cookies = {
243+
str(k).lower(): str(v) for k, v in self._req.get("cookies", {}).items()
244+
}
241245
warnings: list[str] = []
242246

243247
if "authorization" not in headers:
@@ -465,11 +469,7 @@ def _save_errored_tweet(self, tweet: dict, error_msg: str) -> None:
465469
)
466470

467471
def _user_field(self, tweet: dict, key: str) -> str:
468-
result = (
469-
tweet.get("core", {})
470-
.get("user_results", {})
471-
.get("result", {})
472-
)
472+
result = tweet.get("core", {}).get("user_results", {}).get("result", {})
473473
# New API shape: name/screen_name live in result.core; image in result.avatar
474474
if key in ("name", "screen_name", "created_at"):
475475
value = result.get("core", {}).get(key, "")
@@ -590,6 +590,9 @@ def _parse_single_tweet(self, tw: dict) -> Tweet | None:
590590
# media
591591
media_items, media_types = self._collect_media(tw)
592592

593+
# subscriber-only (creator subscription / Super Follow)
594+
is_subscriber_only = bool(tw.get("exclusivityInfo"))
595+
593596
# reply/quote/retweet handling (best-effort)
594597
title = f"{user_name} tweeted"
595598
quoted = tw.get("quoted_status_result") or None
@@ -666,6 +669,7 @@ def _parse_nested(n: dict) -> Tweet | None:
666669
retweets=retweets,
667670
replies=replies,
668671
views=views,
672+
is_subscriber_only=is_subscriber_only,
669673
quoted_tweet=quoted_tweet,
670674
)
671675

@@ -791,7 +795,7 @@ async def _example_stream():
791795

792796

793797
# if __name__ == "__main__":
794-
# asyncio.run(_example_stream())
795-
# Set os env XCLIENT_DEBUG_HTTP
796-
# os.environ["XCLIENT_DEBUG_HTTP"] = "1"
797-
# asyncio.run(_example_once())
798+
# asyncio.run(_example_stream())
799+
# Set os env XCLIENT_DEBUG_HTTP
800+
# os.environ["XCLIENT_DEBUG_HTTP"] = "1"
801+
# asyncio.run(_example_once())

0 commit comments

Comments
 (0)