MCPcopy Create free account
hub / github.com/Freedium-cfd/web / is_valid_medium_url

Function is_valid_medium_url

medium-parser/medium_parser/utils.py:420–450  ·  view source on GitHub ↗

Check if the url is a valid Medium article page Check if the domain is in the known Medium domains and subdomains list. If the doman/subdomain is in the list, then the url is valid

(url: str)

Source from the content-addressed store, hash-verified

418
419@alru_cache(maxsize=100)
420async def is_valid_medium_url(url: str) -> bool:
421 """
422 Check if the url is a valid Medium article page
423
424 Check if the domain is in the known Medium domains and subdomains list. If the doman/subdomain is in the list, then the url is valid
425 """
426 domain = get_fld(url)
427 parsed_url = urlparse(url)
428 domain_netloc = un_wwwify(parsed_url.netloc)
429
430 # TODO: http://freedium.cfd/https://www.google.com.vn/url?sa=i&url=https%3A%2F%2Fmedium.com%2F%40dugguRK%2Fabout-android-hardware-abstraction-layer-hal-5d191dafeb2c&psig=AOvVaw17KP0U_haPMmhAByeMTxSg&ust=1711354113283000&source=images&cd=vfe&opi=89978449&ved=0CBQQjhxqFwoTCMCM_oG5jIUDFQAAAAAdAAAAABAa
431
432 if domain in ["12ft.io", "google.com", "facebook.com", "googleusercontent.com"]:
433 return True
434
435 if domain in NOT_MEDIUM_DOMAINS or domain_netloc in NOT_MEDIUM_DOMAINS:
436 raise exceptions.NotValidMediumURL("100% not valid Medium URL")
437
438 if domain in KNOWN_MEDIUM_DOMAINS or domain_netloc in KNOWN_MEDIUM_CUSTOM_DOMAINS:
439 return True
440
441 logger.warning(f"url '{url}' wasn't detected in known Medium domains")
442
443 # XXX: Unfourtunately, for now we don't know ALL Medium's domains, so we need resolve links
444 resolve_result = bool(await resolve_medium_url(url))
445
446 # send_message(f"We found that {domain=}, {domain_netloc=} is not listed in out known Medium database.\nURL: {url}")
447
448 return resolve_result
449
450 # return False

Callers 1

resolve_urlMethod · 0.85

Calls 3

get_fldFunction · 0.85
un_wwwifyFunction · 0.85
resolve_medium_urlFunction · 0.85

Tested by

no test coverage detected