Ejemplo n.º 1
0
    def push_item(self, item: FullItem, images: Iterable[IO], channel: str, converted_username: str):
        d = self.root / item.service.value / item.source_id
        self.ensure_dir(d)
        json_buffer = BytesIO(json.dumps(item.to_dict(), ensure_ascii=False).encode('utf-8'))
        json_fp = d / f"{item.item_id}_info.json"
        self.write_file(json_fp, json_buffer)
        PostRecord.put_record(item.service, item.item_id, ServiceType.Mega, str(json_fp), channel)

        for idx, img in enumerate(images):
            fp = d / f"{item.item_id}_{idx:03d}.png"
            self.write_file(fp, img)
            PostRecord.put_record(item.service, item.item_id, ServiceType.Mega, str(fp), channel)
Ejemplo n.º 2
0
 def push_item(self, item: FullItem, images: Iterable[IO], channel: str,
               converted_username: str):
     parent = self.root / item.service.value.replace(
         '/', '_') / converted_username.replace('/', '_')
     parent.mkdir(parents=True, exist_ok=True)
     meta_file = parent / f"{item.item_id}_info.json"
     with meta_file.open('w') as f:
         json.dump(item.to_dict(), f, ensure_ascii=False)
     if len(item.content) > 100:
         content_file = parent / f"{item.item_id}_content.txt"
         with content_file.open('w') as f:
             f.write(item.content)
     for idx, buf in enumerate(images):
         fp = parent / f"{item.item_id}_{idx:03d}.png"
         with fp.open('wb') as f:
             f.write(buf.read())
Ejemplo n.º 3
0
    def push_item(self, item: FullItem, images: Iterable[IO], channel: str,
                  converted_username: str):
        json_buffer = BytesIO(
            json.dumps(item.to_dict(), ensure_ascii=False).encode('utf-8'))
        # nickname = UserInfo.get_nickname(item.service, item.source_id)
        # if nickname is None:
        #     dir_name = f"({item.source_id})"
        # else:
        #     dir_name = f"{nickname}({item.source_id})"
        dir_name = item.source_id
        fp = self.write_file(channel, item.service, dir_name,
                             f"{item.item_id}_info.json", json_buffer)
        PostRecord.put_record(item.service, item.item_id, ServiceType.WebDav,
                              fp, channel)

        for idx, img in enumerate(images):
            fp = self.write_file(channel, item.service, dir_name,
                                 f"{item.item_id}_{idx:03d}.png", img)
            PostRecord.put_record(item.service, item.item_id,
                                  ServiceType.WebDav, fp, channel)