first commit
This commit is contained in:
97
src/main/java/org/example/GameInfoResponse.java
Normal file
97
src/main/java/org/example/GameInfoResponse.java
Normal file
@ -0,0 +1,97 @@
|
||||
package org.example;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@JsonIgnoreProperties
|
||||
final class GameInfoResponse
|
||||
{
|
||||
|
||||
private Map<String, String> data;
|
||||
private List<Map<String, String>> apps;
|
||||
private Map<String, Float> price;
|
||||
private Map<String, String> platforms;
|
||||
private Map<String, String> controller;
|
||||
|
||||
|
||||
public Map<String, String> getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, String> data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getApps()
|
||||
{
|
||||
return apps;
|
||||
}
|
||||
|
||||
public void setApps(List<Map<String, String>> apps)
|
||||
{
|
||||
this.apps = apps;
|
||||
}
|
||||
|
||||
public Map<String, Float> getPrice()
|
||||
{
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Map<String, Float> price)
|
||||
{
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Map<String, String> getPlatforms()
|
||||
{
|
||||
return platforms;
|
||||
}
|
||||
|
||||
public void setPlatforms(Map<String, String> platforms)
|
||||
{
|
||||
this.platforms = platforms;
|
||||
}
|
||||
|
||||
public Map<String, String> getController()
|
||||
{
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void setController(Map<String, String> controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
private static final class ReleaseDate
|
||||
{
|
||||
public boolean isComing_soon()
|
||||
{
|
||||
return coming_soon;
|
||||
}
|
||||
|
||||
public void setComing_soon(boolean coming_soon)
|
||||
{
|
||||
this.coming_soon = coming_soon;
|
||||
}
|
||||
|
||||
public Date getDate()
|
||||
{
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date)
|
||||
{
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
private boolean coming_soon;
|
||||
private Date date;
|
||||
}
|
||||
}
|
||||
|
||||
|
129
src/main/java/org/example/SteamPriceParser.java
Normal file
129
src/main/java/org/example/SteamPriceParser.java
Normal file
@ -0,0 +1,129 @@
|
||||
package org.example;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import redis.clients.jedis.*;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
|
||||
//TODO: move const to resources
|
||||
public class SteamPriceParser
|
||||
{
|
||||
|
||||
final static String GAME_DETAILS_API_TEMPLATE = "https://store.steampowered.com/api/packagedetails?packageids=%s&cc=%s&filters=price_overview";
|
||||
final static String REDIS_HOST = "rc1a-67kduigjscq90cna.mdb.yandexcloud.net";
|
||||
final static String REDIS_PASS = "Q1598520q";
|
||||
final static String PROXY_HOST = "91.147.123.214";
|
||||
final static int PROXY_PORT = 50101;
|
||||
final static String PROXY_USER = "pavel0RG3T";
|
||||
final static String PROXY_PASS = "pJ9KTE9QbD";
|
||||
final static String CA_CERT_PASS = "Q1598520q";
|
||||
final static String USER_CERT_PASS = "Q1598520q";
|
||||
|
||||
|
||||
public static void main(String[] args) throws GeneralSecurityException, IOException
|
||||
{
|
||||
JsonNode json;
|
||||
|
||||
try (JedisPooled jedis = new JedisPooled(new HostAndPort(REDIS_HOST, 6380), prepareRedisConfig()))
|
||||
{
|
||||
//TODO: add threads
|
||||
for (int i = 0; i < 150000; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
json = loadGameJson(String.format(GAME_DETAILS_API_TEMPLATE, i, "KZ"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//TODO: add pushing logs to kibana or etc..
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
//TODO: add filter for successful and unsuccessful requests
|
||||
jedis.set(String.valueOf(i), json.toString());
|
||||
System.out.println("Current id = " + i);
|
||||
System.out.println(json.toPrettyString());
|
||||
|
||||
System.out.println("jedis value for " + i + "\n" + jedis.get(String.valueOf(i)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//TODO: move hostname, port, log and pass to resources
|
||||
//TODO: remove deprecated URL constructor
|
||||
//TODO: replace mapper towards concrete class model GameInfoResponse
|
||||
private static JsonNode loadGameJson(String url) throws IOException
|
||||
{
|
||||
InputStream inputStream;
|
||||
|
||||
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(PROXY_HOST, PROXY_PORT));
|
||||
Authenticator authenticator = new Authenticator()
|
||||
{
|
||||
public PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return (new PasswordAuthentication(PROXY_USER, PROXY_PASS.toCharArray()));
|
||||
}
|
||||
};
|
||||
Authenticator.setDefault(authenticator);
|
||||
URLConnection connection = new URL(url).openConnection(proxy);
|
||||
inputStream = connection.getInputStream();
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readTree(reader);
|
||||
|
||||
}
|
||||
|
||||
public static DefaultJedisClientConfig prepareRedisConfig() throws GeneralSecurityException, IOException
|
||||
{
|
||||
SSLSocketFactory sslFactory = createSslSocketFactory(
|
||||
"C:\\truststore.jks",
|
||||
CA_CERT_PASS, // use the password specified for keytool command
|
||||
"C:\\redis-keystore.p12",
|
||||
USER_CERT_PASS // use the password specified for openssl command
|
||||
);
|
||||
|
||||
return DefaultJedisClientConfig.builder()
|
||||
.ssl(true)
|
||||
.sslSocketFactory(sslFactory)
|
||||
.user("default")
|
||||
.password(REDIS_PASS)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static SSLSocketFactory createSslSocketFactory(
|
||||
String caCertPath, String caCertPassword, String userCertPath, String userCertPassword)
|
||||
throws IOException, GeneralSecurityException
|
||||
{
|
||||
|
||||
KeyStore keyStore = KeyStore.getInstance("pkcs12");
|
||||
keyStore.load(Files.newInputStream(Paths.get(userCertPath)), userCertPassword.toCharArray());
|
||||
|
||||
KeyStore trustStore = KeyStore.getInstance("jks");
|
||||
trustStore.load(Files.newInputStream(Paths.get(caCertPath)), caCertPassword.toCharArray());
|
||||
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
|
||||
trustManagerFactory.init(trustStore);
|
||||
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("PKIX");
|
||||
keyManagerFactory.init(keyStore, userCertPassword.toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
return sslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
|
||||
}
|
1
src/main/resources/config.properties
Normal file
1
src/main/resources/config.properties
Normal file
@ -0,0 +1 @@
|
||||
GAME_DETAILS_API_TEMPLATE = https://store.steampowered.com/api/packagedetails?packageids=%s&cc=%s&filters=price_overview
|
38
src/test/java/org/example/SteamPriceParserTest.java
Normal file
38
src/test/java/org/example/SteamPriceParserTest.java
Normal file
@ -0,0 +1,38 @@
|
||||
package org.example;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class SteamPriceParserTest
|
||||
extends TestCase
|
||||
{
|
||||
/**
|
||||
* Create the test case
|
||||
*
|
||||
* @param testName name of the test case
|
||||
*/
|
||||
public SteamPriceParserTest(String testName )
|
||||
{
|
||||
super( testName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the suite of tests being tested
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
return new TestSuite( SteamPriceParserTest.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigourous Test :-)
|
||||
*/
|
||||
public void testApp()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user