0.0.1.4
This commit is contained in:
1 parent
c7f07c9e28
commit
8c690e216d
114 files changed
+4470
-1768
No files matched your search
@@ -6,12 +6,12 @@
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="/home/Kotama_Chio/libs/sqlite-jdbc-3.53.2.1.jar">
|
||||
<classpathentry kind="lib" path="/home/kotama/Silly-Jirafe/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">
|
||||
<classpathentry kind="lib" path="/home/kotama/Silly-Jirafe/libs/json-20250107.jar">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
|
||||
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.
@@ -1,5 +1,44 @@
|
||||
package org.sillyjirafe.json;
|
||||
|
||||
public class ApiKeys {
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class ApiKeys {
|
||||
public static Map<String, String> read()
|
||||
{
|
||||
|
||||
Path filePath = Paths.get("ApiKeys.json");
|
||||
try {
|
||||
String jsonraw = Files.readString(filePath);
|
||||
JSONObject json = new JSONObject(jsonraw);
|
||||
Map<String, String> ApiKeys = new HashMap();
|
||||
|
||||
JSONArray items = json.getJSONArray("keys");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject key = items.getJSONObject(i);
|
||||
String bind = key.getString("bind");
|
||||
String password = key.getString("key");
|
||||
|
||||
ApiKeys.put(bind, password);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("I/O error: " + e.getMessage());
|
||||
} catch (SecurityException e) {
|
||||
System.err.println("Access denied: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
|
||||
import org.sillyjirafe.db.Crawl_StateDB;
|
||||
import org.sillyjirafe.db.ElementsDB;
|
||||
import org.sillyjirafe.json.ApiKeys;
|
||||
import org.sillyjirafe.uoapi.*;
|
||||
|
||||
public class Main {
|
||||
@@ -24,7 +25,8 @@ public class Main {
|
||||
pages.put(nom, crawlstateDB.getPage(nom));
|
||||
}
|
||||
|
||||
List<element> elements = Out.out(pages);
|
||||
|
||||
List<element> elements = Out.out(pages, ApiKeys.read());
|
||||
|
||||
for (int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.sillyjirafe.uoapi;
|
||||
import java.util.List;
|
||||
|
||||
public interface Api {
|
||||
String getURL(int page);
|
||||
String getURL(int page, String apiKey);
|
||||
public List<element> Parse(String JsonRaw);
|
||||
String getName();
|
||||
}
|
||||
@@ -7,12 +7,12 @@ import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
|
||||
public class Caller {
|
||||
public static List<element> CallApi(Api api, int page) throws Exception
|
||||
public static List<element> CallApi(Api api, int page, String apiKey) throws Exception
|
||||
{
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(api.getURL(page)))
|
||||
.uri(URI.create(api.getURL(page, apiKey)))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
|
||||
@@ -32,13 +32,13 @@ public class Out {
|
||||
return bindnames;
|
||||
}
|
||||
|
||||
public List<element> out(Map<String, Integer> bindpages) throws Exception
|
||||
public List<element> out(Map<String, Integer> bindpages, Map<String, String> ApiKeys) 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()));
|
||||
List<element> currentapi = Caller.CallApi(Apis.get(i), bindpages.get(Apis.get(i).getName()), ApiKeys.get(Apis.get(i).getName()));
|
||||
for (int j = 0; j < currentapi.size(); j++)
|
||||
{
|
||||
Elements.add(currentapi.get(j));
|
||||
|
||||
@@ -15,7 +15,7 @@ public class GitHubApacheApi implements Api
|
||||
return "GitHubApacheApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
public String getURL(int page, String apikey) {
|
||||
return "https://api.github.com/search/repositories?q=license:apache-2.0&page=" + page;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class GitHubLGPLApi implements Api
|
||||
return "GitHubLGPLApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
public String getURL(int page, String apikey) {
|
||||
return "https://api.github.com/search/repositories?q=license:lgpl-3.0&page=" + page;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class GitHubMITApi implements Api
|
||||
return "GitHubMITApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
public String getURL(int page, String apikey) {
|
||||
return "https://api.github.com/search/repositories?q=license:mit&page=" + page;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,24 +15,23 @@ public class OpenVerseAudiosApi implements Api
|
||||
return "OpenVerseAudiosApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
public String getURL(int page, String apikey) {
|
||||
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);
|
||||
JSONObject audio = items.getJSONObject(i);
|
||||
|
||||
String titre = image.getString("title");
|
||||
String url = image.getString("url");
|
||||
String licence = image.getString("license");
|
||||
String titre = audio.getString("title");
|
||||
String url = audio.getString("url");
|
||||
String licence = audio.getString("license");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "openverse", "audio"));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class OpenVerseImagesApi implements Api
|
||||
return "OpenVerseImagesApi";
|
||||
}
|
||||
|
||||
public String getURL(int page) {
|
||||
public String getURL(int page, String apikey) {
|
||||
return "https://api.openverse.org/v1/images/?format=json&page=" + page;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 PixabayImagesApi implements Api
|
||||
{
|
||||
public String getName()
|
||||
{
|
||||
return "PixabayImagesAPI";
|
||||
}
|
||||
|
||||
public String getURL(int page, String apikey) {
|
||||
return "https://pixabay.com/api/?page=" + page + "key=" + apikey;
|
||||
}
|
||||
|
||||
public List<element> Parse(String jsonRaw) {
|
||||
List<element> resultats = new ArrayList<>();
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject(jsonRaw);
|
||||
JSONArray items = json.getJSONArray("");
|
||||
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject repo = items.getJSONObject(i);
|
||||
|
||||
String titre = repo.getString("full_name");
|
||||
String url = repo.getString("pageURL");
|
||||
String licence = repo.getJSONObject("license").getString("spdx_id");
|
||||
|
||||
resultats.add(new element(titre, url, licence, "pixabay", "image"));
|
||||
}
|
||||
} catch (org.json.JSONException e) {
|
||||
System.out.println("error but continue : " + e.getMessage());
|
||||
}
|
||||
|
||||
return resultats;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user