0.0.1.0
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
package org.sillyjrafe.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;
|
||||
}
|
||||
}
|
||||
+43
@@ -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.sillyblahaj.uoapi.Api;
|
||||
import org.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.sillyjirafe.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyblahaj.uoapi.element;
|
||||
|
||||
public class Json {
|
||||
public static String JSONConvert(List<element> elements) {
|
||||
JSONArray tableau = new JSONArray();
|
||||
|
||||
for (element e : elements) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("title", e.title());
|
||||
obj.put("url", e.url());
|
||||
obj.put("licence", e.licence());
|
||||
obj.put("source", e.source());
|
||||
obj.put("type", e.type());
|
||||
tableau.put(obj);
|
||||
}
|
||||
|
||||
return tableau.toString();
|
||||
}
|
||||
}
|
||||
+49
@@ -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.sillyblahaj.uoapi.binds.GitHubApacheApi;
|
||||
import org.sillyblahaj.uoapi.binds.GitHubLGPLApi;
|
||||
import org.sillyblahaj.uoapi.binds.GitHubMITApi;
|
||||
import org.sillyblahaj.uoapi.binds.OpenVerseAudiosApi;
|
||||
import org.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package org.sillyjirafe.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyblahaj.uoapi.element;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
public class Start {
|
||||
public static void API(Connection conn) throws IOException {
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(8081), 0);
|
||||
|
||||
server.createContext("/search", exchange -> {
|
||||
String query = exchange.getRequestURI().getQuery();
|
||||
Map<String, String> settings = parseQuery(query);
|
||||
|
||||
try {
|
||||
List<element> results = Search.search(conn, settings);
|
||||
String json = Json.JSONConvert(results);
|
||||
|
||||
exchange.getResponseHeaders().set("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(200, json.getBytes().length);
|
||||
exchange.getResponseBody().write(json.getBytes());
|
||||
exchange.getResponseBody().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
exchange.sendResponseHeaders(500, 0);
|
||||
exchange.getResponseBody().close();
|
||||
}
|
||||
});
|
||||
|
||||
server.start();
|
||||
System.out.println("Search API run on 8081 port");
|
||||
}
|
||||
|
||||
public static Map<String, String> parseQuery(String query) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
if (query == null) return params;
|
||||
|
||||
String[] paires = query.split("&");
|
||||
|
||||
for (String paire : paires) {
|
||||
String[] cle_valeur = paire.split("=", 2);
|
||||
if (cle_valeur.length == 2) {
|
||||
params.put(cle_valeur[0], cle_valeur[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.sillyjirafe.uoapi.binds;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyblahaj.uoapi.Api;
|
||||
import org.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package org.sillyblahaj.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyblahaj.uoapi.element;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
public class Start {
|
||||
public static void API(Connection conn) throws IOException {
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(8081), 0);
|
||||
|
||||
server.createContext("/search", exchange -> {
|
||||
String query = exchange.getRequestURI().getQuery();
|
||||
Map<String, String> settings = parseQuery(query);
|
||||
|
||||
try {
|
||||
List<element> results = Search.search(conn, settings);
|
||||
String json = Json.JSONConvert(results);
|
||||
|
||||
exchange.getResponseHeaders().set("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(200, json.getBytes().length);
|
||||
exchange.getResponseBody().write(json.getBytes());
|
||||
exchange.getResponseBody().close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
exchange.sendResponseHeaders(500, 0);
|
||||
exchange.getResponseBody().close();
|
||||
}
|
||||
});
|
||||
|
||||
server.start();
|
||||
System.out.println("Search API run on 8081 port");
|
||||
}
|
||||
|
||||
public static Map<String, String> parseQuery(String query) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
if (query == null) return params;
|
||||
|
||||
String[] paires = query.split("&");
|
||||
|
||||
for (String paire : paires) {
|
||||
String[] cle_valeur = paire.split("=", 2);
|
||||
if (cle_valeur.length == 2) {
|
||||
params.put(cle_valeur[0], cle_valeur[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
+44
@@ -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.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package org.sillyjrafe.uoapi.binds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.sillyblahaj.uoapi.Api;
|
||||
import org.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+44
@@ -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.sillyblahaj.uoapi.Api;
|
||||
import org.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+43
@@ -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.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package org.sillyblahaj.api;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyblahaj.uoapi.element;
|
||||
|
||||
public class Search {
|
||||
public static List<element> search(Connection conn, Map<String, String> settings) throws SQLException {
|
||||
List<element> results = new ArrayList<>();
|
||||
String sql = """
|
||||
SELECT * FROM creations
|
||||
WHERE (? = '' OR title LIKE ?)
|
||||
AND (? = '' OR licence = ?)
|
||||
AND (? = '' OR type = ?)
|
||||
""";
|
||||
|
||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setString(1, settings.getOrDefault("q", ""));
|
||||
ps.setString(2, "%" + settings.getOrDefault("q", "") + "%");
|
||||
ps.setString(3, settings.getOrDefault("licence", ""));
|
||||
ps.setString(4, settings.getOrDefault("licence", ""));
|
||||
ps.setString(5, settings.getOrDefault("type", ""));
|
||||
ps.setString(6, settings.getOrDefault("type", ""));
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
results.add(new element(
|
||||
rs.getString("title"),
|
||||
rs.getString("url"),
|
||||
rs.getString("licence"),
|
||||
rs.getString("source"),
|
||||
rs.getString("type")
|
||||
));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.sillyjirafe.linker;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyblahaj.db.Crawl_StateDB;
|
||||
import org.sillyblahaj.db.ElementsDB;
|
||||
import org.sillyblahaj.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();
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package org.sillyjirafe.api;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.sillyblahaj.uoapi.element;
|
||||
|
||||
public class Search {
|
||||
public static List<element> search(Connection conn, Map<String, String> settings) throws SQLException {
|
||||
List<element> results = new ArrayList<>();
|
||||
String sql = """
|
||||
SELECT * FROM creations
|
||||
WHERE (? = '' OR title LIKE ?)
|
||||
AND (? = '' OR licence = ?)
|
||||
AND (? = '' OR type = ?)
|
||||
""";
|
||||
|
||||
try (PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setString(1, settings.getOrDefault("q", ""));
|
||||
ps.setString(2, "%" + settings.getOrDefault("q", "") + "%");
|
||||
ps.setString(3, settings.getOrDefault("licence", ""));
|
||||
ps.setString(4, settings.getOrDefault("licence", ""));
|
||||
ps.setString(5, settings.getOrDefault("type", ""));
|
||||
ps.setString(6, settings.getOrDefault("type", ""));
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
results.add(new element(
|
||||
rs.getString("title"),
|
||||
rs.getString("url"),
|
||||
rs.getString("licence"),
|
||||
rs.getString("source"),
|
||||
rs.getString("type")
|
||||
));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
+42
@@ -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.sillyblahaj.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();
|
||||
}
|
||||
}
|
||||
+44
@@ -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.sillyblahaj.uoapi.Api;
|
||||
import org.sillyblahaj.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;
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user