twitter-cli 0.3.3__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. twitter_cli-0.4.0/.github/workflows/publish-clawhub.yml +119 -0
  2. twitter_cli-0.4.0/LICENSE +191 -0
  3. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/PKG-INFO +2 -1
  4. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/pyproject.toml +1 -1
  5. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/auth.py +90 -11
  6. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/client.py +28 -2
  7. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/formatter.py +1 -1
  8. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/uv.lock +1 -1
  9. twitter_cli-0.3.3/.github/workflows/publish-clawhub.yml +0 -59
  10. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/.github/workflows/ci.yml +0 -0
  11. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/.github/workflows/publish.yml +0 -0
  12. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/.gitignore +0 -0
  13. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/README.md +0 -0
  14. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/SKILL.md +0 -0
  15. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/config.yaml +0 -0
  16. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/tests/conftest.py +0 -0
  17. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/tests/test_cli.py +0 -0
  18. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/tests/test_config.py +0 -0
  19. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/tests/test_config_normalization.py +0 -0
  20. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/tests/test_filter.py +0 -0
  21. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/tests/test_serialization.py +0 -0
  22. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/__init__.py +0 -0
  23. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/cli.py +0 -0
  24. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/config.py +0 -0
  25. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/constants.py +0 -0
  26. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/filter.py +0 -0
  27. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/models.py +0 -0
  28. {twitter_cli-0.3.3 → twitter_cli-0.4.0}/twitter_cli/serialization.py +0 -0
@@ -0,0 +1,119 @@
1
+ name: Publish to ClawHub
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ env:
15
+ CLAWHUB_SLUG: twitter-cli
16
+ CLAWHUB_NAME: twitter-cli
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: "20"
24
+
25
+ - name: Install ClawHub CLI
26
+ run: npm install -g clawhub@0.7.0
27
+
28
+ - name: Publish to ClawHub
29
+ env:
30
+ CLAWHUB_TOKEN: ${{ secrets.CLAWHUB_TOKEN }}
31
+ run: |
32
+ if [ -z "${CLAWHUB_TOKEN:-}" ]; then
33
+ echo "Missing required secret: CLAWHUB_TOKEN"
34
+ exit 1
35
+ fi
36
+
37
+ if [ "${GITHUB_REF_TYPE:-}" = "tag" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
38
+ VERSION="${GITHUB_REF_NAME#v}"
39
+ else
40
+ VERSION="$(sed -n 's/^version = \"\([^\"]*\)\"/\1/p' pyproject.toml | head -n 1)"
41
+ fi
42
+ if [ -z "${VERSION:-}" ]; then
43
+ echo "Unable to resolve version"
44
+ exit 1
45
+ fi
46
+ echo "Publishing ${CLAWHUB_SLUG}@${VERSION}"
47
+
48
+ if clawhub --no-input inspect "${CLAWHUB_SLUG}" --version "${VERSION}" >/dev/null 2>&1; then
49
+ echo "Version ${VERSION} already exists on ClawHub, skipping publish."
50
+ exit 0
51
+ fi
52
+
53
+ clawhub --no-input login --token "${CLAWHUB_TOKEN}" --no-browser
54
+
55
+ # Workaround: clawhub@0.7.0 publish doesn't send acceptLicenseTerms,
56
+ # which the server now requires. Use a Node.js script to publish with
57
+ # the corrected payload.
58
+ node - <<'PUBLISH_SCRIPT'
59
+ const { resolve } = require("path");
60
+ const { readFileSync, statSync, readdirSync } = require("fs");
61
+ const folder = resolve(".");
62
+ const slug = process.env.CLAWHUB_SLUG;
63
+ const version = process.env.VERSION;
64
+
65
+ // Collect text files (same logic as clawhub CLI)
66
+ function walk(dir, base = "") {
67
+ let files = [];
68
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
69
+ const rel = base ? base + "/" + entry.name : entry.name;
70
+ if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
71
+ if (entry.isDirectory()) { files.push(...walk(dir + "/" + entry.name, rel)); }
72
+ else { files.push({ rel, abs: dir + "/" + entry.name }); }
73
+ }
74
+ return files;
75
+ }
76
+ const files = walk(folder).filter(f => {
77
+ const ext = f.rel.split(".").pop().toLowerCase();
78
+ return ["md","txt","py","toml","yml","yaml","json","cfg","ini","sh","bat"].includes(ext);
79
+ });
80
+
81
+ const payload = JSON.stringify({
82
+ slug,
83
+ displayName: slug,
84
+ version,
85
+ changelog: "Release " + version,
86
+ tags: ["latest"],
87
+ acceptLicenseTerms: true,
88
+ });
89
+
90
+ const form = new FormData();
91
+ form.set("payload", payload);
92
+ for (const file of files) {
93
+ const bytes = readFileSync(file.abs);
94
+ const blob = new Blob([bytes], { type: "text/plain" });
95
+ form.append("files", blob, file.rel);
96
+ }
97
+
98
+ // Read registry and token from clawhub config
99
+ const os = require("os");
100
+ const configPath = resolve(os.homedir(), ".config", "clawhub", "config.json");
101
+ let token = "";
102
+ try {
103
+ const cfg = JSON.parse(readFileSync(configPath, "utf8"));
104
+ token = cfg.token || "";
105
+ } catch {}
106
+ if (!token) { console.error("No token found"); process.exit(1); }
107
+
108
+ const registry = "https://api.clawhub.io";
109
+ fetch(registry + "/api/v1/skills", {
110
+ method: "POST",
111
+ headers: { Authorization: "Bearer " + token },
112
+ body: form,
113
+ }).then(async r => {
114
+ const text = await r.text();
115
+ if (!r.ok) { console.error("Publish failed:", r.status, text); process.exit(1); }
116
+ console.log("✔ Published", slug + "@" + version);
117
+ }).catch(e => { console.error(e); process.exit(1); });
118
+ PUBLISH_SCRIPT
119
+
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2024 jackwener
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -1,12 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter-cli
3
- Version: 0.3.3
3
+ Version: 0.4.0
4
4
  Summary: A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal
