diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-10-13 23:20:17 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-10-13 23:20:17 -0700 |
| commit | e1c4f7ac903df58ae5f63c6f837af9f97426f5ad (patch) | |
| tree | f168f64c1b80d1889d00d2d9f5571ba720c403b0 /VtuberCaptchaUpdater | |
| parent | f7ad0dcaf179c8c10d8ba9353f6a00acde33f574 (diff) | |
add Java captcha data updater script
Diffstat (limited to 'VtuberCaptchaUpdater')
| -rw-r--r-- | VtuberCaptchaUpdater/pom.xml | 47 | ||||
| -rw-r--r-- | VtuberCaptchaUpdater/src/main/java/Main.java | 82 |
2 files changed, 129 insertions, 0 deletions
diff --git a/VtuberCaptchaUpdater/pom.xml b/VtuberCaptchaUpdater/pom.xml new file mode 100644 index 0000000..a17a550 --- /dev/null +++ b/VtuberCaptchaUpdater/pom.xml @@ -0,0 +1,47 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.example</groupId> + <artifactId>VtuberCaptchaUpdater</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>VtuberCaptchaUpdater</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>com.pinapelz</groupId> + <artifactId>jholodex</artifactId> + <version>1.41</version> + </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20240303</version> + </dependency> + + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.7.4</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>9</source> + <target>9</target> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/VtuberCaptchaUpdater/src/main/java/Main.java b/VtuberCaptchaUpdater/src/main/java/Main.java new file mode 100644 index 0000000..3cb93a8 --- /dev/null +++ b/VtuberCaptchaUpdater/src/main/java/Main.java @@ -0,0 +1,82 @@ +import com.google.gson.Gson; +import com.pinapelz.Holodex; +import com.pinapelz.HolodexException; +import com.pinapelz.datatypes.Channel; +import com.pinapelz.query.ChannelQueryBuilder; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.*; + +import java.sql.*; + + +public class Main +{ + // Organization name -> formatted name + private static Map<String, String> organizations = Map.of( + "Hololive", "Hololive", + "Nijisanji", "Nijisanji", + "VShojo", "VShojo", + "idol Corp", "Idol Corp", + "EIEN Project", "Eien Project", + "Phase Connect", "Phase Connect" + ); + + public static HashMap<String, String> readSettings() throws IOException { + String settings = new String(Files.readAllBytes(Paths.get("secrets.json"))); + return new Gson().fromJson(settings, HashMap.class); + } + + public static Connection createDBConnection(HashMap<String, String> settings) throws IOException, SQLException { + String url = "jdbc:postgresql://"+settings.get("pg_host")+"/"+settings.get("pg_db"); + Properties props = new Properties(); + props.setProperty("user", settings.get("pg_user")); + props.setProperty("password", settings.get("pg_password")); + Connection conn = DriverManager.getConnection(url, props); + return conn; + } + + public static void main( String[] args ) throws IOException, HolodexException, SQLException { + HashMap<String, String> settings = readSettings(); + Connection conn = createDBConnection(settings); + System.out.println("Sucessfully connected to the database"); + Holodex holodex = new Holodex(settings.get("holodex_key")); + Statement stmt = conn.createStatement(); + stmt.executeUpdate("DELETE FROM " + settings.get("pg_table")); + stmt.close(); + System.out.println("Deleted all rows from the channels table"); + for (String org : organizations.keySet()) { + ChannelQueryBuilder query = new ChannelQueryBuilder().setOrg(organizations.get(org)).setLimit(200); + System.out.println("Getting channels for " + org); + List<Channel> channels = holodex.getChannels(new ChannelQueryBuilder().setOrg(org)); + System.out.println("Got " + channels.size() + " channels"); + for (Channel channel : channels) { + if(channel.english_name == null || channel.photo == null || channel.english_name.equals("")) { + System.out.println("Skipping " + channel.name); + continue; + } + if(channel.inactive){ + System.out.println("Skipping inactive channel " + channel.english_name); + continue; + } + String insert = "INSERT INTO " + settings.get("pg_table") + + " (name, affiliation, image_url) " + + "VALUES ('" + channel.english_name + "', '" + org+ "', '" + channel.photo + "')"; + System.out.println(insert); + try{ + stmt = conn.createStatement(); + stmt.executeUpdate(insert); + stmt.close(); + } catch (SQLException e) { + System.out.println("Failed to insert " + channel.english_name); + System.out.println(e.getMessage()); + } + } + } + + + + } +} |
