pdfkit

pip install pdfkit #wkhtmltopdf 的Python封装包
安装wkhtmltopdf并添加至环境变量

sudo apt install wkhtmltopdf
pdfkit用法

pdfkit.from_url('http://google.com', 'out.pdf')  #从URL生成
pdfkit.from_file('test.html', 'out.pdf')  #从文件生

retry

pip install retry
from retry import retry
 
@retry(tries=2)
def func():
    # do something
 
if __name__ == '__main__':
    func()
上面我们指定了func()最多运行2次,即使没有运行成功,在达到2次后,程序也会退出。如果没有tries=2,将表示一致运行至成功

wordcloud

import jieba
import wordcloud
import imageio
import time


class Make_cloud:
    def __init__(self):
        #引入图片
        self.mask = imageio.imread("jian.jpeg")
        self.data = None
        self.image = None
        self.target = None

    def get_data(self):
        #引入文件使用jieba分词
        self.image = open("../tips/doc/mom", "r", encoding="utf-8")
        self.data = jieba.lcut(self.image.read())

    def __del__(self):
        self.image.close()
        print("over")

    def generate_word(self):
        #生成图片
        w = wordcloud.WordCloud(width=1000, height=700, background_color="white", font_path="msyh.ttc", mask=self.mask)
        w.generate(" ".join(self.data))
        w.to_file("{}.png".format(int(time.time())))

    def main(self):
        self.get_data()
        self.generate_word()


if __name__ == '__main__':
    cloud = Make_cloud()
    cloud.main()
 
 
posted on 2022-09-26 11:44  topass123  阅读(10)  评论(1编辑  收藏  举报