我有一个 python 脚本,它在 docker 容器中每分钟运行一次,这是我的 Dockerfile
FROM python:3.8.3 AS base
RUN apt-get update
RUN apt-get -y install software-properties-common cron vim
RUN apt-get update
RUN apt-get -y install python3-pip
RUN pip3 install pandas
RUN pip3 install sklearn
RUN pip3 install SQLAlchemy
RUN pip3 install ConfigParser
RUN pip3 install psycopg2
RUN pip3 install numpy
RUN pip3 install xgboost
RUN pip3 install xlrd
RUN pip3 install matplotlib
FROM base AS publish
WORKDIR /app
COPY . /app
COPY crontab /etc/cron.d/crontab
COPY main.py /app/main.py
RUN …Run Code Online (Sandbox Code Playgroud) @Service
public class PokemonManager implements PokemonService {
private HttpResponse<String> getStringHttpResponseByUrl(final String url) {
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.GET().header("accept", "application/json")
.uri(URI.create(url)).build();
HttpResponse<String> httpResponse = null;
try {
httpResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return httpResponse;
}
private <T> T getObjectResponse(T t, String url) {
ObjectMapper objectMapper = new ObjectMapper();
try {
t = objectMapper.readValue(getStringHttpResponseByUrl(url).body(), new TypeReference<>() {
});
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return t;
}
private List<Pokemon> …Run Code Online (Sandbox Code Playgroud)