Skip to main content

Posts

Showing posts from 2020

Overengineering

... to overengineer or not to overengineer ... There is a simple task: crawl html pages, parse those and return parsed results. Sounds simple and it is. In fact it is just about 40 lines of code including comments public async Task<ActionResult<MeasurementSet>> Get([FromQuery]DateTime? from = null, [FromQuery]DateTime? to = null) { // Defaulting values from ??= DateTime.Today.AddDays(-1); to ??= DateTime.Today; // Defining URLs var query = $"beginn={from:dd.MM.yyyy}&ende={to:dd.MM.yyyy}"; var baseUrl = new Uri("https://BaseURL/"); using (var client = new HttpClient { BaseAddress = baseUrl }) { // Collecting data return Ok(new MeasurementSet { Temperature = await GetMeasures(query, client, "wassertemperatur"), Level = await GetMeasures(query, client, "wasserstand"), }); } } private static async Task<IEnumerable<Measurement>> GetMeasures(string