autojs之词云

使用情景

制作词云, 并在手机上显示

效果展示

吴孟达先生今日走了, 用先生的百度百科做个词云, 纪念小时候的大明星达叔

在这里插入图片描述

原理

  1. 使用python的wordcloud模块生成词云
  2. autojs负责展示词云

难点

  1. django实现文件的上传和下载
  2. autojs实现多文件上传

代码讲解

  1. 画一个界面用于功能演示
"ui";
ui.layout(
  <vertical margin="20">
    <input id="input" h="200dp"></input>
    <button id="btn" textSize="20sp">
      生成词云
    </button>
    <text>备注: 文字越多, 生成越慢, 请耐心等待 1m的文字大概20s左右</text>
    <img id="img"></img>
  </vertical>
);
  1. 设置词云来源内容
let 吴孟达先生的百度百科 = "......"
ui.input.setText(吴孟达先生的百度百科);
  1. 设置按钮的点击事件
ui.btn.click(function () {
    
    
  ui.btn.setEnabled(false);
  ui.btn.setText("服务器生成词云中, 请耐性等待");

  threads.start(function () {
    
    
    let url = "http://192.168.101.4:8000/polls/wordcloud/";

    var res = http.postMultipart(url, getData());

    let tempFilepath = "/sdcard/1.jpg";
    files.writeBytes(tempFilepath, res.body.bytes());
    // app.viewFile(tempFilepath);
    ui.post(function () {
    
    
      ui.img.attr("src", "file://" + tempFilepath);
      ui.btn.setEnabled(true);
      ui.btn.setText("生成词云");
    }, 100);
  });
});
  1. 展示处理好的词云图片
ui.img.attr("src", "file://" + tempFilepath);

查看项目代码


微信公众号 AutoJsPro教程

在这里插入图片描述

QQ群

747748653

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/snailuncle2/article/details/114191192