feat: update charity project assets, add livestream media, and clean up temporary migration scripts
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PopulateLivestream {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Class.forName("oracle.jdbc.OracleDriver");
|
||||
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/sisvietnam", "sisvietnam", "sisvietnam");
|
||||
|
||||
// Get category ID
|
||||
PreparedStatement catStmt = conn.prepareStatement("SELECT id FROM sis_category WHERE slug = 'livestream'");
|
||||
ResultSet rsCat = catStmt.executeQuery();
|
||||
long catId = -1;
|
||||
if (rsCat.next()) {
|
||||
catId = rsCat.getLong("id");
|
||||
}
|
||||
if (catId == -1) {
|
||||
System.out.println("Category 'livestream' not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete old posts
|
||||
PreparedStatement delStmt = conn.prepareStatement("DELETE FROM sis_post WHERE category_id = ?");
|
||||
delStmt.setLong(1, catId);
|
||||
delStmt.executeUpdate();
|
||||
|
||||
String baseDir = "/home/x79/sisvietnamvn_01/Media/Livestream";
|
||||
String uploadDir = "/home/x79/sisvietnamvn_01/sisvietnamvn_main/src/main/resources/static/upload/livestream";
|
||||
new File(uploadDir).mkdirs();
|
||||
|
||||
long currentId = 6500;
|
||||
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String folder = baseDir + "/Tuan" + i;
|
||||
File f = new File(folder);
|
||||
if (!f.exists()) continue;
|
||||
|
||||
String title = "Tuần " + i;
|
||||
String excerpt = "";
|
||||
StringBuilder content = new StringBuilder();
|
||||
String metaDesc = "";
|
||||
String imageUrl = "";
|
||||
|
||||
File contentFile = new File(folder, "content.txt");
|
||||
if (contentFile.exists()) {
|
||||
List<String> lines = Files.readAllLines(contentFile.toPath());
|
||||
if (lines.size() > 0) title = lines.get(0);
|
||||
if (lines.size() > 1) excerpt = lines.get(1);
|
||||
for (int j = 2; j < lines.size(); j++) {
|
||||
content.append(lines.get(j)).append("<br>");
|
||||
}
|
||||
}
|
||||
|
||||
File embedFile = new File(folder, "embed.txt");
|
||||
if (!embedFile.exists()) embedFile = new File(folder, "url.txt");
|
||||
if (embedFile.exists()) {
|
||||
String embedStr = Files.readString(embedFile.toPath());
|
||||
Matcher m = Pattern.compile("src=\"([^\"]+)\"").matcher(embedStr);
|
||||
if (m.find()) {
|
||||
metaDesc = m.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (File img : f.listFiles()) {
|
||||
if (img.getName().endsWith(".jpg") || img.getName().endsWith(".png")) {
|
||||
File dest = new File(uploadDir, "tuan" + i + "_" + img.getName());
|
||||
Files.copy(img.toPath(), dest.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
imageUrl = "/upload/livestream/" + dest.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String slug = "livestream-tuan-" + i;
|
||||
|
||||
PreparedStatement insertStmt = conn.prepareStatement(
|
||||
"INSERT INTO sis_post (id, slug, title, excerpt, content, meta_description, featured_image, category_id, created_date, is_published, views) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, 1, 0)"
|
||||
);
|
||||
insertStmt.setLong(1, currentId++);
|
||||
insertStmt.setString(2, slug);
|
||||
insertStmt.setString(3, title);
|
||||
insertStmt.setString(4, excerpt);
|
||||
insertStmt.setString(5, content.toString());
|
||||
insertStmt.setString(6, metaDesc);
|
||||
insertStmt.setString(7, imageUrl);
|
||||
insertStmt.setLong(8, catId);
|
||||
insertStmt.executeUpdate();
|
||||
|
||||
System.out.println("Inserted Tuan " + i);
|
||||
}
|
||||
|
||||
conn.close();
|
||||
System.out.println("Done.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user