Skip to content

Commit

Permalink
Formatting checks
Browse files Browse the repository at this point in the history
  • Loading branch information
arumoy committed May 10, 2021
1 parent 5190768 commit fb093d1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 55 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- -->
</dependencies>

Expand Down
123 changes: 70 additions & 53 deletions src/main/java/io/github/arumoy/covaxxer/config/AppointmentChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
Expand All @@ -21,68 +23,83 @@
@Configuration
@EnableScheduling
public class AppointmentChecker {
private static final Logger LOGGER = LoggerFactory.getLogger(AppointmentChecker.class);
@Resource private TokenHolder holder;
private static final Logger LOGGER = LoggerFactory.getLogger(AppointmentChecker.class);
@Resource
private TokenHolder holder;

@Value("${cowin.ddmm}")
private String date;
@Value("${cowin.district}")
private Integer district;
@Value("${cowin.date}")
private String date;
@Value("${cowin.district}")
private Integer district;

@Autowired private CowinAppointment appointment;
@Autowired
private CowinAppointment appointment;

@Autowired private ObjectMapper objectMapper;
@Autowired
private ApplicationContext context;

@Scheduled(fixedDelay = 60000)
public void scheduleFixedDelayTask() {
VaxCenters centers = appointment.cal(district, date + "-2021", holder.h());
List<VaxCenter> vaxCenters =
centers.getCenters().stream()
.filter(
f ->
f.getSessions().stream()
.anyMatch(m -> m.getMin_age_limit() == 18 && m.getAvailable_capacity() >= 1))
.collect(Collectors.toList());
if (!vaxCenters.isEmpty()) {
if (SystemTray.isSupported()) {
StringBuilder builder = new StringBuilder();
vaxCenters.forEach(center -> {
builder.append(center.getName()).append('-').append(center.getPincode()).append(" on ");
center.getSessions().forEach(session -> builder.append(session.toString()));
builder.append(';');
});
try{
showWinPopUp(builder.toString());
LOGGER.info("{}", builder);
} catch (AWTException e) {
LOGGER.error(e.getMessage());
LOGGER.info("Slot open at {}", builder);
@Autowired
private ObjectMapper objectMapper;

@Scheduled(fixedDelay = 60000)
public void scheduleFixedDelayTask() {
VaxCenters centers = appointment.cal(district, date, holder.h());
List<VaxCenter> vaxCenters =
centers.getCenters().stream()
.filter(
f ->
f.getSessions().stream()
.anyMatch(m -> m.getMin_age_limit() == 18 && m.getAvailable_capacity() >= 1))
.collect(Collectors.toList());
if (!vaxCenters.isEmpty()) {
if (SystemTray.isSupported()) {
StringBuilder builder = new StringBuilder();
vaxCenters.forEach(center -> {
builder.append(center.getName()).append('-').append(center.getPincode()).append(" on ");
center.getSessions().forEach(session -> builder.append(session.toString()));
builder.append(';');
});
try {
showWinPopUp(builder.toString());
LOGGER.info("{}", builder);
} catch (AWTException e) {
LOGGER.error(e.getMessage());
LOGGER.info("Slot open at {}", builder);
}
}
}
}
}
}

private void showWinPopUp(String centers) throws AWTException {
//Obtain only one instance of the SystemTray object
SystemTray tray = SystemTray.getSystemTray();
private void showWinPopUp(String centers) throws AWTException {
//Obtain only one instance of the SystemTray object
SystemTray tray = SystemTray.getSystemTray();

//If the icon is a file
Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
//Alternative (if the icon is on the classpath):
//Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));

//If the icon is a file
Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
//Alternative (if the icon is on the classpath):
//Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("icon.png"));
TrayIcon trayIcon = new TrayIcon(image, "Vaxx");
//Let the system resize the image if needed
trayIcon.setImageAutoSize(true);
//Set tooltip text for the tray icon
trayIcon.setToolTip("Book Vaccine Now");
tray.add(trayIcon);

TrayIcon trayIcon = new TrayIcon(image, "Vaxx");
//Let the system resize the image if needed
trayIcon.setImageAutoSize(true);
//Set tooltip text for the tray icon
trayIcon.setToolTip("Book Vaccine Now");
tray.add(trayIcon);
trayIcon.displayMessage("Vaccine Notification", "Slot open @ " + centers, TrayIcon.MessageType.INFO);
}

trayIcon.displayMessage("Vaccine Notification", "Slot open @ " + centers, TrayIcon.MessageType.INFO);
}
@PostConstruct
private void logDate() {
if (!date.matches("[0-3][0-9]-[0-1][0-9]-202[1-3]")) {
LOGGER.error("Invalid date Format");
SpringApplication.exit(context, () -> 0);
}

@PostConstruct
private void logDate() {
LOGGER.info("Date: {}-2021", date);
}
if (district < 0 || district > 1000) {
LOGGER.error("Invalid district code");
SpringApplication.exit(context, () -> 0);
}
LOGGER.info("Date: {}", date);
}
}
5 changes: 3 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
server:
port: 80
shutdown: graceful


cowin:
ddmm: 07-05
district: 294
date: DD-MM-YYYY
district: DISTRICT
api:
auth-base: https://cdn-api.co-vin.in/api/v2/auth/public
appointment-base: https://cdn-api.co-vin.in/api/v2/appointment/sessions/public

0 comments on commit fb093d1

Please sign in to comment.