5
5
  Project-URL: Homepage, https://github.com/jackwener/twitter-cli
6
6
  Project-URL: Repository, https://github.com/jackwener/twitter-cli
7
7
  Project-URL: Issues, https://github.com/jackwener/twitter-cli/issues
8
8
  Author-email: jackwener <jakevingoo@gmail.com>
9
9
  License-Expression: Apache-2.0
10
+ License-File: LICENSE
10
11
  Keywords: cli,feed,timeline,twitter,x
11
12
  Classifier: Development Status :: 3 - Alpha
12
13
  Classifier: Environment :: Console
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "twitter-cli"
7
- version = "0.3.3"
7
+ version = "0.4.0"
8
8
  description = "A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -2,8 +2,10 @@
2
2
 
3
3
  Supports:
4
4
  1. Environment variables: TWITTER_AUTH_TOKEN + TWITTER_CT0
5
- 2. Auto-extract from browser via browser-cookie3 (subprocess)
5
+ 2. Auto-extract from browser via browser-cookie3
6
6
  Extracts ALL Twitter cookies for full browser-like fingerprint.
7
+ Prefers in-process extraction (required on macOS for Keychain access),
8
+ falls back to subprocess if in-process fails (e.g. SQLite lock).
7
9
  """
8
10
 
9
11
  from __future__ import annotations
@@ -21,6 +23,14 @@ from .constants import BEARER_TOKEN, USER_AGENT
21
23
 
22
24
  logger = logging.getLogger(__name__)
23
25
 
26
+ # Domains to match for Twitter cookies
27
+ _TWITTER_DOMAINS = {"x.com", "twitter.com", ".x.com", ".twitter.com"}
28
+
29
+
30
+ def _is_twitter_domain(domain):
31
+ # type: (str) -> bool
32
+ return domain in _TWITTER_DOMAINS or domain.endswith(".x.com") or domain.endswith(".twitter.com")
33
+
24
34
 
25
35
  def load_from_env() -> Optional[Dict[str, str]]:
26
36
  """Load cookies from environment variables."""
@@ -39,6 +49,8 @@ def verify_cookies(auth_token, ct0, cookie_string=None):
39
49
  Tries multiple endpoints. Only raises on clear auth failures (401/403).
40
50
  For other errors (404, network), returns empty dict (proceed without verification).
41
51
  """
