Skip to content

Commit

Permalink
Update app
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuSoysal authored Apr 28, 2023
1 parent 748b6e7 commit 1f968c6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/io/github/mathieusoysal/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class App {
private static final String ENV_NAME_PASSWORD = "TEST_PASSWORD";
private static final String ENV_NAME_MAIL = "TEST_EMAIL";
private static final Logger LOGGER = Logger.getLogger();
private static double startTime;

public static void main(String[] args) {
try (Roboto roboto = new Roboto()) {
checkAllEnvVariables(ENV_NAME_MAIL, ENV_NAME_PASSWORD);
roboto.connect(System.getenv(ENV_NAME_MAIL), System.getenv(ENV_NAME_PASSWORD));
roboto.refreshPage();
while (!roboto.checkinButtonIsPresent())
while (!roboto.checkinButtonIsPresent() && !fiftenMinutesPassed())
roboto.refreshPage();
roboto.clickOnSubscription();
} catch (RobotoException e) {
System.out.println(e.getMessage());
} catch (EnvironementVariableNotFoundException e) {
Expand All @@ -29,6 +29,12 @@ public static void main(String[] args) {
}
}

static boolean fiftenMinutesPassed() {
if (startTime == 0)
startTime = System.currentTimeMillis();
return System.currentTimeMillis() - startTime > 15 * 60 * 1000;
}

static void checkAllEnvVariables(String... envNames) throws EnvironementVariableNotFoundException {
var notFound = new ArrayList<String>();
for (String name : envNames) {
Expand Down

0 comments on commit 1f968c6

Please sign in to comment.