Created
January 9, 2024 11:42
-
-
Save SinTeZWh1te/6c9a621e3be44e97c8699d22fe201374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.ellco.bgbilling.kernel.scripts.global.tv; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import org.json.JSONArray; | |
import org.json.JSONObject; | |
import ru.bitel.bgbilling.kernel.container.managed.ServerContext; | |
import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase; | |
import ru.bitel.bgbilling.modules.tv.dyn.JsonClient; | |
import ru.bitel.bgbilling.server.util.Setup; | |
import ru.bitel.common.sql.ConnectionSet; | |
import java.net.URL; | |
import java.sql.Connection; | |
import java.util.HashSet; | |
import java.util.Set; | |
/** | |
* @author sintezwh1te | |
*/ | |
public class SyncWithLifeStream | |
extends GlobalScriptBase { | |
private static final Logger logger = LogManager.getLogger(); | |
private static final String login = "login"; | |
private static final String password = "password"; | |
private static final String url = "https://test.proxy.lfstrm.tv"; | |
JsonClient jsonClient = null; | |
@Override | |
public void execute(Setup setup, ConnectionSet connectionSet) | |
throws Exception { | |
Connection con = connectionSet.getConnection(); | |
ServerContext serverContext = ServerContext.get(); | |
Set<String> lifeStreamAccountSet = new HashSet<>(); | |
try { | |
jsonClient = new JsonClient(new URL(url), login, password); | |
JSONObject response = jsonClient.invoke(JsonClient.Method.get, null, "/v2/accounts", null, null); | |
if (response != null) { | |
JSONArray accounts = response.getJSONArray("accounts"); | |
for (int i = 0; i < accounts.length(); i++) { | |
JSONObject account = accounts.getJSONObject(i); | |
lifeStreamAccountSet.add(account.optString("id")); | |
} | |
} | |
JSONObject pagination = response.optJSONObject("pagination"); | |
int pages = 0; | |
if (pagination != null && !pagination.isEmpty()) { | |
pages = pagination.optInt("pages"); | |
if (pages > 0) { | |
for (int page = 1; page < pages; page++) { | |
response = jsonClient.invoke(JsonClient.Method.get, null, "/v2/accounts?page_size=" + pagination.optInt("page_size") + "&page=" + page, null, null); | |
if (response != null) { | |
JSONArray accounts = response.getJSONArray("accounts"); | |
for (int i = 0; i < accounts.length(); i++) { | |
JSONObject account = accounts.getJSONObject(i); | |
lifeStreamAccountSet.add(account.optString("id")); | |
} | |
} | |
} | |
} | |
} | |
} finally { | |
if (jsonClient != null) { | |
jsonClient.disconnect(); | |
} | |
} | |
/* | |
Тута реализовываем проверки на наличие отсутствия | |
*/ | |
print(lifeStreamAccountSet); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment