MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / two_factor

Function two_factor

Scripts/ButSystem.py:11233–11296  ·  view source on GitHub ↗

two_factor. Internal helper function. This docstring was added automatically to improve maintainability. Returns: Varies.

()

Source from the content-addressed store, hash-verified

11231 per_topic: Dict[str, int] = {}
11232 balanced: List[Dict[str, str]] = []
11233 for item in items:
11234 url = (item.get("url") or "").strip()
11235 topic_key = str(item.get("topic_key") or "other")
11236 if not url or url in seen or per_topic.get(topic_key, 0) >= 25:
11237 continue
11238 seen.add(url)
11239 per_topic[topic_key] = per_topic.get(topic_key, 0) + 1
11240 balanced.append(item)
11241 if len(balanced) >= 800:
11242 break
11243 return balanced
11244
11245def get_news_items(lang: str, force: bool = False) -> List[Dict[str, str]]:
11246 """Return cached news items (per-language)."""
11247 lang = "el" if lang == "el" else "en"
11248 now = time.time()
11249 with _NEWS_LOCK:
11250 ts = float(_NEWS_CACHE["ts"].get(lang, 0.0) or 0.0)
11251 cached = list(_NEWS_CACHE["items"].get(lang, []) or [])
11252 if cached and not force and (now - ts) < _NEWS_TTL:
11253 return cached
11254
11255 # Refresh outside lock (avoid blocking other requests)
11256 try:
11257 fresh = _fetch_news_uncached(lang)
11258 except Exception:
11259 fresh = []
11260
11261 with _NEWS_LOCK:
11262 _NEWS_CACHE["ts"][lang] = time.time()
11263 _NEWS_CACHE["items"][lang] = fresh
11264
11265 return list(fresh)
11266
11267@app.route("/news")
11268@login_required
11269def news():
11270 """News page: worldwide headlines by topic, in EN/EL based on the UI language."""
11271 lang = get_lang()
11272 # UI topics list with labels in the current language
11273 topics = [{"key": "all", "label": ("All" if lang == "en" else "Όλα")}]
11274 for key, labels, _q in NEWS_TOPICS:
11275 topics.append({"key": key, "label": labels.get(lang, labels["en"])})
11276 return render_template("news.html", title=_("News"), topics=topics)
11277
11278@app.route("/api/news")
11279@login_required
11280def api_news():
11281 """Return worldwide headlines (RSS aggregated) in the current language."""
11282 lang = (request.args.get("lang") or get_lang() or "en").strip().lower()
11283 if lang not in ("en", "el"):
11284 lang = get_lang()
11285 force = (request.args.get("force") == "1")
11286 items = []
11287 try:
11288 items = get_news_items(lang, force=force)
11289 except Exception:
11290 items = []

Callers

nothing calls this directly

Calls 10

_client_ipFunction · 0.70
_too_many_attemptsFunction · 0.70
db_connectFunction · 0.70
verify_security_answersFunction · 0.70
_mark_failFunction · 0.70
current_scopeFunction · 0.70
user_is_adminFunction · 0.70
scope_capacity_okFunction · 0.70
_clear_failFunction · 0.70
_complete_login_sessionFunction · 0.70

Tested by

no test coverage detected