0.0.1.0
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="/home/Kotama_Chio/libs/sqlite-jdbc-3.53.2.1.jar">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/home/Kotama_Chio/libs/json-20250107.jar">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SillyBlahaj.org</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
module SillyBlahaj.org {
|
||||
requires java.sql;
|
||||
requires java.net.http;
|
||||
requires org.json;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.sillyjirafe.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class Crawl_StateDB
|
||||
{
|
||||
String URL = new String();
|
||||
String insertSql = "INSERT OR IGNORE INTO crawlstates (bind_name, last_page) VALUES (?, ?)";
|
||||
Connection connection;
|
||||
|
||||
public Crawl_StateDB(String BDstr) throws SQLException
|
||||
{
|
||||
URL = BDstr;
|
||||
connection = DriverManager.getConnection(URL);
|
||||
}
|
||||
|
||||
public void LinkToDB() throws SQLException
|
||||
{
|
||||
try (Statement stmt = connection.createStatement())
|
||||
{
|
||||
stmt.execute("""
|
||||
CREATE TABLE IF NOT EXISTS crawlstates (
|
||||
bind_name TEXT PRIMARY KEY,
|
||||
last_page INTEGER NOT NULL DEFAULT 1
|
||||
)
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddEllement(String bind, int lastpage) throws SQLException
|
||||
{
|
||||
try (PreparedStatement ps = connection.prepareStatement(insertSql))
|
||||
{
|
||||
ps.setString(1, bind);
|
||||
ps.setInt(2, lastpage);
|
||||
ps.executeUpdate();
|
||||
System.out.printf("%s is now page %d \n", bind, lastpage);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPage(String bindName) throws SQLException {
|
||||
String sql = "SELECT last_page FROM crawlstates WHERE bind_name = ?";
|
||||
|
||||
try (PreparedStatement ps = connection.prepareStatement(sql)) {
|
||||
ps.setString(1, bindName);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
return rs.getInt("last_page");
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void updatePage(String bindName) throws SQLException {
|
||||
String sql = """
|
||||
INSERT INTO crawlstates (bind_name, last_page) VALUES (?, 2)
|
||||
ON CONFLICT(bind_name) DO UPDATE SET last_page = last_page + 1
|
||||
""";
|
||||
|
||||
try (PreparedStatement ps = connection.prepareStatement(sql)) {
|
||||
ps.setString(1, bindName);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void Close() throws SQLException
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.sillyjirafe.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class ElementsDB {
|
||||
String URL = new String();
|
||||
String insertSql = "INSERT OR IGNORE INTO creations (title, url, licence, source, type) VALUES (?, ?, ?, ?, ?)";
|
||||
Connection connection;
|
||||
|
||||
public ElementsDB(String BDstr) throws SQLException
|
||||
{
|
||||
URL = BDstr;
|
||||
connection = DriverManager.getConnection(URL);
|
||||
}
|
||||
|
||||
public void LinkToDB() throws SQLException
|
||||
{
|
||||
try (Statement stmt = connection.createStatement()) {
|
||||
stmt.execute("""
|
||||
CREATE TABLE IF NOT EXISTS creations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
url TEXT NOT NULL UNIQUE,
|
||||
licence TEXT NOT NULL,
|
||||
source TEXT NOT NULL,
|
||||
type TEXT NOT NULL
|
||||
)
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
public void AddEllement(String title, String url, String licence, String source, String type) throws SQLException
|
||||
{
|
||||
try (PreparedStatement ps = connection.prepareStatement(insertSql)) {
|
||||
ps.setString(1, title);
|
||||
ps.setString(2, url);
|
||||
ps.setString(3, licence);
|
||||
ps.setString(4, source);
|
||||
ps.setString(5, type);
|
||||
ps.executeUpdate();
|
||||
System.out.printf("%s added \n", title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Close() throws SQLException
|
||||
{
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.sillyjirafe.linker;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyjirafe.db.Crawl_StateDB;
|
||||
import org.sillyjirafe.db.ElementsDB;
|
||||
import org.sillyjirafe.uoapi.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Out Out = new Out();
|
||||
ElementsDB elementDB = new ElementsDB("jdbc:sqlite:elements.db");
|
||||
Crawl_StateDB crawlstateDB = new Crawl_StateDB("jdbc:sqlite:crawlstates.db");
|
||||
elementDB.LinkToDB();
|
||||
crawlstateDB.LinkToDB();
|
||||
|
||||
List<String> bindNames = Out.PreOut();
|
||||
|
||||
Map<String, Integer> pages = new HashMap<>();
|
||||
for (String nom : bindNames) {
|
||||
pages.put(nom, crawlstateDB.getPage(nom));
|
||||
}
|
||||
|
||||
List<element> elements = Out.out(pages);
|
||||
|
||||
for (int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
element el = elements.get(i);
|
||||
elementDB.AddEllement(el.title(), el.url(), el.licence(), el.source(), el.type());
|
||||
}
|
||||
|
||||
for (String name : bindNames) {
|
||||
crawlstateDB.updatePage(name);
|
||||
}
|
||||
|
||||
elementDB.Close();
|
||||
crawlstateDB.Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.sillyjirafe.uoapi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Api {
|
||||
String getURL(int page);
|
||||
public List<element> Parse(String JsonRaw);
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.sillyjirafe.uoapi;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
|
||||
public class Caller {
|
||||
public static List<element> CallApi(Api api, int page) throws Exception
|
||||
{
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(api.getURL(page)))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
return api.Parse(response.body());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.sillyjirafe.uoapi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyjirafe.uoapi.binds.GitHubApacheApi;
|
||||
import org.sillyjirafe.uoapi.binds.GitHubLGPLApi;
|
||||
import org.sillyjirafe.uoapi.binds.GitHubMITApi;
|
||||
import org.sillyjirafe.uoapi.binds.OpenVerseAudiosApi;
|
||||
import org.sillyjirafe.uoapi.binds.OpenVerseImagesApi;
|
||||
|
||||
public class Out {
|
||||
List<Api> Apis = new ArrayList<>();
|
||||
|
||||
public List<String> PreOut()
|
||||
{
|
||||
Apis.add(new GitHubMITApi());
|
||||
Apis.add(new GitHubLGPLApi());
|
||||
Apis.add(new GitHubApacheApi());
|
||||
Apis.add(new OpenVerseImagesApi());
|
||||
Apis.add(new OpenVerseAudiosApi());
|
||||
|
||||
List<String> bindnames = new ArrayList<>();
|
||||
|
||||
for (Api api : Apis)
|
||||
{
|
||||
bindnames.add(api.getName());
|
||||
}
|
||||
|
||||
return bindnames;
|
||||
}
|
||||
|
||||
public List<element> out(Map<String, Integer> bindpages) throws Exception
|
||||
{
|
||||
List<element> Elements = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < Apis.size(); i++)
|
||||
{
|
||||
List<element> currentapi = Caller.CallApi(Apis.get(i), bindpages.get(Apis.get(i).getName()));
|
||||
for (int j = 0; j < currentapi.size(); j++)
|
||||
{
|
||||
Elements.add(currentapi.get(j));
|
||||
}
|
||||
}
|
||||
return Elements;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.sillyjirafe.uoapi.binds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyjirafe.uoapi.Api;
|
||||
import org.sillyjirafe.uoapi.element;
|
||||
|
||||
public class GitHubApacheApi implements Api
|
||||
{
|
||||
public String getName()
|
||||
{
|
||||
return "GitHubApacheApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
return "https://api.github.com/search/repositories?q=license:apache-2.0&page=" + page;
|
||||
}
|
||||
|
||||
public List<element> Parse(String jsonRaw) {
|
||||
List<element> resultats = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonRaw);
|
||||
JSONArray items = json.getJSONArray("items");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject repo = items.getJSONObject(i);
|
||||
|
||||
String titre = repo.getString("full_name");
|
||||
String url = repo.getString("html_url");
|
||||
String licence = repo.getJSONObject("license").getString("spdx_id");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "github", "code"));
|
||||
}
|
||||
} catch (org.json.JSONException e) {
|
||||
System.out.println("error but continue : " + e.getMessage());
|
||||
}
|
||||
|
||||
return resultats;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.sillyjirafe.uoapi.binds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyjirafe.uoapi.Api;
|
||||
import org.sillyjirafe.uoapi.element;
|
||||
|
||||
public class GitHubLGPLApi implements Api
|
||||
{
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "GitHubLGPLApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
return "https://api.github.com/search/repositories?q=license:lgpl-3.0&page=" + page;
|
||||
}
|
||||
|
||||
public List<element> Parse(String jsonRaw) {
|
||||
List<element> resultats = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonRaw);
|
||||
JSONArray items = json.getJSONArray("items");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject repo = items.getJSONObject(i);
|
||||
|
||||
String titre = repo.getString("full_name");
|
||||
String url = repo.getString("html_url");
|
||||
String licence = repo.getJSONObject("license").getString("spdx_id");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "github", "code"));
|
||||
}
|
||||
} catch (org.json.JSONException e) {
|
||||
System.out.println("error but continue : " + e.getMessage());
|
||||
}
|
||||
|
||||
return resultats;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.sillyjirafe.uoapi.binds;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyjirafe.uoapi.Api;
|
||||
import org.sillyjirafe.uoapi.element;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GitHubMITApi implements Api
|
||||
{
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "GitHubMITApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
return "https://api.github.com/search/repositories?q=license:mit&page=" + page;
|
||||
}
|
||||
|
||||
public List<element> Parse(String jsonRaw) {
|
||||
List<element> resultats = new ArrayList<>();
|
||||
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonRaw);
|
||||
JSONArray items = json.getJSONArray("items");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject repo = items.getJSONObject(i);
|
||||
|
||||
String titre = repo.getString("full_name");
|
||||
String url = repo.getString("html_url");
|
||||
String licence = repo.getJSONObject("license").getString("spdx_id");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "github", "code"));
|
||||
}
|
||||
} catch (org.json.JSONException e) {
|
||||
System.out.println("error but continue : " + e.getMessage());
|
||||
}
|
||||
|
||||
return resultats;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.sillyjirafe.uoapi.binds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyjirafe.uoapi.Api;
|
||||
import org.sillyjirafe.uoapi.element;
|
||||
|
||||
public class OpenVerseAudiosApi implements Api
|
||||
{
|
||||
public String getName()
|
||||
{
|
||||
return "OpenVerseAudiosApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
return "https://api.openverse.org/v1/audio/?format=json&page=" + page;
|
||||
}
|
||||
|
||||
public List<element> Parse(String jsonRaw) {
|
||||
List<element> resultats = new ArrayList<>();
|
||||
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonRaw);
|
||||
JSONArray items = json.getJSONArray("results");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject image = items.getJSONObject(i);
|
||||
|
||||
String titre = image.getString("title");
|
||||
String url = image.getString("url");
|
||||
String licence = image.getString("license");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "openverse", "audio"));
|
||||
}
|
||||
} catch (org.json.JSONException e) {
|
||||
System.out.println("error but continue : " + e.getMessage());
|
||||
}
|
||||
return resultats;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.sillyjirafe.uoapi.binds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyjirafe.uoapi.Api;
|
||||
import org.sillyjirafe.uoapi.element;
|
||||
|
||||
public class OpenVerseImagesApi implements Api
|
||||
{
|
||||
public String getName()
|
||||
{
|
||||
return "OpenVerseImagesApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
return "https://api.openverse.org/v1/images/?format=json&page=" + page;
|
||||
}
|
||||
|
||||
public List<element> Parse(String jsonRaw) {
|
||||
List<element> resultats = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonRaw);
|
||||
JSONArray items = json.getJSONArray("results");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject image = items.getJSONObject(i);
|
||||
|
||||
String titre = image.getString("title");
|
||||
String url = image.getString("url");
|
||||
String licence = image.getString("license");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "openverse", "image"));
|
||||
}
|
||||
} catch (org.json.JSONException e) {
|
||||
System.out.println("error but continue : " + e.getMessage());
|
||||
}
|
||||
return resultats;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package org.sillyjirafe.uoapi;
|
||||
|
||||
public record element(String title, String url, String licence, String source, String type) {}
|
||||
Reference in New Issue
Block a user