52
+ from .client import _best_chrome_target
53
+
42
54
  urls = [
43
55
  "https://api.x.com/1.1/account/verify_credentials.json",
44
56
  "https://x.com/i/api/1.1/account/settings.json",
@@ -58,7 +70,7 @@ def verify_cookies(auth_token, ct0, cookie_string=None):
58
70
 
59
71
  proxy = os.environ.get("TWITTER_PROXY", "")
60
72
  session = _cffi_requests.Session(
61
- impersonate="chrome133",
73
+ impersonate=_best_chrome_target(),
62
74
  proxies={"https": proxy, "http": proxy} if proxy else None,
63
75
  )
64
76
 
@@ -85,16 +97,66 @@ def verify_cookies(auth_token, ct0, cookie_string=None):
85
97
  return {}
86
98
 
87
99
 
88
- def extract_from_browser() -> Optional[Dict[str, str]]:
89
- """Auto-extract ALL Twitter cookies from local browser using browser-cookie3.
100
+ def _extract_cookies_from_jar(jar):
101
+ # type: (Any) -> Optional[Dict[str, str]]
102
+ """Extract Twitter cookies from a cookie jar."""
103
+ result = {} # type: Dict[str, str]
104
+ all_cookies = {} # type: Dict[str, str]
105
+ for cookie in jar:
106
+ domain = cookie.domain or ""
107
+ if _is_twitter_domain(domain):
108
+ if cookie.name == "auth_token":
109
+ result["auth_token"] = cookie.value
110
+ elif cookie.name == "ct0":
111
+ result["ct0"] = cookie.value
112
+ if cookie.name and cookie.value:
113
+ all_cookies[cookie.name] = cookie.value
114
+ if "auth_token" in result and "ct0" in result:
115
+ cookies = {"auth_token": result["auth_token"], "ct0": result["ct0"]}
116
+ if all_cookies:
117
+ cookies["cookie_string"] = "; ".join("%s=%s" % (k, v) for k, v in all_cookies.items())
118
+ logger.info("Extracted %d total cookies for full browser fingerprint", len(all_cookies))
119
+ return cookies
120
+ return None
90
121
 
91
- Extracts every cookie for .x.com and .twitter.com domains, not just
92
- auth_token and ct0. This makes requests indistinguishable from real
93
- browser traffic at the cookie level.
94
122
 
95
- Tries browsers in order: Chrome -> Edge -> Firefox -> Brave.
96
- Runs in a subprocess to avoid SQLite database lock issues.
123
+ def _extract_in_process():
124
+ # type: () -> Optional[Dict[str, str]]
125
+ """Extract cookies in the main process (required on macOS for Keychain access).
126
+
127
+ On macOS, Chrome encrypts cookies using a key stored in the system Keychain.
128
+ Child processes do NOT inherit the parent's Keychain authorization, so
129
+ browser_cookie3 must run in the main process to decrypt cookies.
97
130
  """
131
+ try:
132
+ import browser_cookie3
133
+ except ImportError:
134
+ logger.debug("browser_cookie3 not installed, skipping in-process extraction")
135
+ return None
136
+
137
+ browsers = [
138
+ ("chrome", browser_cookie3.chrome),
139
+ ("edge", browser_cookie3.edge),
140
+ ("firefox", browser_cookie3.firefox),
141
+ ("brave", browser_cookie3.brave),
142
+ ]
143
+
144
+ for name, fn in browsers:
145
+ try:
146
+ jar = fn()
147
+ except Exception as e:
148
+ logger.debug("%s in-process extraction failed: %s", name, e)
149
+ continue
150
+ cookies = _extract_cookies_from_jar(jar)
151
+ if cookies:
152
+ logger.info("Found cookies in %s (in-process)", name)
153
+ return cookies
154
+ return None
155
+
156
+
157
+ def _extract_via_subprocess():
158
+ # type: () -> Optional[Dict[str, str]]
159
+ """Extract cookies via subprocess (fallback if in-process fails, e.g. SQLite lock)."""
98
160
  extract_script = '''
99
161
  import json, sys
100
162
  try:
@@ -124,7 +186,6 @@ for name, fn in browsers:
124
186
  result["auth_token"] = cookie.value
125
187
  elif cookie.name == "ct0":
126
188
  result["ct0"] = cookie.value
127
- # Collect ALL cookies for full browser fingerprint
128
189
  if cookie.name and cookie.value:
129
190
  all_cookies[cookie.name] = cookie.value
130
191
  if "auth_token" in result and "ct0" in result:
@@ -164,7 +225,7 @@ sys.exit(1)
164
225
  data = json.loads(output)
165
226
  if "error" in data:
166
227
  return None
167
- logger.info("Found cookies in %s", data.get("browser", "unknown"))
228
+ logger.info("Found cookies in %s (subprocess)", data.get("browser", "unknown"))
168
229
 
169
230
  # Build full cookie string from all extracted cookies
170
231
  cookies = {"auth_token": data["auth_token"], "ct0": data["ct0"]}
@@ -178,6 +239,23 @@ sys.exit(1)
178
239
  return None
179
240
 
180
241
 
242
+ def extract_from_browser() -> Optional[Dict[str, str]]:
243
+ """Auto-extract ALL Twitter cookies from local browser using browser-cookie3.
244
+
245
+ Strategy:
246
+ 1. Try in-process first (required on macOS for Keychain access)
247
+ 2. Fall back to subprocess (handles SQLite lock when browser is running)
248
+ """
249
+ # 1. In-process (works on macOS, may fail with SQLite lock)
250
+ cookies = _extract_in_process()
251
+ if cookies:
252
+ return cookies
253
+
254
+ # 2. Subprocess fallback (handles SQLite lock, but fails on macOS Keychain)
255
+ logger.debug("In-process extraction failed, trying subprocess fallback")
256
+ return _extract_via_subprocess()
257
+
258
+
181
259
  def get_cookies() -> Dict[str, str]:
182
260
  """Get Twitter cookies. Priority: env vars -> browser extraction (Chrome/Edge/Firefox/Brave).
183
261
 
@@ -205,3 +283,4 @@ def get_cookies() -> Dict[str, str]:
205
283
  verify_cookies(cookies["auth_token"], cookies["ct0"], cookies.get("cookie_string"))
206
284
  return cookies
207
285
 
286
+
@@ -22,7 +22,6 @@ logger = logging.getLogger(__name__)
22
22
 
23
23
  # Shared curl_cffi session — impersonates Chrome 133 TLS/JA3/HTTP2 fingerprint
24
24
  _cffi_session = None # type: Optional[Any] # lazy init
25
- _cffi_proxy = None # type: Optional[str]
26
25
 
27
26
 
28
27
  FALLBACK_QUERY_IDS = {
@@ -107,6 +106,31 @@ class TwitterAPIError(RuntimeError):
107
106
  super().__init__(message)
108
107
  self.status_code = status_code
109
108
 
109
+ def _best_chrome_target():
110
+ # type: () -> str
111
+ """Detect the best available Chrome impersonation target at runtime.
112
+
113
+ curl_cffi versions differ in which Chrome targets they ship.
114
+ e.g. 0.14.0 has chrome133a but not chrome133.
115
+ """
116
+ try:
117
+ from curl_cffi.requests import BrowserType
118
+ available = {e.value for e in BrowserType}
119
+ except Exception:
120
+ available = set()
121
+
122
+ # Preference order: exact chrome versions, then suffixed variants
123
+ for target in ("chrome133", "chrome133a", "chrome136", "chrome131", "chrome130"):
124
+ if target in available:
125
+ return target
126
+ # Fallback: pick highest chrome* with a pure numeric suffix
127
+ chrome_targets = sorted(
128
+ [v for v in available if v.startswith("chrome") and v.replace("chrome", "").isdigit()],
129
+ key=lambda x: int(x.replace("chrome", "")),
130
+ reverse=True,
131
+ )
132
+ return chrome_targets[0] if chrome_targets else "chrome131"
133
+
110
134
 
111
135
  def _get_cffi_session():
112
136
  # type: () -> Any
@@ -115,10 +139,12 @@ def _get_cffi_session():
115
139
  if _cffi_session is None:
116
140
  import os
117
141
  proxy = os.environ.get("TWITTER_PROXY", "")
142
+ target = _best_chrome_target()
118
143
  _cffi_session = _cffi_requests.Session(
119
- impersonate="chrome133",
144
+ impersonate=target,
120
145
  proxies={"https": proxy, "http": proxy} if proxy else None,
121
146
  )
147
+ logger.info("curl_cffi impersonating %s", target)
122
148
  if proxy:
123
149
  logger.info("Using proxy: %s", proxy[:20] + "...")
124
150
  return _cffi_session
@@ -79,7 +79,7 @@ def print_tweet_table(tweets, console=None, title=None):
79
79
  )
80
80
 
81
81
  # Score
82
- score_str = "%.1f" % tweet.score if tweet.score else "-"
82
+ score_str = "%.1f" % tweet.score if tweet.score is not None else "-"
83
83
 
84
84
  table.add_row(str(i + 1), author_text, text, stats, score_str)
85
85
 
@@ -950,7 +950,7 @@ wheels = [
950
950
 
951
951
  [[package]]
952
952
  name = "twitter-cli"
953
- version = "0.3.2"
953
+ version = "0.3.4"
954
954
  source = { editable = "." }
955
955
  dependencies = [
956
956
  { name = "beautifulsoup4" },
@@ -1,59 +0,0 @@
1
- name: Publish to ClawHub
2
-
3
- on:
4
- push:
5
- tags:
6
- - "v*"
7
- workflow_dispatch:
8
-
9
- jobs:
10
- publish:
11
- runs-on: ubuntu-latest
12
- permissions:
13
- contents: read
14
- env:
15
- CLAWHUB_SLUG: twitter-cli
16
- CLAWHUB_NAME: twitter-cli
17
-
18
- steps:
19
- - uses: actions/checkout@v4
20
-
21
- - uses: actions/setup-node@v4
22
- with:
23
- node-version: "20"
24
-
25
- - name: Install ClawHub CLI
26
- run: npm install -g clawhub@0.7.0
27
-
28
- - name: Publish to ClawHub
29
- env:
30
- CLAWHUB_TOKEN: ${{ secrets.CLAWHUB_TOKEN }}
31
- run: |
32
- if [ -z "${CLAWHUB_TOKEN:-}" ]; then
33
- echo "Missing required secret: CLAWHUB_TOKEN"
34
- exit 1
35
- fi
36
-
37
- if [ "${GITHUB_REF_TYPE:-}" = "tag" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
38
- VERSION="${GITHUB_REF_NAME#v}"
39
- else
40
- VERSION="$(sed -n 's/^version = \"\([^\"]*\)\"/\1/p' pyproject.toml | head -n 1)"
41
- fi
42
- if [ -z "${VERSION:-}" ]; then
43
- echo "Unable to resolve version"
44
- exit 1
45
- fi
46
- echo "Publishing ${CLAWHUB_SLUG}@${VERSION}"
47
-
48
- if clawhub --no-input inspect "${CLAWHUB_SLUG}" --version "${VERSION}" >/dev/null 2>&1; then
49
- echo "Version ${VERSION} already exists on ClawHub, skipping publish."
50
- exit 0
51
- fi
52
-
53
- clawhub --no-input login --token "${CLAWHUB_TOKEN}" --no-browser
54
- clawhub --no-input publish . \
55
- --slug "${CLAWHUB_SLUG}" \
56
- --name "${CLAWHUB_NAME}" \
57
- --version "${VERSION}" \
58
- --changelog "Release ${VERSION}" \
59
- --tags latest
File without changes
File without changes
File without changes
File without changes