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

Method generate_metadata

medium-parser/medium_parser/core.py:694–751  ·  view source on GitHub ↗
(
        self, post_data: dict, post_id: str, as_dict: bool = False
    )

Source from the content-addressed store, hash-verified

692 return result
693
694 async def generate_metadata(
695 self, post_data: dict, post_id: str, as_dict: bool = False
696 ) -> tuple | dict[str, str]:
697 title = RLStringHelper(
698 post_data["data"]["post"]["title"], ["minimal"]
699 ).get_text()
700 subtitle = RLStringHelper(
701 post_data["data"]["post"]["previewContent"]["subtitle"]
702 ).get_text()
703 description = RLStringHelper(
704 textwrap.shorten(subtitle, width=100, placeholder="...")
705 ).get_text()
706 preview_image_id = post_data["data"]["post"]["previewImage"]["id"]
707 creator = post_data["data"]["post"]["creator"]
708 collection = post_data["data"]["post"]["collection"]
709 url = post_data["data"]["post"]["mediumUrl"]
710
711 reading_time = math.ceil(post_data["data"]["post"]["readingTime"])
712 free_access = "No" if post_data["data"]["post"]["isLocked"] else "Yes"
713 updated_at = convert_datetime_to_human_readable(
714 post_data["data"]["post"]["updatedAt"]
715 )
716 first_published_at = convert_datetime_to_human_readable(
717 post_data["data"]["post"]["firstPublishedAt"]
718 )
719 tags = post_data["data"]["post"]["tags"]
720
721 if as_dict:
722 return {
723 "post_id": post_id,
724 "title": title,
725 "subtitle": subtitle,
726 "description": description,
727 "url": url,
728 "creator": creator,
729 "collection": collection,
730 "reading_time": reading_time,
731 "free_access": free_access,
732 "updated_at": updated_at,
733 "first_published_at": first_published_at,
734 "preview_image_id": preview_image_id,
735 "tags": tags,
736 }
737
738 return (
739 title,
740 subtitle,
741 description,
742 url,
743 creator,
744 collection,
745 reading_time,
746 free_access,
747 updated_at,
748 first_published_at,
749 preview_image_id,
750 tags,
751 )

Callers 2

_render_as_htmlMethod · 0.95
fetch_post_metadataFunction · 0.80

Calls 3

RLStringHelperClass · 0.90
get_textMethod · 0.80

Tested by

no test coverage detected