Added too much functionality with redis + fix for build docker stage and added run stage
Some checks failed
Build and push image / deploy (push) Failing after 27s

This commit is contained in:
2024-03-18 18:20:27 +03:00
parent 1b2d3844d9
commit e7599f72da
7 changed files with 345 additions and 37 deletions

View File

@ -1,7 +1,9 @@
FROM eclipse-temurin:21-jdk-jammy
FROM maven:3.9.6-eclipse-temurin-21
# build
WORKDIR app
COPY pom.xml .
RUN mvn -f /app/pom.xml clean package -Dmaven.test.skip=true
COPY . .
RUN mvn -f pom.xml clean package -Dmaven.test.skip=true
# run
RUN java -jar target/testSteamPrices .jar

View File

@ -7,6 +7,7 @@
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testSteamPrices</name>
<url>http://maven.apache.org</url>
@ -62,5 +63,6 @@
</configuration>
</plugin>
</plugins>
<finalName>testSteamPrices</finalName>
</build>
</project>

View File

@ -0,0 +1,61 @@
package org.example;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class GameInfoMapper
{
public GameInfoResponse mapGameInfoJson(JsonNode node)
{
GameInfoResponse response = new GameInfoResponse();
response.setName(node.get("name").toString().replaceAll("\"", ""));
response.setPage_image(node.get("page_image").toString().replaceAll("\"", ""));
response.setSmall_logo(node.get("small_logo").toString().replaceAll("\"", ""));
if (node.get("apps").isArray())
{
ArrayList<GameInfoResponse.AppClass> apps = new ArrayList<>();
for (JsonNode jsonNode : node.get("apps"))
{
apps.add(new GameInfoResponse.AppClass(jsonNode.get("id").asInt(), jsonNode.get("name").toString().replaceAll("\"", "")));
}
response.setApps(apps);
}
GameInfoResponse.Price price = null;
if (node.get("price") != null)
{
price = new GameInfoResponse.Price(node.get("price").get("currency").toString().replaceAll("\"", ""), node.get("price").get("initial").asInt(), node.get("price").get("final").asInt(), node.get("price").get("discount_percent").asInt(), node.get("price").get("individual").asInt());
}
response.setPrice(price);
GameInfoResponse.Platforms platforms = new GameInfoResponse.Platforms(node.get("platforms").get("windows").asBoolean(), node.get("platforms").get("mac").asBoolean(), node.get("platforms").get("linux").asBoolean());
response.setPlatforms(platforms);
GameInfoResponse.Controller controller = new GameInfoResponse.Controller(node.get("controller").get("full_gamepad").asBoolean());
response.setController(controller);
GameInfoResponse.ReleaseDate releaseDate = null;
try
{
String jsonDate = node.get("release_date").get("date").toString().replaceAll("\"", "");
Date formattedDate = null;
if (!jsonDate.isEmpty())
{
formattedDate = new SimpleDateFormat("dd MMM, yyyy", Locale.ENGLISH).parse(jsonDate);
}
releaseDate = new GameInfoResponse.ReleaseDate(node.get("release_date").get("coming_soon").asBoolean(), formattedDate);
}
catch (ParseException e)
{
throw new RuntimeException(e);
}
response.setRelease_date(releaseDate);
return response;
}
}

View File

