Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8.0
uses: actions/setup-java@v3
with:
java-version: '8.0'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Java CI with Maven
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file my-app/pom.xml
- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify --file my-app/pom.xml

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class App

Обратиться через браузер на адрес **https://api.ipify.org/?format=json** и получить json-ответ, содержащий IP4-адрес клиента. Извлечь адрес и вывести на экран в виде строки.

# Задание №3
## Задание №3

Через сайт **https://open-meteo.com** получить прогноз погоды на сутки. Использовать в качестве местоположения координаты Нижнего Новгорода (56, 44).

Expand Down
99 changes: 99 additions & 0 deletions my-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>

<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.15.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
78 changes: 78 additions & 0 deletions my-app/src/main/java/com/mycompany/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.mycompany.app;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import java.time.Duration;
import java.io.FileWriter;
import java.io.PrintWriter;

public class App {

public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:\\Users\\ilya_\\Downloads\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");

WebDriver webDriver = new ChromeDriver();
String generatedPassword = "";
String ipAddress = "";
String forecastTable = "";

try {
System.out.println("\n" + "=".repeat(60));
System.out.println("Задание №1: Генерация пароля");
System.out.println("=".repeat(60));

webDriver.get("https://www.calculator.net/password-generator.html");

WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(10));

WebElement passwordBlock = wait.until(
ExpectedConditions.presenceOfElementLocated(
By.cssSelector("div.verybigtext b"))
);
generatedPassword = passwordBlock.getText();
System.out.println("Сгенерированный пароль: " + generatedPassword);

System.out.println("\n" + "=".repeat(60));
System.out.println("Задание №2: Получение IP-адреса");
System.out.println("=".repeat(60));

ipAddress = Task2.getIpAddress(webDriver);
System.out.println("Ваш IP-адрес: " + ipAddress);

System.out.println("\n" + "=".repeat(60));
System.out.println("Задание №3: Прогноз погоды");
System.out.println("=".repeat(60));

forecastTable = Task3.getWeatherForecast(webDriver);

saveAllResults(generatedPassword, ipAddress, forecastTable);

} catch (Exception e) {
System.out.println("Error");
System.out.println(e.toString());
} finally {
webDriver.quit();
}
}

private static void saveAllResults(String password, String ip, String forecastTable) {
try (PrintWriter writer = new PrintWriter(new FileWriter("../result/forecast.txt"))) {
writer.println("# Результаты выполнения задания ST-7\n");
writer.println("## Задание №1: Генерация пароля\n");
writer.println("Сгенерированный пароль: **" + password + "**\n");
writer.println("Настройки: длина 16, заглавные, строчные, цифры, спецсимволы\n");
writer.println("## Задание №2: Получение IP-адреса\n");
writer.println("Ваш IP-адрес: **" + ip + "**\n");
writer.println("## Задание №3: Прогноз погоды для Нижнего Новгорода (56, 44)\n");
writer.println(forecastTable);
System.out.println("\nРезультаты сохранены в файл: ../result/forecast.txt");
} catch (Exception e) {
System.out.println("Ошибка при сохранении результатов: " + e.getMessage());
}
}
}
28 changes: 28 additions & 0 deletions my-app/src/main/java/com/mycompany/app/Task2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mycompany.app;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

public class Task2 {

public static String getIpAddress(WebDriver webDriver) {
try {
webDriver.get("https://api.ipify.org/?format=json");

WebElement preElement = webDriver.findElement(By.tagName("pre"));
String jsonString = preElement.getText();

JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(jsonString);

return (String) jsonObject.get("ip");

} catch (Exception e) {
System.out.println("Ошибка в Task2: " + e.getMessage());
return null;
}
}
}
59 changes: 59 additions & 0 deletions my-app/src/main/java/com/mycompany/app/Task3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.mycompany.app;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

public class Task3 {

public static String getWeatherForecast(WebDriver webDriver) {
try {
String url = "https://api.open-meteo.com/v1/forecast?latitude=56&longitude=44&hourly=temperature_2m,rain&current=cloud_cover&timezone=Europe%2FMoscow&forecast_days=1&wind_speed_unit=ms";
webDriver.get(url);

WebElement preElement = webDriver.findElement(By.tagName("pre"));
String jsonString = preElement.getText();

JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(jsonString);

JSONObject hourly = (JSONObject) jsonObject.get("hourly");
JSONArray times = (JSONArray) hourly.get("time");
JSONArray temperatures = (JSONArray) hourly.get("temperature_2m");
JSONArray rains = (JSONArray) hourly.get("rain");

System.out.println("\n" + "=".repeat(80));
System.out.println("Прогноз погоды для Нижнего Новгорода (56, 44)");
System.out.println("=".repeat(80));

System.out.printf("%-4s | %-20s | %-12s | %-10s%n", "№", "Дата/время", "Температура", "Осадки (мм)");
System.out.println("-".repeat(60));

StringBuilder table = new StringBuilder();
table.append(String.format("%-4s | %-20s | %-12s | %-10s%n", "№", "Дата/время", "Температура", "Осадки (мм)"));
table.append("-".repeat(60)).append("\n");

for (int i = 0; i < times.size(); i++) {
String time = (String) times.get(i);
Number temp = (Number) temperatures.get(i);
Number rain = (Number) rains.get(i);

String line = String.format("%-4d | %-20s | %-12s | %-10s%n",
(i + 1), time, temp + "°C", rain + " mm");
System.out.print(line);
table.append(line);
}

System.out.println("=".repeat(80));

return table.toString();

} catch (Exception e) {
System.out.println("Ошибка в Task3: " + e.getMessage());
return "Ошибка получения прогноза погоды";
}
}
}
19 changes: 19 additions & 0 deletions my-app/src/test/java/com/mycompany/app/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mycompany.app;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

/**
* Unit test for simple App.
*/
public class AppTest {

/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}
Loading
Loading