Beispiel #1
0
def create_singel_word_cloud(text, path, colors=None):
    filename = f"{path}.png"
    with checkTimes(msg=f"Saved {filename} "):
        if not text:
            error("none text!")
            return
        stopwords = set(STOPWORDS) | set(read_stopwords())
        list(map(stopwords.add, ["看", "都", "不"]))
        jiebares = jieba.cut(text)
        if conf.use_frequencies:
            jiebares = dict(
                filter(
                    lambda item: bool(item[0].strip())
                    and item[0].strip() not in stopwords,
                    Counter(jiebares).most_common(100000),
                )
            )
        else:
            jiebares = " ".join(jiebares)
        wc = WordCloud(
            background_color="black" if conf.is_dark else "white",
            font_path="HYQiHei-25J.ttf",
            max_words=2000,
            mask=colors,
            stopwords=stopwords,
            max_font_size=100,
            random_state=45,
        )
        (wc.generate_from_frequencies if conf.use_frequencies else wc.generate)(
            jiebares
        )
        wc.recolor(color_func=ImageColorGenerator(colors))
        wc.to_file(filename)
Beispiel #2
0
def create_xlsx(datas, columns, filename="res.xlsx"):
    with checkTimes(msg=f"Created {filename} "):
        xlsx = pandas.DataFrame(datas)
        xlsx.rename(columns={_: __ for _, __ in enumerate(columns)}, inplace=True)
        writer = pandas.ExcelWriter(
            filename, engine="xlsxwriter", options={"strings_to_urls": False}
        )
        xlsx.to_excel(writer, "data")
        writer.save()
Beispiel #3
0
def CreateXLSX(datas, columns, filename='res.xlsx'):
    with checkTimes():
        xlsx = pandas.DataFrame(datas)
        xlsx.rename(columns=columns, inplace=True)
        writer = pandas.ExcelWriter(
            filename, options={'strings_to_urls': False})
        xlsx.to_excel(writer, "data")
        writer.save()
        success('Created {filename}')
Beispiel #4
0
def create_json(datas, filename="res.json"):
    with checkTimes(msg=f"Saved {filename} "):
        with open(filename, "w") as f:
            f.write(json.dumps(datas, ensure_ascii=False, indent=4))
Beispiel #5
0
        conf.max_time = 20000
    if new:
        conf.new = new
    if cons:
        conf.maxConnections = cons
    if excel:
        conf.need_excel = excel
    if words:
        conf.need_words = words
    if use_frequencies:
        conf.use_frequencies = use_frequencies
    if words_background:
        conf.words_background = words_background
    if is_dark:
        conf.is_dark = is_dark
    if graph:
        conf.need_graph = graph
    Spider().run()


if __name__ == "__main__":
    with checkTimes():
        try:
            main()
        except KeyboardInterrupt:
            pass
        except Exception as e:
            raise e
        finally:
            info("finished")
Beispiel #6
0
def CreateJson(datas, filename='res.json'):
    with checkTimes():
        with open(filename, 'w') as f:
            f.write(json.dumps(datas, ensure_ascii=False, indent=4))
            success(f'Saved {filename}')