socialcli 0.3.0__py3-none-any.whl
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.
Potentially problematic release.
This version of socialcli might be problematic. Click here for more details.
- socialcli-0.3.0.dist-info/METADATA +168 -0
- socialcli-0.3.0.dist-info/RECORD +224 -0
- socialcli-0.3.0.dist-info/WHEEL +4 -0
- socialcli-0.3.0.dist-info/entry_points.txt +3 -0
- socialcli-0.3.0.dist-info/licenses/LICENSE +21 -0
- socialctl/__init__.py +0 -0
- socialctl/__main__.py +6 -0
- socialctl/adapters/__init__.py +6 -0
- socialctl/adapters/base.py +68 -0
- socialctl/adapters/errores.py +56 -0
- socialctl/adapters/facebook.py +180 -0
- socialctl/adapters/instagram.py +442 -0
- socialctl/adapters/tiktok.py +535 -0
- socialctl/adapters/youtube.py +331 -0
- socialctl/agent_errors.py +176 -0
- socialctl/agent_guide.py +23 -0
- socialctl/approval_cli.py +27 -0
- socialctl/auth.py +139 -0
- socialctl/authflow.py +344 -0
- socialctl/brands.py +194 -0
- socialctl/capabilities.py +57 -0
- socialctl/capabilities.yml +5945 -0
- socialctl/cli.py +1766 -0
- socialctl/connection_service/__init__.py +0 -0
- socialctl/connection_service/__main__.py +33 -0
- socialctl/connection_service/app.py +496 -0
- socialctl/connection_service/assets/PLATFORM-LOGOS-LICENSE.txt +50 -0
- socialctl/connection_service/assets/connection.css +75 -0
- socialctl/connection_service/assets/facebook.webp +0 -0
- socialctl/connection_service/assets/instagram.svg +194 -0
- socialctl/connection_service/assets/socialcli-logo.png +0 -0
- socialctl/connection_service/assets/tiktok.png +0 -0
- socialctl/connection_service/assets/youtube.svg +1 -0
- socialctl/connection_service/landing.py +146 -0
- socialctl/connection_service/legacy.py +48 -0
- socialctl/connection_service/peer.py +13 -0
- socialctl/connection_service/providers.py +324 -0
- socialctl/connection_service/settings.py +76 -0
- socialctl/connection_service/store.py +124 -0
- socialctl/connections/__init__.py +0 -0
- socialctl/connections/account_cli.py +438 -0
- socialctl/connections/cli.py +379 -0
- socialctl/connections/client.py +126 -0
- socialctl/connections/credential_cli.py +224 -0
- socialctl/connections/credential_store.py +49 -0
- socialctl/connections/file_store.py +193 -0
- socialctl/connections/keychain.py +78 -0
- socialctl/connections/meta_user.py +81 -0
- socialctl/connections/rotation_cli.py +116 -0
- socialctl/connections/saas_client.py +91 -0
- socialctl/connections/temporary_media.py +62 -0
- socialctl/delivery_options.py +70 -0
- socialctl/engagement.py +200 -0
- socialctl/engagement_cli.py +50 -0
- socialctl/executor.py +135 -0
- socialctl/formatter.py +291 -0
- socialctl/hosted_media.py +152 -0
- socialctl/identity.py +200 -0
- socialctl/inbox.py +298 -0
- socialctl/inbox_cli.py +46 -0
- socialctl/inventory.py +155 -0
- socialctl/inventory_cli.py +171 -0
- socialctl/inventory_sources.py +101 -0
- socialctl/management/__init__.py +1 -0
- socialctl/management/batch_cli.py +115 -0
- socialctl/management/batches.py +325 -0
- socialctl/management/changes.py +485 -0
- socialctl/management/cli.py +227 -0
- socialctl/management/comments_cli.py +352 -0
- socialctl/management/community_batch_cli.py +63 -0
- socialctl/management/community_batches.py +294 -0
- socialctl/management/community_changes.py +370 -0
- socialctl/management/community_cli.py +142 -0
- socialctl/management/community_schema.py +119 -0
- socialctl/management/facebook_groups.py +1118 -0
- socialctl/management/groups_cli.py +274 -0
- socialctl/management/inbox_readers.py +87 -0
- socialctl/management/meta_changes.py +197 -0
- socialctl/management/meta_cli.py +342 -0
- socialctl/management/meta_client.py +631 -0
- socialctl/management/meta_comment_inbox.py +565 -0
- socialctl/management/meta_comments.py +587 -0
- socialctl/management/meta_errors.py +59 -0
- socialctl/management/meta_pagination.py +52 -0
- socialctl/management/meta_schema.py +128 -0
- socialctl/management/meta_webhooks.py +147 -0
- socialctl/management/metadata_parts.py +144 -0
- socialctl/management/owned_assets.py +85 -0
- socialctl/management/owned_changes.py +470 -0
- socialctl/management/owned_cli.py +128 -0
- socialctl/management/owned_reorder.py +62 -0
- socialctl/management/owned_schema.py +368 -0
- socialctl/management/reply_context.py +24 -0
- socialctl/management/reply_evidence.py +80 -0
- socialctl/management/resource_changes.py +407 -0
- socialctl/management/resource_cli.py +136 -0
- socialctl/management/snippet_readback.py +26 -0
- socialctl/management/stories.py +713 -0
- socialctl/management/stories_cli.py +172 -0
- socialctl/management/youtube.py +323 -0
- socialctl/management/youtube_community.py +326 -0
- socialctl/management/youtube_metadata.py +122 -0
- socialctl/management/youtube_owned.py +259 -0
- socialctl/management/youtube_resources.py +305 -0
- socialctl/media.py +269 -0
- socialctl/media_cli.py +183 -0
- socialctl/media_ingress.py +211 -0
- socialctl/media_preflight.py +114 -0
- socialctl/media_registry.py +301 -0
- socialctl/media_requirements.py +52 -0
- socialctl/metricas/__init__.py +6 -0
- socialctl/metricas/almacen.py +133 -0
- socialctl/metricas/analytics_changes.py +295 -0
- socialctl/metricas/analytics_cli.py +191 -0
- socialctl/metricas/analytics_client.py +304 -0
- socialctl/metricas/analytics_ingest.py +260 -0
- socialctl/metricas/analytics_schema.py +174 -0
- socialctl/metricas/base.py +147 -0
- socialctl/metricas/facebook.py +418 -0
- socialctl/metricas/insights.py +227 -0
- socialctl/metricas/instagram.py +133 -0
- socialctl/metricas/modelos.py +87 -0
- socialctl/metricas/piezas.py +134 -0
- socialctl/metricas/reach.py +94 -0
- socialctl/metricas/reporting_client.py +112 -0
- socialctl/metricas/resumen.py +251 -0
- socialctl/metricas/slugs.py +89 -0
- socialctl/metricas/tiktok.py +185 -0
- socialctl/metricas/youtube.py +403 -0
- socialctl/migration_cli.py +60 -0
- socialctl/migration_files.py +68 -0
- socialctl/models.py +150 -0
- socialctl/native_schedule/__init__.py +13 -0
- socialctl/native_schedule/api_delivery.py +15 -0
- socialctl/native_schedule/api_reconcile.py +40 -0
- socialctl/native_schedule/approval.py +160 -0
- socialctl/native_schedule/cadence.py +73 -0
- socialctl/native_schedule/cli.py +510 -0
- socialctl/native_schedule/dispatcher.py +120 -0
- socialctl/native_schedule/facebook.py +112 -0
- socialctl/native_schedule/facebook_reels.py +140 -0
- socialctl/native_schedule/first_comment.py +181 -0
- socialctl/native_schedule/handoff.py +193 -0
- socialctl/native_schedule/instagram_delivery.py +224 -0
- socialctl/native_schedule/instagram_runtime.py +66 -0
- socialctl/native_schedule/inventory.py +70 -0
- socialctl/native_schedule/migration.py +310 -0
- socialctl/native_schedule/models.py +103 -0
- socialctl/native_schedule/reconcile.py +83 -0
- socialctl/native_schedule/remote_data.py +177 -0
- socialctl/native_schedule/report.py +151 -0
- socialctl/native_schedule/store.py +560 -0
- socialctl/native_schedule/verification.py +32 -0
- socialctl/native_schedule/youtube.py +339 -0
- socialctl/operation_output.py +87 -0
- socialctl/plantillas/accounts.yml +33 -0
- socialctl/plantillas/brand.md +95 -0
- socialctl/plantillas/estrategia.md +64 -0
- socialctl/postfile.py +240 -0
- socialctl/preflight.py +73 -0
- socialctl/publication_policy.py +34 -0
- socialctl/publication_status.py +75 -0
- socialctl/publication_steps.py +398 -0
- socialctl/publish_output.py +96 -0
- socialctl/publisher.py +445 -0
- socialctl/queue_migration.py +302 -0
- socialctl/read_budget.py +224 -0
- socialctl/read_reports.py +91 -0
- socialctl/rutas.py +103 -0
- socialctl/saas/__init__.py +1 -0
- socialctl/saas/access.py +75 -0
- socialctl/saas/auth.py +213 -0
- socialctl/saas/backup.py +124 -0
- socialctl/saas/billing.py +327 -0
- socialctl/saas/billing_enrollment.py +1237 -0
- socialctl/saas/billing_enrollment_schema.py +519 -0
- socialctl/saas/billing_inventory.py +775 -0
- socialctl/saas/billing_reconcile.py +127 -0
- socialctl/saas/billing_routes.py +27 -0
- socialctl/saas/budget.py +66 -0
- socialctl/saas/connections.py +374 -0
- socialctl/saas/consent.py +52 -0
- socialctl/saas/lifecycle.py +341 -0
- socialctl/saas/mail.py +89 -0
- socialctl/saas/maintenance.py +68 -0
- socialctl/saas/meta_user.py +298 -0
- socialctl/saas/meta_webhooks.py +358 -0
- socialctl/saas/migration.py +107 -0
- socialctl/saas/models.py +8 -0
- socialctl/saas/operations.py +102 -0
- socialctl/saas/pages.py +126 -0
- socialctl/saas/pairing.py +158 -0
- socialctl/saas/permissions.py +57 -0
- socialctl/saas/reminders.py +128 -0
- socialctl/saas/renewal.py +74 -0
- socialctl/saas/restore_guard.py +229 -0
- socialctl/saas/revocation.py +97 -0
- socialctl/saas/rotation.py +114 -0
- socialctl/saas/routes.py +221 -0
- socialctl/saas/settings.py +34 -0
- socialctl/saas/store.py +106 -0
- socialctl/saas/temporary_media.py +245 -0
- socialctl/saas/webhooks.py +76 -0
- socialctl/schedule_remote.py +262 -0
- socialctl/schedule_sqlite.py +44 -0
- socialctl/scheduler.py +581 -0
- socialctl/scheduler_launchd.py +319 -0
- socialctl/scheduler_systemd.py +167 -0
- socialctl/source_links.py +119 -0
- socialctl/ui/__init__.py +1 -0
- socialctl/ui/assets/agent-manual.md +850 -0
- socialctl/ui/assets/agents.md +27 -0
- socialctl/ui/assets/components.css +20 -0
- socialctl/ui/assets/connection-layout.css +53 -0
- socialctl/ui/assets/otp.template.html +10 -0
- socialctl/ui/assets/tokens.css +1 -0
- socialctl/ui/assets/trial.template.html +11 -0
- socialctl/ui/assets/web-layout.css +38 -0
- socialctl/ui/email/otp.html +10 -0
- socialctl/ui/email/trial.html +11 -0
- socialctl/upload_consent.py +13 -0
- socialctl/workspace.py +8 -0
- socialctl/youtube_data.py +471 -0
- socialctl/youtube_data_service.py +225 -0
socialctl/postfile.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"""Read and write post.yml files."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import warnings
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import yaml
|
|
9
|
+
from pydantic import ValidationError as PydanticValidationError
|
|
10
|
+
|
|
11
|
+
from socialctl.brands import Brand
|
|
12
|
+
from socialctl.media import leer_media, ruta_relativa_efectiva
|
|
13
|
+
from socialctl.models import CampaignType, Platform, PlatformPost, Post
|
|
14
|
+
from socialctl.rutas import validar_componente_de_ruta, validar_ruta_relativa
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PostNoEncontrado(Exception):
|
|
18
|
+
"""No post.yml exists for the requested slug."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SlugInvalido(ValueError):
|
|
22
|
+
"""The post slug is not a safe single path component."""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class NombreDeMediaInvalido(ValueError):
|
|
26
|
+
"""A supplied media filename or relative path is unsafe."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class PostInvalido(ValueError):
|
|
30
|
+
"""post.yml cannot be interpreted as a Post."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _validar_slug(dir_posts: Path, slug: str) -> Path:
|
|
34
|
+
"""Validate a slug and return its directory within the posts root."""
|
|
35
|
+
return validar_componente_de_ruta(dir_posts, slug, SlugInvalido, "slug")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _validar_nombre_de_media(dir_media: Path, nombre_fichero: object) -> Path:
|
|
39
|
+
"""Validate and resolve a supplied media path, including safe subdirectories."""
|
|
40
|
+
return validar_ruta_relativa(
|
|
41
|
+
dir_media, nombre_fichero, NombreDeMediaInvalido, "media name"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _ruta(brand: Brand, slug: str) -> Path:
|
|
46
|
+
carpeta = _validar_slug(brand.dir_posts, slug)
|
|
47
|
+
return carpeta / "post.yml"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _cargar_datos(fichero: Path) -> dict:
|
|
51
|
+
"""Read and decode YAML, requiring a mapping at the root."""
|
|
52
|
+
try:
|
|
53
|
+
contenido = fichero.read_text(encoding="utf-8")
|
|
54
|
+
except OSError as exc:
|
|
55
|
+
raise PostInvalido(f"cannot read {fichero}: {exc}") from exc
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
datos = yaml.safe_load(contenido)
|
|
59
|
+
except yaml.YAMLError as exc:
|
|
60
|
+
raise PostInvalido(f"'{fichero}' is not valid YAML: {exc}") from exc
|
|
61
|
+
|
|
62
|
+
if datos is None:
|
|
63
|
+
return {}
|
|
64
|
+
|
|
65
|
+
if not isinstance(datos, dict):
|
|
66
|
+
raise PostInvalido(
|
|
67
|
+
f"'{fichero}' must contain a mapping (key: value) at the root; "
|
|
68
|
+
f"received {type(datos).__name__}"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return datos
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _construir_platform_post(
|
|
75
|
+
platform: Platform, bloque: object, dir_media: Path, fichero: Path, *, media_reader=None
|
|
76
|
+
) -> PlatformPost:
|
|
77
|
+
if not isinstance(bloque, dict):
|
|
78
|
+
raise PostInvalido(
|
|
79
|
+
f"the block for '{platform.value}' in {fichero} must be a mapping (key: value); received {type(bloque).__name__}"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
body = bloque.get("body")
|
|
83
|
+
if not isinstance(body, str):
|
|
84
|
+
raise PostInvalido(
|
|
85
|
+
f"'{platform.value}' in {fichero} has no string 'body' "
|
|
86
|
+
"(the field is missing or is not a string)"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
hashtags = bloque.get("hashtags", [])
|
|
90
|
+
if not isinstance(hashtags, list):
|
|
91
|
+
raise PostInvalido(
|
|
92
|
+
f"'hashtags' for '{platform.value}' in {fichero} must be a list; "
|
|
93
|
+
f"received {type(hashtags).__name__}"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
media_nombres = bloque.get("media", [])
|
|
97
|
+
if not isinstance(media_nombres, list):
|
|
98
|
+
raise PostInvalido(
|
|
99
|
+
f"'media' for '{platform.value}' in {fichero} must be a list; "
|
|
100
|
+
f"received {type(media_nombres).__name__}"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
media = []
|
|
104
|
+
for nombre_fichero in media_nombres:
|
|
105
|
+
ruta_absoluta = _validar_nombre_de_media(dir_media, nombre_fichero)
|
|
106
|
+
# `ruta_absoluta` ya está validada como dentro de `dir_media` (ver
|
|
107
|
+
# `_validar_nombre_de_media`), asà que recuperar aquà la ruta
|
|
108
|
+
# relativa con `relative_to` es seguro y, a la vez, normaliza el
|
|
109
|
+
# valor tal como se escribió en post.yml (p. ej. una barra doble
|
|
110
|
+
# se colapsa) para que `MediaAsset.ruta_relativa` -y quien la lea
|
|
111
|
+
# después: el preview, `guardar_post`, la URL de Instagram- vea
|
|
112
|
+
# siempre la forma canónica, con '/' como separador.
|
|
113
|
+
ruta_relativa = ruta_absoluta.relative_to(dir_media).as_posix()
|
|
114
|
+
media.append((media_reader or leer_media)(ruta_absoluta, ruta_relativa=ruta_relativa))
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
return PlatformPost(
|
|
118
|
+
platform=platform,
|
|
119
|
+
title=bloque.get("title"),
|
|
120
|
+
body=body,
|
|
121
|
+
hashtags=hashtags,
|
|
122
|
+
**({"tags": bloque["tags"]} if "tags" in bloque else {}),
|
|
123
|
+
**({"visible_hashtags": bloque["visible_hashtags"]} if "visible_hashtags" in bloque else {}),
|
|
124
|
+
media=media,
|
|
125
|
+
link=bloque.get("link"),
|
|
126
|
+
first_comment=bloque.get("first_comment"),
|
|
127
|
+
content_origin=bloque.get("content_origin"),
|
|
128
|
+
source_video_id=bloque.get("source_video_id"),
|
|
129
|
+
privacy=bloque.get("privacy"),
|
|
130
|
+
)
|
|
131
|
+
except PydanticValidationError as exc:
|
|
132
|
+
raise PostInvalido(
|
|
133
|
+
f"the block for '{platform.value}' in {fichero} is invalid: {exc}"
|
|
134
|
+
) from exc
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def cargar_post(brand: Brand, slug: str) -> Post:
|
|
138
|
+
"""Load post.yml and resolve supplied media to absolute paths with metadata."""
|
|
139
|
+
fichero = _ruta(brand, slug)
|
|
140
|
+
if not fichero.exists():
|
|
141
|
+
raise PostNoEncontrado(f"no post exists with slug '{slug}' in {fichero}")
|
|
142
|
+
|
|
143
|
+
datos = _cargar_datos(fichero)
|
|
144
|
+
|
|
145
|
+
slug_declarado = datos.get("slug")
|
|
146
|
+
if isinstance(slug_declarado, str) and slug_declarado != slug:
|
|
147
|
+
warnings.warn(
|
|
148
|
+
f"'slug' in {fichero} is {slug_declarado!r}, but does not match the actual directory name ({slug!r}); ignored because the directory name is always the source of truth",
|
|
149
|
+
stacklevel=2,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
if "platforms" not in datos:
|
|
153
|
+
raise PostInvalido(
|
|
154
|
+
f"'platforms' is missing in {fichero}: a post needs at least one platform to publish on"
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
platforms_datos = datos["platforms"]
|
|
158
|
+
if not isinstance(platforms_datos, dict):
|
|
159
|
+
raise PostInvalido(
|
|
160
|
+
f"'platforms' in {fichero} must be a mapping (key: value); "
|
|
161
|
+
f"received {type(platforms_datos).__name__}"
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
if not platforms_datos:
|
|
165
|
+
raise PostInvalido(
|
|
166
|
+
f"'platforms' in {fichero} is empty: a post needs at least one platform to publish on"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
dir_media = brand.raiz / "media"
|
|
170
|
+
platforms: dict[Platform, PlatformPost] = {}
|
|
171
|
+
for nombre, bloque in platforms_datos.items():
|
|
172
|
+
try:
|
|
173
|
+
platform = Platform(nombre)
|
|
174
|
+
except ValueError:
|
|
175
|
+
validas = ", ".join(p.value for p in Platform)
|
|
176
|
+
raise PostInvalido(
|
|
177
|
+
f"unknown platform '{nombre}' in {fichero}. Valid platforms: {validas}"
|
|
178
|
+
) from None
|
|
179
|
+
|
|
180
|
+
platforms[platform] = _construir_platform_post(platform, bloque, dir_media, fichero)
|
|
181
|
+
|
|
182
|
+
if "campaign" not in datos:
|
|
183
|
+
validas = ", ".join(c.value for c in CampaignType)
|
|
184
|
+
raise PostInvalido(
|
|
185
|
+
f"'campaign' is missing in {fichero}. Valid campaigns: {validas}"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
campaign_valor = datos["campaign"]
|
|
189
|
+
try:
|
|
190
|
+
campaign = CampaignType(campaign_valor)
|
|
191
|
+
except ValueError:
|
|
192
|
+
validas = ", ".join(c.value for c in CampaignType)
|
|
193
|
+
raise PostInvalido(
|
|
194
|
+
f'unknown campaign {campaign_valor!r} in {fichero}. Valid campaigns: {validas}'
|
|
195
|
+
) from None
|
|
196
|
+
|
|
197
|
+
try:
|
|
198
|
+
return Post(
|
|
199
|
+
slug=slug,
|
|
200
|
+
brand=brand.nombre,
|
|
201
|
+
campaign=campaign,
|
|
202
|
+
platforms=platforms,
|
|
203
|
+
)
|
|
204
|
+
except PydanticValidationError as exc:
|
|
205
|
+
raise PostInvalido(f"{fichero} is not a valid post: {exc}") from exc
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def guardar_post(brand: Brand, post: Post) -> Path:
|
|
209
|
+
"""Write post.yml from an in-memory Post."""
|
|
210
|
+
fichero = _ruta(brand, post.slug)
|
|
211
|
+
fichero.parent.mkdir(parents=True, exist_ok=True)
|
|
212
|
+
|
|
213
|
+
datos = {
|
|
214
|
+
"slug": post.slug,
|
|
215
|
+
"campaign": post.campaign.value,
|
|
216
|
+
"platforms": {
|
|
217
|
+
platform.value: {
|
|
218
|
+
**({"title": pp.title} if pp.title else {}),
|
|
219
|
+
"body": pp.body,
|
|
220
|
+
"hashtags": pp.hashtags,
|
|
221
|
+
**({"tags": pp.tags} if pp.tags is not None else {}),
|
|
222
|
+
**({"visible_hashtags": pp.visible_hashtags} if pp.visible_hashtags is not None else {}),
|
|
223
|
+
**({"content_origin": pp.content_origin} if pp.content_origin is not None else {}),
|
|
224
|
+
**({"source_video_id": pp.source_video_id} if pp.source_video_id is not None else {}),
|
|
225
|
+
"media": [ruta_relativa_efectiva(asset) for asset in pp.media],
|
|
226
|
+
**({"link": pp.link} if pp.link else {}),
|
|
227
|
+
**({"first_comment": pp.first_comment} if pp.first_comment else {}),
|
|
228
|
+
**({"privacy": pp.privacy} if pp.privacy else {}),
|
|
229
|
+
}
|
|
230
|
+
for platform, pp in post.platforms.items()
|
|
231
|
+
},
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
comentario = (
|
|
235
|
+
"# 'slug' is informational and ignored when loading.\n"
|
|
236
|
+
"# The containing directory determines the slug; editing this value has no effect.\n"
|
|
237
|
+
)
|
|
238
|
+
contenido = yaml.safe_dump(datos, allow_unicode=True, sort_keys=False)
|
|
239
|
+
fichero.write_text(comentario + contenido, encoding="utf-8")
|
|
240
|
+
return fichero
|
socialctl/preflight.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Read-only local checks reused by doctor, without credential repair or media edits."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from socialctl.models import Platform
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def credential_status(brand):
|
|
8
|
+
from socialctl.connections.credential_store import configuration_path, store_for
|
|
9
|
+
from socialctl.connections.file_store import EncryptedFileStore, protected_parent
|
|
10
|
+
result = {'backend': 'not_required', 'available': True, 'failure_class': None}
|
|
11
|
+
try:
|
|
12
|
+
if not configuration_path(brand).exists() and not any(
|
|
13
|
+
brand.leer_secreto(p).get('auth_mode') == 'broker' for p in Platform
|
|
14
|
+
):
|
|
15
|
+
return result
|
|
16
|
+
store = store_for(brand)
|
|
17
|
+
result['backend'] = 'encrypted-file' if isinstance(store, EncryptedFileStore) else 'keyring'
|
|
18
|
+
if isinstance(store, EncryptedFileStore):
|
|
19
|
+
cipher = store.cipher()
|
|
20
|
+
# No lock-file creation, claim, migration, rotation or credential renewal.
|
|
21
|
+
with protected_parent(store.path) as (parent, name):
|
|
22
|
+
store.bind_data(store._load(parent, name, cipher), brand)
|
|
23
|
+
else:
|
|
24
|
+
store.ensure_available()
|
|
25
|
+
except (ValueError, OSError):
|
|
26
|
+
result.update(available=False, failure_class='credential_store_unavailable',
|
|
27
|
+
action='Check the selected backend, external key format, owner-only directory permissions and mode 0600 credential files. No repair was attempted.')
|
|
28
|
+
return result
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def supplied_media_status(paths):
|
|
32
|
+
from socialctl.media import leer_media, MediaInvalida, MediaNoEncontrada
|
|
33
|
+
rows = []
|
|
34
|
+
for path in paths:
|
|
35
|
+
row = {'path': str(path), 'valid': False, 'failure_class': None}
|
|
36
|
+
try:
|
|
37
|
+
asset = leer_media(Path(path))
|
|
38
|
+
row.update(valid=True, asset=asset.model_dump(mode='json'))
|
|
39
|
+
except MediaInvalida as exc:
|
|
40
|
+
row['failure_class'] = exc.code
|
|
41
|
+
except MediaNoEncontrada:
|
|
42
|
+
row['failure_class'] = 'media_missing'
|
|
43
|
+
except (ValueError, OSError):
|
|
44
|
+
row['failure_class'] = 'media_unreadable'
|
|
45
|
+
rows.append(row)
|
|
46
|
+
return rows
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def post_status(brand, slug):
|
|
50
|
+
from socialctl.media_preflight import check_post
|
|
51
|
+
if slug is None:
|
|
52
|
+
return None
|
|
53
|
+
try:
|
|
54
|
+
result = check_post(brand, slug)
|
|
55
|
+
return {**result, 'valid': result['status'] == 'passed',
|
|
56
|
+
'failure_class': None if result['status'] == 'passed' else 'post_invalid'}
|
|
57
|
+
except Exception:
|
|
58
|
+
return {'slug': slug, 'valid': False, 'failure_class': 'post_invalid',
|
|
59
|
+
'action': 'Run media check SLUG --json for detailed supplied-media validation.'}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def scope_requirements(statuses, required):
|
|
63
|
+
"""Compare exact scopes actually recorded as granted, never requested scopes."""
|
|
64
|
+
rows = []
|
|
65
|
+
for status in statuses:
|
|
66
|
+
observed = status.get('granted_scopes') or {}
|
|
67
|
+
known = observed.get('state') == 'known'
|
|
68
|
+
missing = sorted(set(required) - set(observed.get('values') or [])) if known else None
|
|
69
|
+
rows.append({'platform': status['platform'], 'required': sorted(set(required)),
|
|
70
|
+
'source': observed.get('source'), 'state': 'known' if known else 'unknown',
|
|
71
|
+
'missing': missing, 'satisfied': not missing if known else not required,
|
|
72
|
+
'write_permissions_verified': False})
|
|
73
|
+
return rows
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Pure origin policy: declarations are never inferred from titles or other posts."""
|
|
2
|
+
|
|
3
|
+
from socialctl.models import MediaKind, Platform, PlatformPost, ValidationError
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def expected_long_comment(video_id: str) -> str:
|
|
7
|
+
return f"🎥 Video completo en https://www.youtube.com/watch?v={video_id}"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def validate_derivation(post: PlatformPost, *, require_origin: bool) -> list[ValidationError]:
|
|
11
|
+
errors = []
|
|
12
|
+
|
|
13
|
+
def error(field: str, message: str) -> None:
|
|
14
|
+
errors.append(ValidationError(platform=post.platform, campo=field, motivo=message))
|
|
15
|
+
|
|
16
|
+
meta = post.platform in {Platform.FACEBOOK, Platform.INSTAGRAM}
|
|
17
|
+
video = any(asset.kind is MediaKind.VIDEO for asset in post.media)
|
|
18
|
+
if post.content_origin is None:
|
|
19
|
+
if post.source_video_id is not None:
|
|
20
|
+
error("content_origin", "a YouTube source is present without a content classification")
|
|
21
|
+
elif meta and video and require_origin:
|
|
22
|
+
error("content_origin", "declare standalone or youtube_long before publishing")
|
|
23
|
+
return errors
|
|
24
|
+
if post.content_origin == "standalone":
|
|
25
|
+
if post.source_video_id is not None:
|
|
26
|
+
error("source_video_id", "standalone does not support a source long-form video")
|
|
27
|
+
return errors
|
|
28
|
+
if post.source_video_id is None:
|
|
29
|
+
error("source_video_id", "the exact source long-form video ID is missing")
|
|
30
|
+
elif meta and post.first_comment not in {
|
|
31
|
+
expected_long_comment(post.source_video_id),
|
|
32
|
+
f"Full video: https://www.youtube.com/watch?v={post.source_video_id}"}:
|
|
33
|
+
error("first_comment", "the exact comment linking to the source long-form video is missing")
|
|
34
|
+
return errors
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Human-readable publication status without inferring remote visibility."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from socialctl.models import Platform, PostResult, PostStatus
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _aware_datetime(value: str | None) -> datetime | None:
|
|
11
|
+
if not value:
|
|
12
|
+
return None
|
|
13
|
+
try:
|
|
14
|
+
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
15
|
+
except (ValueError, TypeError):
|
|
16
|
+
return None
|
|
17
|
+
return parsed if parsed.utcoffset() is not None else None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def describe_result(result: PostResult) -> str:
|
|
21
|
+
"""Describe what is known, keeping requested and observed state separate."""
|
|
22
|
+
if result.status is not PostStatus.PUBLICADO:
|
|
23
|
+
return {PostStatus.PENDIENTE_CONFIRMACION: "pending_confirmation", PostStatus.OMITIDO: "skipped", PostStatus.ERROR: "error"}.get(result.status, "published")
|
|
24
|
+
if result.platform is not Platform.YOUTUBE:
|
|
25
|
+
return "publication confirmed"
|
|
26
|
+
observed = _aware_datetime(result.visibility_observed_at)
|
|
27
|
+
if observed is None or not result.observed_privacy:
|
|
28
|
+
return "upload confirmed; visibility unverified"
|
|
29
|
+
if result.observed_privacy == "private":
|
|
30
|
+
planned = _aware_datetime(result.observed_publish_at)
|
|
31
|
+
if planned is not None and planned > observed:
|
|
32
|
+
return "upload confirmed; scheduled, still private"
|
|
33
|
+
return "upload confirmed; private"
|
|
34
|
+
if result.observed_privacy == "unlisted":
|
|
35
|
+
return "upload confirmed; unlisted"
|
|
36
|
+
if result.observed_privacy == "public":
|
|
37
|
+
if result.observed_processing_status == "succeeded":
|
|
38
|
+
return "upload confirmed; public"
|
|
39
|
+
return (
|
|
40
|
+
'upload confirmed; public privacy observed, processing unverified'
|
|
41
|
+
)
|
|
42
|
+
return "upload confirmed; visibility unverified"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def describe_result_with_observation(result: PostResult) -> str:
|
|
46
|
+
"""Add the observation instant so persisted reports cannot look current."""
|
|
47
|
+
description = describe_result(result)
|
|
48
|
+
has_observation = any(
|
|
49
|
+
(
|
|
50
|
+
result.observed_privacy,
|
|
51
|
+
result.observed_publish_at,
|
|
52
|
+
result.observed_processing_status,
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
if (
|
|
56
|
+
result.platform is Platform.YOUTUBE
|
|
57
|
+
and has_observation
|
|
58
|
+
and _aware_datetime(result.visibility_observed_at) is not None
|
|
59
|
+
):
|
|
60
|
+
return f"{description} (observed {result.visibility_observed_at})"
|
|
61
|
+
return description
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def describe_native_job(job, payload: dict, *, comment_status: dict | None = None) -> str:
|
|
65
|
+
"""Keep native lifecycle and dependent follow-up work distinct."""
|
|
66
|
+
stamp = job.observation_watermark.isoformat() if job.observation_watermark else 'never'
|
|
67
|
+
result = f'{job.state}; requested {job.publish_at.isoformat()}; observed {stamp}'
|
|
68
|
+
if payload.get('first_comment'):
|
|
69
|
+
status = (comment_status or {}).get('status', 'pending durable worker follow-up after public verification')
|
|
70
|
+
result += f'; first comment: {status}'
|
|
71
|
+
if (comment_status or {}).get('publication_id'):
|
|
72
|
+
result += f"; recovery: {comment_status['publication_id']}"
|
|
73
|
+
if payload.get('options', {}).get('related_video_id'):
|
|
74
|
+
result += '; related-video link: pending separate verification'
|
|
75
|
+
return result
|