X Post Review Queue: scheduled X posts with a Discord review window
$5
X Post Review Queue is a small Python tool for posting to X on a schedule without giving up the last look. You keep a queue of posts in a local file. Before each one is published, you get a Discord...
Read full descriptionDescription
X Post Review Queue is a small Python tool for posting to X on a schedule without giving up the last look. You keep a queue of posts in a local file. Before each one is published, you get a Discord message with the exact text and the exact time it will go out. Cancel it with one command (or by creating a single file). If you do nothing, it posts on schedule through the X API v2.
How it works
propose(run on your schedule, for example weekdays at 9:00) takes the next post and starts a review window, 30 minutes by default, and notifies Discord.execute(run every 15 minutes from cron or launchd) publishes the post once the window has passed, unless it was cancelled.add,status,cancel, andresolvehandle the rest.
Built to be trusted with your account
- Never double-posts. The attempt is saved before X is called. If a run is killed mid-post or the outcome is unclear, it is flagged for you to check and never retried blindly.
- No notice, no post. If the Discord message fails, the post is held and not published.
- Length checks by X's rules: 280 weighted characters, links counted as 23.
- Fails loudly: missing credentials or webhook stop the command with a clear error. It never posts without credentials.
- Overlap-safe: atomic state writes and a lock file, so overlapping scheduler runs can't collide.
- Late-run expiry: a post whose time passed long ago (say, the laptop was asleep) expires instead of going out at a strange hour.
Example Discord notice
Scheduled for X at Tue Oct 21, 3:45 PM EDT (in 30 min)
New in v2.3: export your reports as CSV. Changelog: https://example.com/changelog
75/280 characters, id a1
To cancel, before then: run `python -m x_post_review_queue cancel` or create the cancel-flag fileWho it's for
Indie developers, small teams, and solo founders who want posts to go out on a schedule but always want a last chance to stop them, and who are comfortable running a Python script from cron or launchd.
Requirements
- Python 3.9+ on macOS or Linux (Windows works with Task Scheduler)
- Your own X developer app with Read and Write permission and OAuth 1.0a keys
- A Discord webhook
- Two Python packages: requests and requests-oauthlib
X API access is not included. X sets its own API access tiers, limits, and prices, and may charge per post or per request. Arranging API access and paying any API fees is your responsibility. Check X's current developer pricing before scheduling.
What's included
About 800 lines of readable Python, a README with step-by-step setup and copy-paste cron and launchd examples, an example config and .env, and 40 offline tests with the X API and Discord mocked.
Text-only posts. Not affiliated with or endorsed by X Corp. or Discord Inc.
Files included
x-post-review-queuex-post-review-queue
teststests
- test_queue.pytest_queue.py16.2 KB
x_post_review_queuex_post_review_queue
- core.pycore.py15.5 KB
- config.pyconfig.py4.1 KB
- __main__.py__main__.py2.7 KB
- x_api.pyx_api.py2.2 KB
- store.pystore.py2.2 KB
- text.pytext.py1.9 KB
- notify.pynotify.py842 B
- __init__.py__init__.py104 B
- README.mdREADME.md11.2 KB
- CHANGELOG.mdCHANGELOG.md819 B
- config.example.jsonconfig.example.json365 B
- .env.example.env.example294 B
- requirements.txtrequirements.txt75 B
- .gitignore.gitignore57 B
README
x-post-review-queue/README.md
X Post Review Queue
Schedule X (Twitter) posts from a local queue file, with a review window before anything goes out. Each post is announced in Discord with its exact text and the time it will be published. If you don't like it, cancel it. If you do nothing, it posts on schedule.
X has no "draft, then publish later" flow in its API. This tool supplies one with two small commands run by your scheduler:
proposetakes the next post from the queue, starts its review window (30 minutes by default), and sends a Discord message with the exact text and the scheduled time.executeruns every ~15 minutes. Once the window has passed, it posts through the X API v2, unless the post was cancelled.
Cancelling is one command (cancel), or simply creating an empty file at the cancel-flag
path. That works from anything that can create a file, such as an SSH session from your
phone or a synced folder.
It also has:
- No double posts. The attempt is written to disk before X is called. If a run is killed mid-post, the next run does not guess. It flags the post for you to check. Details below.
- No post without a notification. If the Discord message fails, the post is held and never published until a notice gets through.
- Length checks by X's rules. 280 weighted characters, with every link counted as 23, checked when you add a post and again before it is sent.
- Overlap-safe scheduling. A lock stops two runs from acting on the same post, and all state files are written atomically.
- Loud failures. Missing credentials stop the command with a clear error (exit code 2). It never posts without them and never pretends nothing was due.
- A small codebase: about 800 lines of Python, two dependencies, and 40 offline tests.
You supply the posts. Nothing is generated for you.
What it looks like
A queue file (queue.json). Use add, or edit it by hand while no run is active:
[
{"id": "a1", "text": "New in v2.3: export your reports as CSV. Changelog: https://example.com/changelog"},
{"id": "a2", "text": "Tip: press / anywhere in the app to jump straight to search."},
"Plain strings work too. An id is assigned when the post is proposed."
]The Discord message propose sends:
Scheduled for X at Tue Oct 21, 3:45 PM EDT (in 30 min)
New in v2.3: export your reports as CSV. Changelog: https://example.com/changelog
75/280 characters, id a1
To cancel, before then: run `python -m x_post_review_queue cancel` or create the file
`/home/you/.config/x-post-review-queue/cancel.flag`After it posts:
Posted a1: https://x.com/i/web/status/1849000000000000000Requirements
- macOS or Linux with Python 3.9+ (Windows works, with Task Scheduler instead of cron)
- An X developer account and an app with Read and Write permission, plus the four OAuth 1.0a keys for the account you post as (step 2)
- A Discord server where you can create a webhook
About X API access and cost: posting through the X API requires API access that you arrange directly with X. X sets the access tiers, usage limits, and prices, changes them from time to time, and may charge per post or per request. Check X's current developer pricing before you schedule anything. Any API fees are your responsibility, and this product does not include API access.
Setup (about 15 minutes)
1. Install
pip install -r requirements.txt
cp config.example.json config.json
cp .env.example .env2. Create X API credentials
- Sign in to the X developer portal with the account you want to post from, and create a project and app.
- In the app's User authentication settings, set app permissions to Read and write. Do this before generating access tokens. Tokens made under read-only permission stay read-only.
- Under Keys and tokens, copy the API Key and Secret (consumer keys) and generate an Access Token and Secret for your account.
- Put all four in
.env:
X_API_KEY=...
X_API_SECRET=...
X_ACCESS_TOKEN=...
X_ACCESS_TOKEN_SECRET=...Real environment variables take priority over .env. .env is read from the folder you run
the command in and from the folder holding config.json. Treat these values like a password:
they can post as you.
3. Create a Discord webhook
In Discord, open Server Settings, Integrations, Webhooks, New Webhook, pick a channel,
copy the URL, and set DISCORD_WEBHOOK_URL in .env (or discord_webhook_url in
config.json). propose refuses to run without a webhook, because a review window you aren't
told about isn't a review window.
4. Add posts and try it
python -m x_post_review_queue add "My first scheduled post"
python -m x_post_review_queue add --file long-post.txt # multi-line posts
python -m x_post_review_queue status
python -m x_post_review_queue propose # check Discord
python -m x_post_review_queue execute # "in its review window (30 min left)"To try the flow without posting, set "review_minutes": 1, run propose, then cancel.
Commands
| Command | What it does |
|---|---|
add TEXT / add --file PATH | Append a post to the queue (--file - reads stdin). Rejects posts over 280. |
propose | Move the next queued post into its review window and notify Discord. Does nothing if a post is already pending or the queue is empty. |
execute | Post the pending post if its window has passed and it wasn't cancelled. Otherwise does nothing. Safe to run as often as you like. |
status | Queue size, the pending post and its time, the last 5 outcomes, and whether credentials and webhook are set. |
cancel | Cancel the pending post now. Creating the cancel-flag file does the same on the next execute. |
resolve posted / resolve not-posted | Settle a post whose outcome is unknown (see below). not-posted posts it on the next execute. |
Global options: --config PATH (default ./config.json) and --env-file PATH (default ./.env).
Exit codes: 0 OK or nothing to do, 1 a post failed or needs attention, 2 config or
credentials error.
Configuration
All keys are optional. Unknown keys are rejected so typos don't fail silently. Relative paths
are resolved from the folder holding config.json.
| Key | Default | What it does |
|---|---|---|
queue_file | ~/.config/x-post-review-queue/queue.json | Posts waiting to be proposed. |
state_file | ~/.config/x-post-review-queue/state.json | The pending post and the outcome history. |
cancel_flag | ~/.config/x-post-review-queue/cancel.flag | If this file exists, the pending post is cancelled. |
review_minutes | 30 | Time between the Discord notice and the post. |
max_late_minutes | 720 | If execute first runs this long after the scheduled time (say, the laptop was asleep), the post expires instead of going out late. 0 = no limit. |
max_attempts | 3 | Retries when X clearly rejects a post (for example, a rate limit). |
timezone | UTC | IANA name (America/New_York) for times shown in messages. |
discord_webhook_url | Env DISCORD_WEBHOOK_URL takes priority. Required for propose. | |
discord_username | X Post Review Queue | Name shown on the Discord messages. |
x_api_url | https://api.x.com/2/tweets | The create-post endpoint. |
Run it automatically
Pick when posts should be proposed (for example, weekdays at 9:00), and run execute every
15 minutes. With a 30-minute window, posts go out 30 to 45 minutes after they are proposed.
cron (macOS or Linux). Run crontab -e and add the following, with your own paths. Cron
has a minimal environment, so use full paths. The .env file next to config.json is
picked up automatically.
0 9 * * 1-5 cd /path/to/x-post-review-queue && /usr/bin/python3 -m x_post_review_queue propose >> run.log 2>&1
*/15 * * * * cd /path/to/x-post-review-queue && /usr/bin/python3 -m x_post_review_queue execute >> run.log 2>&1launchd (macOS). Save as ~/Library/LaunchAgents/local.x-post-review-queue.execute.plist,
then run launchctl load ~/Library/LaunchAgents/local.x-post-review-queue.execute.plist.
Make a second copy with propose and a StartCalendarInterval (for example Hour 9,
Minute 0) instead of StartInterval.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>local.x-post-review-queue.execute</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>-m</string>
<string>x_post_review_queue</string>
<string>execute</string>
</array>
<key>WorkingDirectory</key><string>/path/to/x-post-review-queue</string>
<key>StartInterval</key><integer>900</integer>
<key>StandardOutPath</key><string>/path/to/x-post-review-queue/run.log</string>
<key>StandardErrorPath</key><string>/path/to/x-post-review-queue/run.log</string>
</dict>
</plist>Unlike cron, launchd runs a missed interval when the Mac wakes up. max_late_minutes
decides whether a post that is very late still goes out.
How it avoids double posts
Before calling X, execute saves the post as posting. What happens next:
- X confirms (201 with a post id): recorded as posted, done.
- X clearly refuses (any 4xx, or the connection never opened): nothing was created. The
post returns to
pendingand is retried on the next run, up tomax_attempts. - Anything unclear (timeout after sending, dropped connection, 5xx, the process killed
mid-call): the post becomes
unknownand is not retried. You get a Discord message asking you to check your profile, then runresolve postedorresolve not-posted.
The tool chooses "at most once." A rare unclear failure costs you a manual check. It never
costs you a duplicate post. Overlapping runs are serialized by a lock file next to
state_file.
Limitations
- Text-only posts. No images, video, polls, replies, or threads.
- One post at a time. Each
proposehandles one post. Schedule it as often as you want posts to go out. - The length check is close to X's, but not exact. Links count as 23 and CJK characters and emoji as 2, matching X's rules. Some multi-part emoji are counted higher than X counts them, so a post right at 280 can be rejected here and need a small trim. X's API decides in the end.
- Your computer has to be on. It's a local tool. A sleeping laptop delays
execute(seemax_late_minutes). - Cancel is per post. Cancelling drops the pending post. Other queued posts are not affected.
- X's API, limits, and pricing can change at any time, outside this tool's control.
Tests
pip install pytest && python -m pytest testsThe tests are fully mocked (X API and Discord) and need no accounts or network.
Disclaimer
This software is provided "as is", without warranty of any kind. You run it with your own X and Discord credentials and are responsible for what is posted, for following X's rules and developer terms, and for any API costs. The author is not liable for missed, delayed, or unintended posts, API charges, account restrictions, or any resulting loss.
Not affiliated with or endorsed by X Corp. or Discord Inc. X is a trademark of X Corp.
Reviews
No reviews