You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.7 KiB
47 lines
1.7 KiB
package com.example.moviecli.command;
|
|
|
|
import com.example.moviecli.repository.MovieRepository;
|
|
import com.example.moviecli.strategy.MovieStrategyFactory;
|
|
import com.example.moviecli.view.ConsoleView;
|
|
|
|
public class AutoCommand implements Command {
|
|
private final ConsoleView view;
|
|
private final MovieStrategyFactory factory;
|
|
private final CrawlCommand crawlCommand;
|
|
|
|
public AutoCommand(ConsoleView view, MovieStrategyFactory factory) {
|
|
this.view = view;
|
|
this.factory = factory;
|
|
this.crawlCommand = new CrawlCommand(view, factory);
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "auto";
|
|
}
|
|
|
|
@Override
|
|
public void execute(String[] args, MovieRepository repository) {
|
|
view.printInfo("开始自动执行预设任务...");
|
|
|
|
// 1. 豆瓣电影 Top250
|
|
crawlCommand.execute(new String[]{"crawl", "https://movie.douban.com/top250"}, repository);
|
|
|
|
// 2. 新浪新闻(替代猫眼)
|
|
crawlCommand.execute(new String[]{"crawl", "https://news.sina.com.cn/"}, repository);
|
|
|
|
// 3. 豆瓣图书 Top50
|
|
crawlCommand.execute(new String[]{"crawl", "https://book.douban.com/top250"}, repository);
|
|
|
|
// 4. 列出所有数据
|
|
new ListCommand(view).execute(new String[]{"list"}, repository);
|
|
|
|
// 5. 统计评分分布
|
|
new StatCommand(view).execute(new String[]{"stat"}, repository);
|
|
|
|
// 6. 导出全部数据到 movies.csv
|
|
new ExportCommand(view).execute(new String[]{"export"}, repository);
|
|
|
|
view.printSuccess("自动任务执行完毕!已生成三个独立 CSV 文件及总文件 movies.csv。");
|
|
}
|
|
}
|