• pdfkit,retry,wordcloud


    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()
     
     
  • 相关阅读:
    在Linux中安装Oracle(较详细图解)
    SecureCRT
    MHA配置文件说明
    MySQL建表规范与常见问题 (go)
    Shell编程时常用的系统文件(转)
    Leetcode: Excel Sheet Column Title
    Leetcode: Find Peak Element
    Leetcode: Intersection of Two Linked Lists
    Leetcode: Majority Element
    Summary: Class Variable vs. Instance Variable && Class Method
  • 原文地址:https://www.cnblogs.com/topass123/p/16730375.html
Copyright © 2020-2023  润新知