Spaces:
Running
Running
Download pmct/post.py from sharpflowapp/web: direct link, hf CLI and curl.
- Browser
- Download file 5.01 kB
-
https://huggingface.co/spaces/sharpflowapp/web/resolve/main/pmct/post.py
- Command line
-
hf download hf://spaces/sharpflowapp/web/pmct/post.py
-
curl -L -o post.py https://huggingface.co/spaces/sharpflowapp/web/resolve/main/pmct/post.py
5.01 kB
| """Turn a digest run into ready-to-post distribution assets. | |
| The product's bottleneck is distribution, not code. This module converts the | |
| same digest data into: | |
| - an X / Twitter thread (list of <=280-char tweets), and | |
| - a dark-theme PNG card of the top moves (for the first tweet). | |
| Posting itself needs a human-owned account (or API keys) β this just produces | |
| the assets so posting is one copy-paste / one API call away. | |
| """ | |
| from __future__ import annotations | |
| from pathlib import Path | |
| import pandas as pd | |
| from .digest import Move | |
| TWEET_LIMIT = 280 | |
| def _short(w: str) -> str: | |
| return f"{w[:6]}β¦{w[-4:]}" | |
| def x_thread(selected: pd.DataFrame, moves: list[Move], hours: int, | |
| site_url: str = "") -> list[str]: | |
| """Compose the thread. Tweet 1 = hook, then top moves, then CTA.""" | |
| n_traders = len(selected) | |
| hook = ( | |
| f"π Consistent Polymarket smart-money β last {hours}h\n\n" | |
| f"The {n_traders} mid-size traders whale trackers ignore " | |
| f"(too small to flag) β and their highest-conviction moves right now.\n\n" | |
| f"A thread π§΅" | |
| ) | |
| tweets = [hook] | |
| # diversify: best move per wallet first, so the thread isn't 5 near-dupes | |
| seen: set[str] = set() | |
| diverse = [m for m in moves if not (m.wallet in seen or seen.add(m.wallet))] | |
| if len(diverse) < 5: | |
| diverse += [m for m in moves if m not in diverse] | |
| for i, m in enumerate(diverse[:5], 1): | |
| stars = "β " * max(1, int(round(m.signal_quality * 5))) | |
| title = (m.title[:70] + "β¦") if len(m.title) > 71 else m.title | |
| t = ( | |
| f"{i}/ {stars} signal {m.signal_quality:.2f}\n" | |
| f"{_short(m.wallet)} β {title} ({m.outcome})\n" | |
| f"@ {m.price:.2f} Β· ${m.usdc:,.0f} Β· conviction {m.conviction:.0%}" | |
| ) | |
| tweets.append(t[:TWEET_LIMIT]) | |
| best = selected.head(3) | |
| lead = "Why these traders: picked for consistency (green most months) + a " | |
| lead += "repeatable style, NOT size. Sample of who we track:\n\n" | |
| lead += "\n".join( | |
| f"β’ {_short(r['wallet'])} β score {r['trader_score']:.2f}, " | |
| f"{float(r.get('monthly_profit_ratio',0)):.0%} green months" | |
| for _, r in best.iterrows() | |
| ) | |
| tweets.append(lead[:TWEET_LIMIT]) | |
| cta = "Score ANY Polymarket wallet free β consistent, whale, market-maker, " | |
| cta += "or just lucky?" | |
| if site_url: | |
| cta += f"\n\n{site_url}" | |
| cta += "\n\nFlow intelligence, not financial advice." | |
| tweets.append(cta[:TWEET_LIMIT]) | |
| return tweets | |
| def table_png(moves: list[Move], out: Path, hours: int) -> Path | None: | |
| """Render the top moves as a shareable dark card. Returns path or None.""" | |
| if not moves: | |
| return None | |
| try: | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| except Exception: | |
| return None | |
| # one clean row per wallet β no duplicate padding, so the card never shows | |
| # the same trader three times when only a few distinct wallets are active | |
| seen: set[str] = set() | |
| top = [m for m in moves if not (m.wallet in seen or seen.add(m.wallet))][:8] | |
| bg, ink, mut, acc = "#0b0e14", "#e6edf3", "#8b98a9", "#3fb950" | |
| n = len(top) | |
| fig, ax = plt.subplots(figsize=(10, 1.6 + 0.5 * n)) | |
| fig.patch.set_facecolor(bg) | |
| ax.set_facecolor(bg) | |
| ax.axis("off") | |
| ax.text(0.02, 0.97, "β SharpFlow", color=acc, fontsize=17, fontweight="bold", | |
| transform=ax.transAxes, va="top") | |
| ax.text(0.02, 0.86, f"Consistent smart-money β top moves, last {hours}h", | |
| color=ink, fontsize=13, transform=ax.transAxes, va="top") | |
| y_hdr = 0.70 | |
| ax.text(0.02, y_hdr, "SIGNAL", color=mut, fontsize=9, transform=ax.transAxes) | |
| ax.text(0.16, y_hdr, "TRADER", color=mut, fontsize=9, transform=ax.transAxes) | |
| ax.text(0.34, y_hdr, "MOVE", color=mut, fontsize=9, transform=ax.transAxes) | |
| ax.text(0.82, y_hdr, "SIZE", color=mut, fontsize=9, transform=ax.transAxes) | |
| y_top, y_bot = 0.62, 0.10 | |
| step = (y_top - y_bot) / max(1, n - 1) if n > 1 else 0.0 | |
| for i, m in enumerate(top): | |
| y = y_top - i * step | |
| bar = "β" * max(1, int(round(m.signal_quality * 5))) | |
| ax.text(0.02, y, f"{bar} {m.signal_quality:.2f}", color=acc, fontsize=10, | |
| transform=ax.transAxes, family="monospace") | |
| ax.text(0.16, y, _short(m.wallet), color=ink, fontsize=10, | |
| transform=ax.transAxes, family="monospace") | |
| title = (m.title[:34] + "β¦") if len(m.title) > 35 else m.title | |
| ax.text(0.34, y, f"{title} ({m.outcome[:12]})", color=ink, fontsize=10, | |
| transform=ax.transAxes) | |
| ax.text(0.82, y, f"${m.usdc:,.0f}", color=ink, fontsize=10, | |
| transform=ax.transAxes) | |
| ax.text(0.02, 0.02, "Flow intelligence, not financial advice Β· sharpflow", | |
| color=mut, fontsize=8, transform=ax.transAxes) | |
| fig.savefig(out, dpi=150, facecolor=bg, pad_inches=0) | |
| plt.close(fig) | |
| return out | |