@ -1,34 +1,267 @@
package org.example;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
final class GameInfoResponse
public class GameInfoResponse
{
private String name;
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;
private Map<String, ReleaseDate> date;
private String page_image;
@Getter
@Setter
@NoArgsConstructor
private static final class ReleaseDate
private String small_logo;
private ArrayList<AppClass> apps;
private Price price;
private Platforms platforms;
private Controller controller;
private ReleaseDate release_date;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPage_image()
{
return page_image;
}
public void setPage_image(String page_image)
{
this.page_image = page_image;
}
public String getSmall_logo()
{
return small_logo;
}
public void setSmall_logo(String small_logo)
{
this.small_logo = small_logo;
}
public ArrayList<AppClass> getApps()
{
return apps;
}
public void setApps(ArrayList<AppClass> apps)
{
this.apps = apps;
}
public Price getPrice()
{
return price;
}
public void setPrice(Price price)
{
this.price = price;
}
public Platforms getPlatforms()
{
return platforms;
}
public void setPlatforms(Platforms platforms)
{
this.platforms = platforms;
}
public Controller getController()
{
return controller;
}
public void setController(Controller controller)
{
this.controller = controller;
}
public ReleaseDate getRelease_date()
{
return release_date;
}
public void setRelease_date(ReleaseDate release_date)
{
this.release_date = release_date;
}
public static class AppClass
{
private int id;
private String name;
public AppClass()
{
}
public AppClass(int id, String name)
{
this.id = id;
this.name = name;
}
public int getId()
{
return id;
}
public String getName()
{
return name;
}
}
public static class Price
{
private String currency;
private int initial;
private int finals;
private int discount_percent;
private int individual;
public Price()
{
}
public Price(String currency, int initial, int finals, int discount_percent, int individual)
{
this.currency = currency;
this.initial = initial;
this.finals = finals;
this.discount_percent = discount_percent;
this.individual = individual;
}
public String getCurrency()
{
return currency;
}
public int getInitial()
{
return initial;
}
public int getFinals()
{
return finals;
}
public int getDiscount_percent()
{
return discount_percent;
}
public int getIndividual()
{
return individual;
}
}
public static class Platforms
{
private boolean windows;
private boolean mac;
private boolean linux;
public Platforms()
{
}
public Platforms(boolean windows, boolean mac, boolean linux)
{
this.windows = windows;
this.mac = mac;
this.linux = linux;
}
public boolean isWindows()
{
return windows;
}
public boolean isMac()
{
return mac;
}
public boolean isLinux()
{
return linux;
}
}
public static class Controller
{
private boolean full_gamepad;
public Controller()
{
}
public Controller(boolean full_gamepad)
{
this.full_gamepad = full_gamepad;
}
public boolean isFull_gamepad()
{
return full_gamepad;
}
}
public static class ReleaseDate
{
private boolean coming_soon;
private Date date;
public ReleaseDate()
{
}
public ReleaseDate(boolean coming_soon, Date date)
{
this.coming_soon = coming_soon;
this.date = date;
}
public boolean isComing_soon()
{
return coming_soon;
}
public Date getDate()
{
return date;
}
}
}

View File

@ -1,6 +1,7 @@
package org.example;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.HostAndPort;
@ -15,6 +16,9 @@ public class LoadGameService
@Autowired
private RedisService redisService;
@Autowired
private GameInfoMapper mapper;
public void loadGamesbySingleThread() throws InterruptedException
{
@ -35,17 +39,26 @@ public class LoadGameService
e.printStackTrace();
if (e.getMessage().equals("429"))
{
Thread.sleep(30000);
Thread.sleep(240000);
continue;
}
i++;
continue;
}
//TODO: add filter for successful and unsuccessful requests
jedis.set(String.valueOf(i), json.toString());
if (json.get(Integer.toString(i)).get("success").asBoolean())
{
GameInfoResponse infoResponse = mapper.mapGameInfoJson(json.get(Integer.toString(i)).get("data"));
jedis.set(infoResponse.getName(), new ObjectMapper().writeValueAsString(infoResponse));
System.out.println("Current id = " + i);
System.out.println(json.toPrettyString());
GameInfoResponse newResponse = new ObjectMapper().readValue(jedis.get(infoResponse.getName()), GameInfoResponse.class);
System.out.println("Value loaded from Redis = " + jedis.get(json.get(Integer.toString(i)).get("data").get("name").toString()));
}
else
{
System.out.println("Game with id = " + i + " does not exist in Steam");
}
i++;
}

View File

@ -6,10 +6,10 @@ public class SteamConstants
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 PROXY_HOST = "77.73.134.212";
final static int PROXY_PORT = 8000;
final static String PROXY_USER = "KzMUMc";
final static String PROXY_PASS = "457pZN";
final static String CA_CERT_PASS = "Q1598520q";
final static String USER_CERT_PASS = "Q1598520q";
}

View File

@ -1,20 +1,17 @@
package org.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.HashMap;
import java.util.Map;
@Configuration
@ComponentScan
public class SteamPriceParser
{
public static Map<Integer, Boolean> gameCodeList = new HashMap<>();
static