tw2img 0.1.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.
- tw2img-0.1.0/PKG-INFO +194 -0
- tw2img-0.1.0/README.md +185 -0
- tw2img-0.1.0/article2img.py +1299 -0
- tw2img-0.1.0/pyproject.toml +21 -0
- tw2img-0.1.0/setup.cfg +4 -0
- tw2img-0.1.0/tw2img.egg-info/PKG-INFO +194 -0
- tw2img-0.1.0/tw2img.egg-info/SOURCES.txt +10 -0
- tw2img-0.1.0/tw2img.egg-info/dependency_links.txt +1 -0
- tw2img-0.1.0/tw2img.egg-info/entry_points.txt +3 -0
- tw2img-0.1.0/tw2img.egg-info/requires.txt +1 -0
- tw2img-0.1.0/tw2img.egg-info/top_level.txt +2 -0
- tw2img-0.1.0/tw2img.py +1435 -0
tw2img-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tw2img
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Render tweets as PNG/JPG images using Playwright
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: playwright
|
|
9
|
+
|
|
10
|
+
# tw2img
|
|
11
|
+
A tool that renders tweets as PNG images using Playwright (headless Chromium). Works with usernames, tweet IDs, URLs, local JSON files, or stdin.
|
|
12
|
+
This style is based on [nitter](https://github.com/zedeus/nitter/) using [Midnight](https://github.com/cmj/nitter/blob/master/public/css/themes/midnight.css) theme as default.
|
|
13
|
+
|  |  |
|
|
14
|
+
|---------------------------------|----------------------|
|
|
15
|
+
## Installation
|
|
16
|
+
```bash
|
|
17
|
+
# Install required packages
|
|
18
|
+
pip install playwright
|
|
19
|
+
playwright install chromium
|
|
20
|
+
```
|
|
21
|
+
## Quick Start
|
|
22
|
+
### 1. Guest Mode (no auth token required, missing context for replies)
|
|
23
|
+
```bash
|
|
24
|
+
# By @username (fetch latest tweet)
|
|
25
|
+
python tw2img.py @AP --guest
|
|
26
|
+
# By @username, fetch the 3rd most recent tweet
|
|
27
|
+
python tw2img.py @AP 3 --guest
|
|
28
|
+
# By tweet ID
|
|
29
|
+
python tw2img.py 2041557036274475228 --guest
|
|
30
|
+
# By tweet URL
|
|
31
|
+
python tw2img.py https://x.com/NASA/status/2041557036274475228 --guest
|
|
32
|
+
```
|
|
33
|
+
Here is a list of popular Twitter accounts sorted by most recent, and useful for guest access:\
|
|
34
|
+
https://github.com/cmj/twitter-tools/wiki/RSS%E2%80%90Friendly
|
|
35
|
+
|
|
36
|
+
### 2. Authenticated Mode (full thread + reply data)
|
|
37
|
+
You need your Twitter auth tokens. Export them as environment variables:
|
|
38
|
+
```bash
|
|
39
|
+
export TWITTER_AUTH_TOKEN="your_auth_token_here"
|
|
40
|
+
export TWITTER_CSRF_TOKEN="your_ct0_token_here"
|
|
41
|
+
# alternative, only requires setting auth_token
|
|
42
|
+
export TWITTER_CSRF_TOKEN=$(openssl rand -hex 16)
|
|
43
|
+
```
|
|
44
|
+
Then run:
|
|
45
|
+
```bash
|
|
46
|
+
python tw2img.py 2054583770045386950
|
|
47
|
+
```
|
|
48
|
+
**Where to find tokens:** Open browser devtools, network tab, any x.com request, select cookies tab `auth_token` and `ct0`
|
|
49
|
+
## Basic Options
|
|
50
|
+
| Option | Description |
|
|
51
|
+
|--------|-------------|
|
|
52
|
+
| `@user` | Fetch latest tweet from this user |
|
|
53
|
+
| `--user <name>` | Same as above |
|
|
54
|
+
| `--light` | Use light theme (default is dark) |
|
|
55
|
+
| `--no-source` | Hide the "Twitter for iPhone" source text |
|
|
56
|
+
| `--no-context` | Show only the focal tweet, no thread/replies |
|
|
57
|
+
| `--no-retina` | Disable 2x retina rendering (smaller file) |
|
|
58
|
+
| `--full-stats` | Show full numbers instead of abbreviated (e.g. 12,345 instead of 12.3K) |
|
|
59
|
+
| `--output-dir <path>` | Directory to save output PNG (default: current working directory) |
|
|
60
|
+
| `--width 800` | Set output width in pixels (default: 598) |
|
|
61
|
+
| `--css theme.css` | File to override the theme (ex: nitter/public/css/themes/pleroma.css) |
|
|
62
|
+
| `--nitter` | Use Nitter default theme |
|
|
63
|
+
| `--html-only` | Print HTML to stdout instead of rendering PNG |
|
|
64
|
+
| `--save-html` | Save HTML to this file instead of rendering PNG |
|
|
65
|
+
| `--imgur` | Upload PNG to imgur after rendering |
|
|
66
|
+
| `--dump-json` | Print raw API JSON to stdout and exit |
|
|
67
|
+
| `--view` | Automatically open the rendered output file after creation |
|
|
68
|
+
| `--viewer <cmd>` | Specify custom viewer executable/command (e.g., `viewnior`, `firefox`, or `kitty +icat {}`) |
|
|
69
|
+
| `-c <file>` | Load config from a custom path (see Config below) |
|
|
70
|
+
## Config File
|
|
71
|
+
Options can be set as persistent defaults in a config file (INI format). Config is loaded in this order - later sources override earlier ones:
|
|
72
|
+
|
|
73
|
+
1. `~/.config/tw2img/tw2img.conf` - user default
|
|
74
|
+
2. `<script_dir>/tw2img.conf` - next to the script, if present
|
|
75
|
+
3. `-c /path/to/custom.conf` - explicit override
|
|
76
|
+
4. Command options / flags always have highest priority
|
|
77
|
+
|
|
78
|
+
A default config is included as `tw2img.conf`. To install it:
|
|
79
|
+
```bash
|
|
80
|
+
mkdir -p ~/.config/tw2img
|
|
81
|
+
cp tw2img.conf ~/.config/tw2img/tw2img.conf
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Set a default download directory in the config so you don't have to specify it each run:
|
|
85
|
+
```ini
|
|
86
|
+
[tw2img]
|
|
87
|
+
output_dir = ~/Pictures/tweets
|
|
88
|
+
```
|
|
89
|
+
If `output_dir` is set, all PNGs are saved there unless you pass an explicit output path (absolute or with a directory component) on the command line.
|
|
90
|
+
|
|
91
|
+
Use `-c` to load an alternate config for a specific run without touching your defaults:
|
|
92
|
+
```bash
|
|
93
|
+
python tw2img.py 2054583770045386950 -c ~/work/tw2img-work.conf --light
|
|
94
|
+
```
|
|
95
|
+
## Input Types
|
|
96
|
+
```bash
|
|
97
|
+
# @username shorthand - latest tweet
|
|
98
|
+
python tw2img.py @NASA --guest
|
|
99
|
+
|
|
100
|
+
# @username shorthand - Nth most recent tweet (1-20, skips RTs and replies)
|
|
101
|
+
python tw2img.py @NASA 5 --guest
|
|
102
|
+
|
|
103
|
+
# Explicit --user flag (equivalent to @username)
|
|
104
|
+
python tw2img.py --user NASA --guest
|
|
105
|
+
|
|
106
|
+
# Tweet ID
|
|
107
|
+
python tw2img.py 2054583770045386950 --guest
|
|
108
|
+
|
|
109
|
+
# Full URL
|
|
110
|
+
python tw2img.py "https://x.com/username/status/123456789" --guest
|
|
111
|
+
|
|
112
|
+
# Local JSON file (from API)
|
|
113
|
+
python tw2img.py tweet.json
|
|
114
|
+
|
|
115
|
+
# Stdin (pipe JSON)
|
|
116
|
+
cat tweet.json | python tw2img.py -
|
|
117
|
+
```
|
|
118
|
+
## Output
|
|
119
|
+
By default, saves as `<screen_name>-<tweet_id>.png` in current directory. Specify a custom filename as the argument after the input (or after the tweet index when using `@username`):
|
|
120
|
+
```bash
|
|
121
|
+
# Custom output with tweet ID
|
|
122
|
+
python tw2img.py 2054583770045386950 --guest my_screenshot.png
|
|
123
|
+
|
|
124
|
+
# Custom output with @username shorthand
|
|
125
|
+
python tw2img.py @NASA my_screenshot.png --guest
|
|
126
|
+
|
|
127
|
+
# Custom output with @username and tweet index
|
|
128
|
+
python tw2img.py @NASA 3 my_screenshot.png --guest
|
|
129
|
+
|
|
130
|
+
# Open with a specific GUI viewer
|
|
131
|
+
python tw2img.py @NASA --guest --view --viewer viewnior
|
|
132
|
+
|
|
133
|
+
# Render directly inline inside a supported terminal (like kitty)
|
|
134
|
+
python tw2img.py @NASA --guest --view --viewer "kitty +icat {}"
|
|
135
|
+
|
|
136
|
+
# View directly in Firefox (ideal when combined with --save-html)
|
|
137
|
+
python tw2img.py 2054583770045386950 --save-html tweet.html --view --viewer firefox
|
|
138
|
+
```
|
|
139
|
+
## Examples
|
|
140
|
+
**Basic screenshot with thread (dark mode):**
|
|
141
|
+
```bash
|
|
142
|
+
python tw2img.py 2054583770045386950 --guest
|
|
143
|
+
```
|
|
144
|
+
**Latest tweet from a user:**
|
|
145
|
+
```bash
|
|
146
|
+
python tw2img.py @NASA --guest
|
|
147
|
+
```
|
|
148
|
+
**5th most recent tweet from a user:**
|
|
149
|
+
```bash
|
|
150
|
+
python tw2img.py @NASA 5 --guest
|
|
151
|
+
```
|
|
152
|
+
**Automatically open the snapshot after rendering:**
|
|
153
|
+
```bash
|
|
154
|
+
python tw2img.py @NASA --guest --view
|
|
155
|
+
```
|
|
156
|
+
**Upload to imgur**
|
|
157
|
+
```bash
|
|
158
|
+
python tw2img.py @NASA --guest --imgur
|
|
159
|
+
```
|
|
160
|
+
**Light theme, focal tweet only:**
|
|
161
|
+
```bash
|
|
162
|
+
python tw2img.py 2054583770045386950 --guest --light --no-context
|
|
163
|
+
```
|
|
164
|
+
**Wide screenshot without source:**
|
|
165
|
+
```bash
|
|
166
|
+
python tw2img.py 2054583770045386950 --guest --width 800 --no-source
|
|
167
|
+
```
|
|
168
|
+
**Full stat numbers:**
|
|
169
|
+
```bash
|
|
170
|
+
python tw2img.py 2054583770045386950 --guest --full-stats
|
|
171
|
+
```
|
|
172
|
+
**Print HTML to stdout (for inspection or debugging)**
|
|
173
|
+
```bash
|
|
174
|
+
python tw2img.py 2054583770045386950 --guest --html-only
|
|
175
|
+
```
|
|
176
|
+
**Save HTML to a file**
|
|
177
|
+
```bash
|
|
178
|
+
python tw2img.py 2054583770045386950 --guest --save-html tweet.html
|
|
179
|
+
```
|
|
180
|
+
**Save HTML to a file and load in Firefox**
|
|
181
|
+
```bash
|
|
182
|
+
python tw2img.py --guest @barackobama --full-stats --save-html /tmp/tweet.html && firefox /tmp/tweet.html
|
|
183
|
+
```
|
|
184
|
+
## Articles
|
|
185
|
+
|
|
186
|
+
**Save article and auto-load rendered HTML in Firefox**
|
|
187
|
+
```bash
|
|
188
|
+
# BEST METHOD: Save as HTML and open (uses article_viewer from conf, or xdg-open)
|
|
189
|
+
# Use the tweet url that contains the article link (or simply just the id)
|
|
190
|
+
python article2img.py --guest --save-html out.html --view https://x.com/ARCRaidersGame/status/2054607629738037736
|
|
191
|
+
# Simplify with an alias
|
|
192
|
+
alias tw-article='article2img --guest --save-html /tmp/out.html --view > /dev/null'
|
|
193
|
+
tw-article https://n/XDevelopers/status/2041295840325636551
|
|
194
|
+
```
|
tw2img-0.1.0/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# tw2img
|
|
2
|
+
A tool that renders tweets as PNG images using Playwright (headless Chromium). Works with usernames, tweet IDs, URLs, local JSON files, or stdin.
|
|
3
|
+
This style is based on [nitter](https://github.com/zedeus/nitter/) using [Midnight](https://github.com/cmj/nitter/blob/master/public/css/themes/midnight.css) theme as default.
|
|
4
|
+
|  |  |
|
|
5
|
+
|---------------------------------|----------------------|
|
|
6
|
+
## Installation
|
|
7
|
+
```bash
|
|
8
|
+
# Install required packages
|
|
9
|
+
pip install playwright
|
|
10
|
+
playwright install chromium
|
|
11
|
+
```
|
|
12
|
+
## Quick Start
|
|
13
|
+
### 1. Guest Mode (no auth token required, missing context for replies)
|
|
14
|
+
```bash
|
|
15
|
+
# By @username (fetch latest tweet)
|
|
16
|
+
python tw2img.py @AP --guest
|
|
17
|
+
# By @username, fetch the 3rd most recent tweet
|
|
18
|
+
python tw2img.py @AP 3 --guest
|
|
19
|
+
# By tweet ID
|
|
20
|
+
python tw2img.py 2041557036274475228 --guest
|
|
21
|
+
# By tweet URL
|
|
22
|
+
python tw2img.py https://x.com/NASA/status/2041557036274475228 --guest
|
|
23
|
+
```
|
|
24
|
+
Here is a list of popular Twitter accounts sorted by most recent, and useful for guest access:\
|
|
25
|
+
https://github.com/cmj/twitter-tools/wiki/RSS%E2%80%90Friendly
|
|
26
|
+
|
|
27
|
+
### 2. Authenticated Mode (full thread + reply data)
|
|
28
|
+
You need your Twitter auth tokens. Export them as environment variables:
|
|
29
|
+
```bash
|
|
30
|
+
export TWITTER_AUTH_TOKEN="your_auth_token_here"
|
|
31
|
+
export TWITTER_CSRF_TOKEN="your_ct0_token_here"
|
|
32
|
+
# alternative, only requires setting auth_token
|
|
33
|
+
export TWITTER_CSRF_TOKEN=$(openssl rand -hex 16)
|
|
34
|
+
```
|
|
35
|
+
Then run:
|
|
36
|
+
```bash
|
|
37
|
+
python tw2img.py 2054583770045386950
|
|
38
|
+
```
|
|
39
|
+
**Where to find tokens:** Open browser devtools, network tab, any x.com request, select cookies tab `auth_token` and `ct0`
|
|
40
|
+
## Basic Options
|
|
41
|
+
| Option | Description |
|
|
42
|
+
|--------|-------------|
|
|
43
|
+
| `@user` | Fetch latest tweet from this user |
|
|
44
|
+
| `--user <name>` | Same as above |
|
|
45
|
+
| `--light` | Use light theme (default is dark) |
|
|
46
|
+
| `--no-source` | Hide the "Twitter for iPhone" source text |
|
|
47
|
+
| `--no-context` | Show only the focal tweet, no thread/replies |
|
|
48
|
+
| `--no-retina` | Disable 2x retina rendering (smaller file) |
|
|
49
|
+
| `--full-stats` | Show full numbers instead of abbreviated (e.g. 12,345 instead of 12.3K) |
|
|
50
|
+
| `--output-dir <path>` | Directory to save output PNG (default: current working directory) |
|
|
51
|
+
| `--width 800` | Set output width in pixels (default: 598) |
|
|
52
|
+
| `--css theme.css` | File to override the theme (ex: nitter/public/css/themes/pleroma.css) |
|
|
53
|
+
| `--nitter` | Use Nitter default theme |
|
|
54
|
+
| `--html-only` | Print HTML to stdout instead of rendering PNG |
|
|
55
|
+
| `--save-html` | Save HTML to this file instead of rendering PNG |
|
|
56
|
+
| `--imgur` | Upload PNG to imgur after rendering |
|
|
57
|
+
| `--dump-json` | Print raw API JSON to stdout and exit |
|
|
58
|
+
| `--view` | Automatically open the rendered output file after creation |
|
|
59
|
+
| `--viewer <cmd>` | Specify custom viewer executable/command (e.g., `viewnior`, `firefox`, or `kitty +icat {}`) |
|
|
60
|
+
| `-c <file>` | Load config from a custom path (see Config below) |
|
|
61
|
+
## Config File
|
|
62
|
+
Options can be set as persistent defaults in a config file (INI format). Config is loaded in this order - later sources override earlier ones:
|
|
63
|
+
|
|
64
|
+
1. `~/.config/tw2img/tw2img.conf` - user default
|
|
65
|
+
2. `<script_dir>/tw2img.conf` - next to the script, if present
|
|
66
|
+
3. `-c /path/to/custom.conf` - explicit override
|
|
67
|
+
4. Command options / flags always have highest priority
|
|
68
|
+
|
|
69
|
+
A default config is included as `tw2img.conf`. To install it:
|
|
70
|
+
```bash
|
|
71
|
+
mkdir -p ~/.config/tw2img
|
|
72
|
+
cp tw2img.conf ~/.config/tw2img/tw2img.conf
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Set a default download directory in the config so you don't have to specify it each run:
|
|
76
|
+
```ini
|
|
77
|
+
[tw2img]
|
|
78
|
+
output_dir = ~/Pictures/tweets
|
|
79
|
+
```
|
|
80
|
+
If `output_dir` is set, all PNGs are saved there unless you pass an explicit output path (absolute or with a directory component) on the command line.
|
|
81
|
+
|
|
82
|
+
Use `-c` to load an alternate config for a specific run without touching your defaults:
|
|
83
|
+
```bash
|
|
84
|
+
python tw2img.py 2054583770045386950 -c ~/work/tw2img-work.conf --light
|
|
85
|
+
```
|
|
86
|
+
## Input Types
|
|
87
|
+
```bash
|
|
88
|
+
# @username shorthand - latest tweet
|
|
89
|
+
python tw2img.py @NASA --guest
|
|
90
|
+
|
|
91
|
+
# @username shorthand - Nth most recent tweet (1-20, skips RTs and replies)
|
|
92
|
+
python tw2img.py @NASA 5 --guest
|
|
93
|
+
|
|
94
|
+
# Explicit --user flag (equivalent to @username)
|
|
95
|
+
python tw2img.py --user NASA --guest
|
|
96
|
+
|
|
97
|
+
# Tweet ID
|
|
98
|
+
python tw2img.py 2054583770045386950 --guest
|
|
99
|
+
|
|
100
|
+
# Full URL
|
|
101
|
+
python tw2img.py "https://x.com/username/status/123456789" --guest
|
|
102
|
+
|
|
103
|
+
# Local JSON file (from API)
|
|
104
|
+
python tw2img.py tweet.json
|
|
105
|
+
|
|
106
|
+
# Stdin (pipe JSON)
|
|
107
|
+
cat tweet.json | python tw2img.py -
|
|
108
|
+
```
|
|
109
|
+
## Output
|
|
110
|
+
By default, saves as `<screen_name>-<tweet_id>.png` in current directory. Specify a custom filename as the argument after the input (or after the tweet index when using `@username`):
|
|
111
|
+
```bash
|
|
112
|
+
# Custom output with tweet ID
|
|
113
|
+
python tw2img.py 2054583770045386950 --guest my_screenshot.png
|
|
114
|
+
|
|
115
|
+
# Custom output with @username shorthand
|
|
116
|
+
python tw2img.py @NASA my_screenshot.png --guest
|
|
117
|
+
|
|
118
|
+
# Custom output with @username and tweet index
|
|
119
|
+
python tw2img.py @NASA 3 my_screenshot.png --guest
|
|
120
|
+
|
|
121
|
+
# Open with a specific GUI viewer
|
|
122
|
+
python tw2img.py @NASA --guest --view --viewer viewnior
|
|
123
|
+
|
|
124
|
+
# Render directly inline inside a supported terminal (like kitty)
|
|
125
|
+
python tw2img.py @NASA --guest --view --viewer "kitty +icat {}"
|
|
126
|
+
|
|
127
|
+
# View directly in Firefox (ideal when combined with --save-html)
|
|
128
|
+
python tw2img.py 2054583770045386950 --save-html tweet.html --view --viewer firefox
|
|
129
|
+
```
|
|
130
|
+
## Examples
|
|
131
|
+
**Basic screenshot with thread (dark mode):**
|
|
132
|
+
```bash
|
|
133
|
+
python tw2img.py 2054583770045386950 --guest
|
|
134
|
+
```
|
|
135
|
+
**Latest tweet from a user:**
|
|
136
|
+
```bash
|
|
137
|
+
python tw2img.py @NASA --guest
|
|
138
|
+
```
|
|
139
|
+
**5th most recent tweet from a user:**
|
|
140
|
+
```bash
|
|
141
|
+
python tw2img.py @NASA 5 --guest
|
|
142
|
+
```
|
|
143
|
+
**Automatically open the snapshot after rendering:**
|
|
144
|
+
```bash
|
|
145
|
+
python tw2img.py @NASA --guest --view
|
|
146
|
+
```
|
|
147
|
+
**Upload to imgur**
|
|
148
|
+
```bash
|
|
149
|
+
python tw2img.py @NASA --guest --imgur
|
|
150
|
+
```
|
|
151
|
+
**Light theme, focal tweet only:**
|
|
152
|
+
```bash
|
|
153
|
+
python tw2img.py 2054583770045386950 --guest --light --no-context
|
|
154
|
+
```
|
|
155
|
+
**Wide screenshot without source:**
|
|
156
|
+
```bash
|
|
157
|
+
python tw2img.py 2054583770045386950 --guest --width 800 --no-source
|
|
158
|
+
```
|
|
159
|
+
**Full stat numbers:**
|
|
160
|
+
```bash
|
|
161
|
+
python tw2img.py 2054583770045386950 --guest --full-stats
|
|
162
|
+
```
|
|
163
|
+
**Print HTML to stdout (for inspection or debugging)**
|
|
164
|
+
```bash
|
|
165
|
+
python tw2img.py 2054583770045386950 --guest --html-only
|
|
166
|
+
```
|
|
167
|
+
**Save HTML to a file**
|
|
168
|
+
```bash
|
|
169
|
+
python tw2img.py 2054583770045386950 --guest --save-html tweet.html
|
|
170
|
+
```
|
|
171
|
+
**Save HTML to a file and load in Firefox**
|
|
172
|
+
```bash
|
|
173
|
+
python tw2img.py --guest @barackobama --full-stats --save-html /tmp/tweet.html && firefox /tmp/tweet.html
|
|
174
|
+
```
|
|
175
|
+
## Articles
|
|
176
|
+
|
|
177
|
+
**Save article and auto-load rendered HTML in Firefox**
|
|
178
|
+
```bash
|
|
179
|
+
# BEST METHOD: Save as HTML and open (uses article_viewer from conf, or xdg-open)
|
|
180
|
+
# Use the tweet url that contains the article link (or simply just the id)
|
|
181
|
+
python article2img.py --guest --save-html out.html --view https://x.com/ARCRaidersGame/status/2054607629738037736
|
|
182
|
+
# Simplify with an alias
|
|
183
|
+
alias tw-article='article2img --guest --save-html /tmp/out.html --view > /dev/null'
|
|
184
|
+
tw-article https://n/XDevelopers/status/2041295840325636551
|
|
185
|
+
```
|