<commit_before>package net.kedare.iot.leds;

import com.qmetric.spark.authentication.AuthenticationDetails;
import com.qmetric.spark.authentication.BasicAuthenticationFilter;
import net.kedare.iot.particle.ParticleException;
import org.json.JSONObject;
import spark.servlet.SparkApplication;

import java.util.logging.Level;
import java.util.logging.Logger;

import static spark.Spark.*;

public class LedStripApplication implements SparkApplication {

    private LedStrip ledStrip;
    private String token;
    private String deviceId;
    private Logger logger;

    public LedStripApplication() {
        this.token = System.getenv("LED_CONTROLLER_TOKEN");
        this.deviceId = System.getenv("LED_CONTROLLER_DEVICE");

        this.logger = Logger.getLogger(LedStripApplication.class.getName());

        try {
            this.ledStrip = new LedStrip(token, deviceId, logger);
        } catch (ParticleException exception) {
            logger.log(Level.SEVERE, "Fail to initialize Particle", exception);
        }
    }

    public static void main(String[] args) throws Exception {
        int configuredPort;
        try {
            configuredPort = Integer.valueOf(System.getenv("PORT"));
        } catch (Exception e) {
            configuredPort = 80;
        }
        port(configuredPort);
        LedStripApplication controller = new LedStripApplication();
        controller.init();
    }

    public void init() {

        externalStaticFileLocation("target/static");

        before(new BasicAuthenticationFilter("/*", new AuthenticationDetails(System.getenv("LED_CONTROLLER_USER"), System.getenv("LED_CONTROLLER_PASS"))));

        // Modes list
        get("/api/modes", (req, res) -> {
            res.type("application/json");
            return new JSONObject(LedStrip.PROGRAMS);
        });

        // GET/SET mode
        get("/api/mode", (req, res) -> {
            res.type("application/json");
            return this.ledStrip.getMode();
        });
<commit_msg>Add environment variable check<commit_after>package net.kedare.iot.leds;

import com.qmetric.spark.authentication.AuthenticationDetails;
import com.qmetric.spark.authentication.BasicAuthenticationFilter;
import net.kedare.iot.particle.ParticleException;
import org.json.JSONObject;
import spark.servlet.SparkApplication;

import java.util.logging.Level;
import java.util.logging.Logger;

import static spark.Spark.*;

public class LedStripApplication implements SparkApplication {

    private LedStrip ledStrip;
    private String token;
    private String deviceId;
    private String user;
    private String password;
    private Logger logger;

    public LedStripApplication() throws Exception {
        this.token = System.getenv("LED_CONTROLLER_TOKEN");
        this.deviceId = System.getenv("LED_CONTROLLER_DEVICE");
        this.user = System.getenv("LED_CONTROLLER_USER");
        this.password = System.getenv("LED_CONTROLLER_PASS");

        this.logger = Logger.getLogger(LedStripApplication.class.getName());

        if (this.token == null || this.deviceId == null || this.user == null || this.password == null) {
            logger.log(Level.SEVERE, "Please make sure all the required environment variables are configured : ");
            logger.log(Level.SEVERE, "LED_CONTROLLER_TOKEN, LED_CONTROLLER_DEVICE, LED_CONTROLLER_USER, LED_CONTROLLER_PASS");
            throw new Exception("Missing environment variables");
        }

        try {
            this.ledStrip = new LedStrip(token, deviceId, logger);
        } catch (ParticleException exception) {
            logger.log(Level.SEVERE, "Fail to initialize Particle", exception);
        }
    }

    public static void main(String[] args) throws Exception {
        int configuredPort;
        try {
            configuredPort = Integer.valueOf(System.getenv("PORT"));
        } catch (Exception e) {
            configuredPort = 80;
        }
        port(configuredPort);
        LedStripApplication controller = new LedStripApplication();
        controller.init();
    }

    public void init() {
        externalStaticFileLocation("target/static");
        before(new BasicAuthenticationFilter("/*", new AuthenticationDetails(this.user, this.password)));

        // Modes list
        get("/api/modes", (req, res) -> {
            res.type("application/json");
            return new JSONObject(LedStrip.PROGRAMS);
        });

        // GET/SET mode
        get("/api/mode", (req, res) -> {
            res.type("application/json");
            return this.ledStrip.getMode();
        });

{'fraction_non_alphanumeric': 0.11001749781277341, 'fraction_numerical': 0.0008748906386701663, 'mean_word_length': 2.8952299829642247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7318549', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1242, 'n_words': 261}