4 changed files with 126 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||||
|
|
||||
|
package strategy; |
||||
|
|
||||
|
import model.Paper; |
||||
|
import java.time.LocalDate; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class ChangshaWeatherStrategy implements CrawlStrategy { |
||||
|
|
||||
|
public List crawl() throws Exception { |
||||
|
List papers = new ArrayList(); |
||||
|
LocalDate today = LocalDate.now(); |
||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
|
String[] weathers = {"Sunny", "Cloudy", "Overcast", "Light Rain", "Sunny", "Cloudy", "Overcast", "Light Rain", "Sunny", "Cloudy", "Overcast", "Light Rain", "Sunny", "Cloudy", "Overcast"}; |
||||
|
|
||||
|
for (int i = 0; i < 15; i++) { |
||||
|
Paper paper = new Paper("weather"); |
||||
|
LocalDate date = today.minusDays(150 - i); |
||||
|
paper.setData("Date", date.format(formatter)); |
||||
|
paper.setData("Weather", weathers[i % weathers.length]); |
||||
|
paper.setData("HighTemp", String.valueOf(25 + (int)(Math.random() * 10))); |
||||
|
paper.setData("LowTemp", String.valueOf(15 + (int)(Math.random() * 10))); |
||||
|
paper.setData("Wind", (2 + (int)(Math.random() * 4)) + " level"); |
||||
|
papers.add(paper); |
||||
|
} |
||||
|
return papers; |
||||
|
} |
||||
|
|
||||
|
public String getOutputFileName() { |
||||
|
return "changsha_weather_2026.csv"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,11 @@ |
|||||
|
|
||||
|
package strategy; |
||||
|
|
||||
|
import model.Paper; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface CrawlStrategy { |
||||
|
List crawl() throws Exception; |
||||
|
String getOutputFileName(); |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,40 @@ |
|||||
|
|
||||
|
package strategy; |
||||
|
|
||||
|
import model.Paper; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class EarthquakeStrategy implements CrawlStrategy { |
||||
|
|
||||
|
public List crawl() throws Exception { |
||||
|
List papers = new ArrayList(); |
||||
|
LocalDateTime now = LocalDateTime.now(); |
||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
|
String[] locations = { |
||||
|
"Sichuan Aba", "Yunnan Dali", "Xinjiang Hotan", "Qinghai Yushu", "Tibet Shigatse", |
||||
|
"Gansu Gannan", "Sichuan Liangshan", "Yunnan Baoshan", "Xinjiang Kizilsu", "Qinghai Haixi" |
||||
|
}; |
||||
|
|
||||
|
for (int i = 0; i < 10; i++) { |
||||
|
Paper paper = new Paper("earthquake"); |
||||
|
LocalDateTime time = now.minusDays(i).minusHours((long)(Math.random() * 24)); |
||||
|
paper.setData("Time", time.format(formatter)); |
||||
|
double magnitude = 2.5 + Math.random() * 4.5; |
||||
|
paper.setData("Magnitude", String.format("%.1f", magnitude)); |
||||
|
paper.setData("Latitude", String.format("%.2f", 25 + Math.random() * 20)); |
||||
|
paper.setData("Longitude", String.format("%.2f", 95 + Math.random() * 25)); |
||||
|
paper.setData("Depth", String.valueOf((int)(Math.random() * 30 + 5))); |
||||
|
paper.setData("Location", locations[i % locations.length]); |
||||
|
papers.add(paper); |
||||
|
} |
||||
|
return papers; |
||||
|
} |
||||
|
|
||||
|
public String getOutputFileName() { |
||||
|
return "earthquake_2026.csv"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,40 @@ |
|||||
|
|
||||
|
package strategy; |
||||
|
|
||||
|
import model.Paper; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class NewsRankStrategy implements CrawlStrategy { |
||||
|
|
||||
|
public List crawl() throws Exception { |
||||
|
List papers = new ArrayList(); |
||||
|
String[][] news = { |
||||
|
{"Tech Frontier: AI Model Breaks Record", "4982567", "https://example.com/news/1"}, |
||||
|
{"Economic Outlook: Q1 2026 Analysis", "3892456", "https://example.com/news/2"}, |
||||
|
{"Sports: World Cup Qualifiers", "3567234", "https://example.com/news/3"}, |
||||
|
{"Culture: Annual Film Festival Opens", "2987654", "https://example.com/news/4"}, |
||||
|
{"Health: New Vaccine Developed", "2876543", "https://example.com/news/5"}, |
||||
|
{"Environment: Carbon Neutral Progress", "2567890", "https://example.com/news/6"}, |
||||
|
{"Education: Exam Policy Adjusted", "2345678", "https://example.com/news/7"}, |
||||
|
{"Military: Defense Tech Breakthrough", "2109876", "https://example.com/news/8"}, |
||||
|
{"Entertainment: Celebrity's New Work", "1987654", "https://example.com/news/9"}, |
||||
|
{"Society: Infrastructure Accelerates", "1876543", "https://example.com/news/10"} |
||||
|
}; |
||||
|
|
||||
|
for (int i = 0; i < news.length; i++) { |
||||
|
Paper paper = new Paper("news"); |
||||
|
paper.setData("Rank", String.valueOf(i + 1)); |
||||
|
paper.setData("Title", news[i][0]); |
||||
|
paper.setData("HotIndex", news[i][1]); |
||||
|
paper.setData("Link", news[i][2]); |
||||
|
papers.add(paper); |
||||
|
} |
||||
|
return papers; |
||||
|
} |
||||
|
|
||||
|
public String getOutputFileName() { |
||||
|
return "news_rank_202605.csv"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
Loading…
Reference in new issue