<commit_before>package de.dqi11.quickStarter.modules;

import java.net.ConnectException;
import java.util.concurrent.ExecutionException;

import javax.swing.SwingWorker;

import de.dqi11.quickStarter.controller.MainController;
import de.dqi11.quickStarter.controller.Search;
import de.dqi11.quickStarter.helpers.JSONParser;
import de.dqi11.quickStarter.modules.bridges.OpenWeatherMapBridge;

public class WeatherModule extends Module {
	private final String KEY = this.toString();
	
	public WeatherModule(MainController mainController) {
		super(mainController);
	}
	
	@Override
	public ModuleAction getModuleAction(final Search search) throws ConnectException {
		if (search.isCommand("weather")) {
			SwingWorker<ModuleAction, ModuleAction> worker = new SwingWorker<ModuleAction, ModuleAction>() {
				
				@Override
				protected ModuleAction doInBackground() throws Exception {
					String location = search.getParam(0);
					if(location == null) location = "Bremen";
					if(location.split(",").length == 1) location += ",de";
					
					String json = OpenWeatherMapBridge.getJSON(location, 2000);
					String text = "";
					JSONParser jsonParser = new JSONParser(json);
					text = jsonParser.get("name") + ": " + jsonParser.get("main.temp") + "C";
					
					return new ModuleAction(KEY, text);
				}
				
				@Override
				protected void done() {
					try {
						getMainController().updateModule(get());
					} catch (InterruptedException | ExecutionException e) {
						getMainController().updateModule(new WarningModuleAction(KEY, "An error occured."));
					}
					
					super.done();
				}
			};
			worker.execute();
			
			return new LoadingModuleAction(KEY, "Loading weather...");
		}
		
		return null;
	}

}<commit_msg>implemented a loop when an error occurs, to write a " " instead of a "," is possible now<commit_after>package de.dqi11.quickStarter.modules;

import java.net.ConnectException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;

import javax.swing.SwingWorker;

import de.dqi11.quickStarter.controller.MainController;
import de.dqi11.quickStarter.controller.Search;
import de.dqi11.quickStarter.helpers.JSONParser;
import de.dqi11.quickStarter.modules.bridges.OpenWeatherMapBridge;

public class WeatherModule extends Module {
	private final String KEY = this.toString();
	private SwingWorker<ModuleAction, ModuleAction> worker;

	public WeatherModule(MainController mainController) {
		super(mainController);
		worker = new SwingWorker<ModuleAction, ModuleAction>(){
			@Override
			protected ModuleAction doInBackground() throws Exception {
				return null;
			}
		};
	}

	@Override
	public ModuleAction getModuleAction(final Search search) throws ConnectException {

		if (search.isCommand("weather")) {
			try{
				worker.cancel(true);
			}catch(CancellationException e){
				//TODO
			}
			worker = new SwingWorker<ModuleAction, ModuleAction>() {

				@Override
				protected ModuleAction doInBackground() throws Exception {
					String location = search.getParam(0);
					if(location == null) location = "Bremen";
					if(location.split(",").length == 1){
						if (search.getParam(1)!=null) location +=","+search.getParam(1);
						else location += ",de";
					}

					String json = OpenWeatherMapBridge.getJSON(location, 2000);
					String text = "";
					JSONParser jsonParser = new JSONParser(json);
					text = jsonParser.get("name") + ": " + jsonParser.get("main.temp") + "C";
					
					return new ModuleAction(KEY, text);
				}

				@Override
				protected void done() {
					try {
						System.out.println(search.getSearchString());
						getMainController().updateModule(get());
					} catch (InterruptedException | ExecutionException e) {
						getMainController().updateModule(new WarningModuleAction(KEY, "An error occured."));

						try {
							getModuleAction(search);
						} catch (ConnectException e1) {
							e1.printStackTrace();
						}
					}
					super.done();
				}
			};
			worker.execute();

			return new LoadingModuleAction(KEY, "Loading weather...");
		}

		return null;
	}

}
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.008786917256529168, 'mean_word_length': 3.8785714285714286, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 8, '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': '821929', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1168, 'n_words': 258}