MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / main

Function main

scripts/website/queue_browser_syndication.py:131–191  ·  view source on GitHub ↗
(argv: list[str])

Source from the content-addressed store, hash-verified

129
130
131def main(argv: list[str]) -> int:
132 args = parse_args(argv)
133 today = dt.date.fromisoformat(args.today) if args.today else dt.date.today()
134 floor = dt.date.fromisoformat(args.floor)
135 platforms = [p.strip() for p in args.platforms.split(",") if p.strip()]
136 state = State.load(Path(args.state_file))
137 blog_dir = Path(args.blog_dir)
138 posts = _eligible_posts(today, floor, args.min_age_days, blog_dir)
139 # Slug -> publish date for *every* post, so existing queue tasks can be
140 # re-checked against the per-platform rules regardless of eligibility.
141 dates_by_slug = {p.slug: p.date for p in discover_posts(blog_dir)}
142
143 queue_path = Path(args.queue_file)
144 if queue_path.exists():
145 queue = json.loads(queue_path.read_text(encoding="utf-8"))
146 else:
147 queue = {"tasks": []}
148
149 # Prune any already-queued task that the per-platform rules no longer
150 # allow (e.g. a non-Friday DZone task queued before the Friday-only
151 # filter landed, or one added by hand). The drain tool submits whatever
152 # sits in the queue, so this prune is what actually stops a stray task
153 # from reaching moderation.
154 original_tasks = queue.get("tasks", [])
155 kept_tasks = [t for t in original_tasks if _task_is_allowed(t, dates_by_slug)]
156 pruned = [t for t in original_tasks if t not in kept_tasks]
157 if pruned:
158 print(f"Pruning {len(pruned)} disallowed task(s) from the queue:")
159 for t in pruned:
160 print(f" - {t.get('id')}")
161 queue["tasks"] = kept_tasks
162 existing_ids = {t.get("id") for t in kept_tasks}
163
164 new_tasks: list[dict] = []
165 for post in posts:
166 for platform in platforms:
167 if not _platform_accepts(platform, post):
168 continue
169 task_id = f"{platform}:{post.slug}"
170 if task_id in existing_ids:
171 continue
172 if state.is_syndicated(post.slug, platform):
173 continue
174 new_tasks.append(_build_task(post, platform))
175
176 if new_tasks:
177 print(f"Queueing {len(new_tasks)} new task(s):")
178 for t in new_tasks:
179 print(f" + {t['id']}")
180 elif not pruned:
181 print("No new browser-syndication tasks to queue.")
182
183 if args.dry_run:
184 return 0
185
186 # Write when there is anything to add OR anything was pruned, so the
187 # cleaned queue is persisted even on a run that queues nothing new.
188 if new_tasks or pruned:

Callers 1

Calls 15

discover_postsFunction · 0.90
_eligible_postsFunction · 0.85
_task_is_allowedFunction · 0.85
_platform_acceptsFunction · 0.85
_build_taskFunction · 0.85
is_syndicatedMethod · 0.80
parse_argsFunction · 0.70
splitMethod · 0.65
loadMethod · 0.65
existsMethod · 0.65
getMethod · 0.65
appendMethod · 0.65

Tested by

no test coverage detected