コード例 #1
0
 def fix_metadata(self,
                  metadata,
                  standard_format=False,
                  api_type: str = "") -> dict:
     new_format = {}
     new_format["version"] = 1
     new_format["content"] = {}
     if isinstance(metadata, list):
         version = 0.3
         for m in metadata:
             new_format["content"] |= self.fix_metadata(m)["content"]
             print
         metadata = new_format
     else:
         version = metadata.get("version", None)
     if any(x for x in metadata if x in media_types().__dict__.keys()):
         standard_format = True
         print
     if not version and not standard_format and metadata:
         legacy_metadata = metadata
         media_type = legacy_metadata.get("type", None)
         if not media_type:
             version = 0.1
             media_type = api_type if api_type else media_type
         else:
             version = 0.2
         if version == 0.2:
             legacy_metadata.pop("type")
         new_format["content"][media_type] = {}
         for key, posts in legacy_metadata.items():
             if all(isinstance(x, list) for x in posts):
                 posts = list(chain(*posts))
             new_format["content"][media_type][key] = posts
             print
         print
     elif standard_format:
         if any(x for x in metadata if x in media_types().__dict__.keys()):
             metadata.pop("directories", None)
             for key, status in metadata.items():
                 if isinstance(status, int):
                     continue
                 for key2, posts in status.items():
                     if all(x and isinstance(x, list) for x in posts):
                         posts = list(chain(*posts))
                         metadata[key][key2] = posts
                     print
                 print
             print
         new_format["content"] = metadata
         print
     else:
         if global_version == version:
             new_format = metadata
         else:
             print
     print
     if "content" not in new_format:
         print
     return new_format
コード例 #2
0
    def __init__(
        self,
        authed=None,
        version=None,
        temp_old_content: dict = {},
        export=False,
        reformat=False,
        args={},
    ):
        class assign_state(object):
            def __init__(self) -> None:
                self.valid = []
                self.invalid = []

            def __iter__(self):
                for attr, value in self.__dict__.items():
                    yield attr, value

        old_content = temp_old_content.copy()
        old_content.pop("directories", None)
        new_content = media_types(assign_states=assign_state)
        for key, new_item in new_content:
            old_item = old_content.get(key)
            if not old_item:
                continue
            for old_key, old_item2 in old_item.items():
                new_posts = []
                if global_version == version:
                    posts = old_item2
                    for old_post in posts:
                        post = self.post_item(old_post)
                        new_medias = []
                        for media in post.medias:
                            media["media_type"] = key
                            media2 = self.media_item(media)
                            new_medias.append(media2)
                        post.medias = new_medias
                        new_posts.append(post)
                        print

                elif version == 1:
                    old_item2.sort(key=lambda x: x["post_id"])
                    media_list = [
                        list(g) for k, g in groupby(old_item2,
                                                    key=lambda x: x["post_id"])
                    ]
                    for media_list2 in media_list:
                        old_post = media_list2[0]
                        post = self.post_item(old_post)
                        for item in media_list2:
                            item["media_type"] = key
                            media = self.media_item(item)
                            post.medias.append(media)
                        new_posts.append(post)
                else:
                    media_list = []
                    input("METADATA VERSION: INVALID")
                setattr(new_item, old_key, new_posts)
        self.content = new_content