Changeset View
Changeset View
Standalone View
Standalone View
dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Line(s) | 244 | { | |||
---|---|---|---|---|---|
261 | } | 261 | } | ||
262 | 262 | | |||
263 | if (sourceAction[1] == QLatin1String("weather") && sourceAction.size() >= 3) { | 263 | if (sourceAction[1] == QLatin1String("weather") && sourceAction.size() >= 3) { | ||
264 | if (sourceAction.count() >= 3) { | 264 | if (sourceAction.count() >= 3) { | ||
265 | if (sourceAction[2].isEmpty()) { | 265 | if (sourceAction[2].isEmpty()) { | ||
266 | setData(source, QStringLiteral("validate"), QStringLiteral("bbcukmet|malformed")); | 266 | setData(source, QStringLiteral("validate"), QStringLiteral("bbcukmet|malformed")); | ||
267 | return true; | 267 | return true; | ||
268 | } | 268 | } | ||
269 | m_place[QStringLiteral("bbcukmet|") +sourceAction[2]].XMLurl = sourceAction[3]; | 269 | | ||
270 | XMLMapInfo& place = m_place[QStringLiteral("bbcukmet|") + sourceAction[2]]; | ||||
cfeck: Space after + | |||||
271 | | ||||
272 | // backward compatibility after rss feed url change in 2018/03 | ||||
273 | place.sourceExtraArg = sourceAction[3]; | ||||
274 | if (place.sourceExtraArg.startsWith(QLatin1String("http://open.live.bbc.co.uk/"))) { | ||||
275 | // Old data source id stored the full (now outdated) observation feed url | ||||
276 | // http://open.live.bbc.co.uk/weather/feeds/en/STATIOID/observations.rss | ||||
277 | // as extra argument, so extract the id from that | ||||
278 | place.stationId = place.sourceExtraArg.section(QLatin1Char('/'), -2, -2); | ||||
279 | } else { | ||||
280 | place.stationId = place.sourceExtraArg; | ||||
281 | } | ||||
270 | getXMLData(sourceAction[0] + QLatin1Char('|') + sourceAction[2]); | 282 | getXMLData(sourceAction[0] + QLatin1Char('|') + sourceAction[2]); | ||
271 | return true; | 283 | return true; | ||
272 | } | 284 | } | ||
273 | return false; | 285 | return false; | ||
274 | 286 | | |||
275 | } | 287 | } | ||
276 | 288 | | |||
277 | setData(source, QStringLiteral("validate"), QStringLiteral("bbcukmet|malformed")); | 289 | setData(source, QStringLiteral("validate"), QStringLiteral("bbcukmet|malformed")); | ||
278 | return true; | 290 | return true; | ||
279 | } | 291 | } | ||
280 | 292 | | |||
281 | // Gets specific city XML data | 293 | // Gets specific city XML data | ||
282 | void UKMETIon::getXMLData(const QString& source) | 294 | void UKMETIon::getXMLData(const QString& source) | ||
283 | { | 295 | { | ||
284 | for (const QString& fetching : qAsConst(m_obsJobList)) { | 296 | for (const QString& fetching : qAsConst(m_obsJobList)) { | ||
285 | if (fetching == source) { | 297 | if (fetching == source) { | ||
286 | // already getting this source and awaiting the data | 298 | // already getting this source and awaiting the data | ||
287 | return; | 299 | return; | ||
288 | } | 300 | } | ||
289 | } | 301 | } | ||
290 | 302 | | |||
291 | const QUrl url(m_place[source].XMLurl); | 303 | const QUrl url(QStringLiteral("https://weather-broker-cdn.api.bbci.co.uk/en/observation/rss/") + m_place[source].stationId); | ||
292 | 304 | | |||
293 | KIO::TransferJob* getJob = KIO::get(url, KIO::Reload, KIO::HideProgressInfo); | 305 | KIO::TransferJob* getJob = KIO::get(url, KIO::Reload, KIO::HideProgressInfo); | ||
294 | getJob->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); // Disable displaying cookies | 306 | getJob->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); // Disable displaying cookies | ||
295 | m_obsJobXml.insert(getJob, new QXmlStreamReader); | 307 | m_obsJobXml.insert(getJob, new QXmlStreamReader); | ||
296 | m_obsJobList.insert(getJob, source); | 308 | m_obsJobList.insert(getJob, source); | ||
297 | 309 | | |||
298 | connect(getJob, &KIO::TransferJob::data, | 310 | connect(getJob, &KIO::TransferJob::data, | ||
299 | this, &UKMETIon::observation_slotDataArrived); | 311 | this, &UKMETIon::observation_slotDataArrived); | ||
Show All 23 Lines | 333 | /* | |||
323 | connect(getJob, SIGNAL(redirection(KIO::Job*,KUrl)), | 335 | connect(getJob, SIGNAL(redirection(KIO::Job*,KUrl)), | ||
324 | this, SLOT(setup_slotRedirected(KIO::Job*,KUrl))); | 336 | this, SLOT(setup_slotRedirected(KIO::Job*,KUrl))); | ||
325 | */ | 337 | */ | ||
326 | } | 338 | } | ||
327 | 339 | | |||
328 | void UKMETIon::getFiveDayForecast(const QString& source) | 340 | void UKMETIon::getFiveDayForecast(const QString& source) | ||
329 | { | 341 | { | ||
330 | XMLMapInfo& place = m_place[source]; | 342 | XMLMapInfo& place = m_place[source]; | ||
331 | QUrl xmlMap(place.forecastHTMLUrl); | | |||
332 | | ||||
333 | const QString stationID = xmlMap.path().section(QLatin1Char('/'), -1); | | |||
334 | | ||||
335 | place.XMLforecastURL = QStringLiteral("http://open.live.bbc.co.uk/weather/feeds/en/") + stationID + QStringLiteral("/3dayforecast.rss") + xmlMap.query(); | | |||
336 | 343 | | |||
337 | const QUrl url(place.XMLforecastURL); | 344 | const QUrl url(QStringLiteral("https://weather-broker-cdn.api.bbci.co.uk/en/forecast/rss/3day/") + place.stationId); | ||
338 | 345 | | |||
339 | KIO::TransferJob* getJob = KIO::get(url, KIO::Reload, KIO::HideProgressInfo); | 346 | KIO::TransferJob* getJob = KIO::get(url, KIO::Reload, KIO::HideProgressInfo); | ||
340 | getJob->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); // Disable displaying cookies | 347 | getJob->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); // Disable displaying cookies | ||
341 | m_forecastJobXml.insert(getJob, new QXmlStreamReader); | 348 | m_forecastJobXml.insert(getJob, new QXmlStreamReader); | ||
342 | m_forecastJobList.insert(getJob, source); | 349 | m_forecastJobList.insert(getJob, source); | ||
343 | 350 | | |||
344 | connect(getJob, &KIO::TransferJob::data, | 351 | connect(getJob, &KIO::TransferJob::data, | ||
345 | this, &UKMETIon::forecast_slotDataArrived); | 352 | this, &UKMETIon::forecast_slotDataArrived); | ||
Show All 11 Lines | 363 | if (!jsonDocumentObject.isEmpty()) { | |||
357 | const QJsonArray results = jsonDocumentObject.value(QStringLiteral("results")).toArray(); | 364 | const QJsonArray results = jsonDocumentObject.value(QStringLiteral("results")).toArray(); | ||
358 | 365 | | |||
359 | for (const QJsonValue& resultValue : results) { | 366 | for (const QJsonValue& resultValue : results) { | ||
360 | QJsonObject result = resultValue.toObject(); | 367 | QJsonObject result = resultValue.toObject(); | ||
361 | const QString id = result.value(QStringLiteral("id")).toString(); | 368 | const QString id = result.value(QStringLiteral("id")).toString(); | ||
362 | const QString fullName = result.value(QStringLiteral("fullName")).toString(); | 369 | const QString fullName = result.value(QStringLiteral("fullName")).toString(); | ||
363 | 370 | | |||
364 | if (!id.isEmpty() && !fullName.isEmpty()) { | 371 | if (!id.isEmpty() && !fullName.isEmpty()) { | ||
365 | const QString url = QStringLiteral("http://open.live.bbc.co.uk/weather/feeds/en/") + id + QStringLiteral("/observations.rss"); | | |||
366 | | ||||
367 | QString tmp = QStringLiteral("bbcukmet|") + fullName; | 372 | QString tmp = QStringLiteral("bbcukmet|") + fullName; | ||
368 | 373 | | |||
369 | // Duplicate places can exist | 374 | // Duplicate places can exist | ||
370 | if (m_locations.contains(tmp)) { | 375 | if (m_locations.contains(tmp)) { | ||
371 | tmp += QStringLiteral(" (#") + QString::number(counter) + QLatin1Char(')'); | 376 | tmp += QStringLiteral(" (#") + QString::number(counter) + QLatin1Char(')'); | ||
372 | counter++; | 377 | counter++; | ||
373 | } | 378 | } | ||
374 | XMLMapInfo& place = m_place[tmp]; | 379 | XMLMapInfo& place = m_place[tmp]; | ||
375 | place.XMLurl = url; | 380 | place.stationId = id; | ||
376 | place.place = fullName; | 381 | place.place = fullName; | ||
377 | m_locations.append(tmp); | 382 | m_locations.append(tmp); | ||
378 | } | 383 | } | ||
379 | } | 384 | } | ||
380 | } | 385 | } | ||
381 | 386 | | |||
382 | validate(source); | 387 | validate(source); | ||
383 | } | 388 | } | ||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | 557 | while (!xml.atEnd()) { | |||
556 | 561 | | |||
557 | if (xml.isEndElement() && elementName == QLatin1String("channel")) { | 562 | if (xml.isEndElement() && elementName == QLatin1String("channel")) { | ||
558 | break; | 563 | break; | ||
559 | } | 564 | } | ||
560 | 565 | | |||
561 | if (xml.isStartElement()) { | 566 | if (xml.isStartElement()) { | ||
562 | if (elementName == QLatin1String("item")) { | 567 | if (elementName == QLatin1String("item")) { | ||
563 | parseFiveDayForecast(source, xml); | 568 | parseFiveDayForecast(source, xml); | ||
569 | } else if (elementName == QLatin1String("link") && | ||||
570 | xml.namespaceUri().isEmpty()) { | ||||
571 | m_place[source].forecastHTMLUrl = xml.readElementText(); | ||||
564 | } else { | 572 | } else { | ||
565 | parseUnknownElement(xml); | 573 | parseUnknownElement(xml); | ||
566 | } | 574 | } | ||
567 | } | 575 | } | ||
568 | } | 576 | } | ||
569 | } | 577 | } | ||
570 | 578 | | |||
571 | void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml) | 579 | void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml) | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 646 | if (conditionData.contains(QLatin1Char(','))) { | |||
639 | data.condition = conditionData.section(QLatin1Char(','), 0, 0).trimmed(); | 647 | data.condition = conditionData.section(QLatin1Char(','), 0, 0).trimmed(); | ||
640 | 648 | | |||
641 | if (data.condition == QLatin1String("null")) { | 649 | if (data.condition == QLatin1String("null")) { | ||
642 | data.condition.clear(); | 650 | data.condition.clear(); | ||
643 | } | 651 | } | ||
644 | } | 652 | } | ||
645 | } | 653 | } | ||
646 | 654 | | |||
647 | } else if (elementName == QLatin1String("link")) { | | |||
648 | m_place[source].forecastHTMLUrl = xml.readElementText(); | | |||
649 | | ||||
650 | } else if (elementName == QLatin1String("description")) { | 655 | } else if (elementName == QLatin1String("description")) { | ||
651 | QString observeString = xml.readElementText(); | 656 | QString observeString = xml.readElementText(); | ||
652 | const QStringList observeData = observeString.split(QLatin1Char(':')); | 657 | const QStringList observeData = observeString.split(QLatin1Char(':')); | ||
653 | 658 | | |||
654 | // FIXME: We should make this use a QRegExp but I need some help here :) -spstarr | 659 | // FIXME: We should make this use a QRegExp but I need some help here :) -spstarr | ||
655 | 660 | | |||
656 | QString temperature_C = observeData[1].section(QChar(176), 0, 0).trimmed(); | 661 | QString temperature_C = observeData[1].section(QChar(176), 0, 0).trimmed(); | ||
657 | parseFloat(data.temperature_C, temperature_C); | 662 | parseFloat(data.temperature_C, temperature_C); | ||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Line(s) | 870 | setData(source, QStringLiteral("validate"), | |||
866 | QVariant(QStringLiteral("bbcukmet|invalid|multiple|") + invalidPlace)); | 871 | QVariant(QStringLiteral("bbcukmet|invalid|multiple|") + invalidPlace)); | ||
867 | } | 872 | } | ||
868 | return; | 873 | return; | ||
869 | } | 874 | } | ||
870 | 875 | | |||
871 | QString placeList; | 876 | QString placeList; | ||
872 | for (const QString& place : qAsConst(m_locations)) { | 877 | for (const QString& place : qAsConst(m_locations)) { | ||
873 | const QString p = place.section(QLatin1Char('|'), 1, 1); | 878 | const QString p = place.section(QLatin1Char('|'), 1, 1); | ||
874 | placeList.append(QStringLiteral("|place|") + p + QStringLiteral("|extra|") + m_place[place].XMLurl); | 879 | placeList.append(QStringLiteral("|place|") + p + QStringLiteral("|extra|") + m_place[place].stationId); | ||
875 | } | 880 | } | ||
876 | if (m_locations.count() > 1) { | 881 | if (m_locations.count() > 1) { | ||
877 | setData(source, QStringLiteral("validate"), | 882 | setData(source, QStringLiteral("validate"), | ||
878 | QVariant(QStringLiteral("bbcukmet|valid|multiple") + placeList)); | 883 | QVariant(QStringLiteral("bbcukmet|valid|multiple") + placeList)); | ||
879 | } else { | 884 | } else { | ||
880 | placeList[7] = placeList[7].toUpper(); | 885 | placeList[7] = placeList[7].toUpper(); | ||
881 | setData(source, QStringLiteral("validate"), | 886 | setData(source, QStringLiteral("validate"), | ||
882 | QVariant(QStringLiteral("bbcukmet|valid|single") + placeList)); | 887 | QVariant(QStringLiteral("bbcukmet|valid|single") + placeList)); | ||
Show All 9 Lines | 896 | if (weatherData.isForecastsDataPending || weatherData.isSolarDataPending) { | |||
892 | return; | 897 | return; | ||
893 | } | 898 | } | ||
894 | 899 | | |||
895 | const XMLMapInfo& place = m_place[source]; | 900 | const XMLMapInfo& place = m_place[source]; | ||
896 | 901 | | |||
897 | QString weatherSource = source; | 902 | QString weatherSource = source; | ||
898 | // TODO: why the replacement here instead of just a new string? | 903 | // TODO: why the replacement here instead of just a new string? | ||
899 | weatherSource.replace(QStringLiteral("bbcukmet|"), QStringLiteral("bbcukmet|weather|")); | 904 | weatherSource.replace(QStringLiteral("bbcukmet|"), QStringLiteral("bbcukmet|weather|")); | ||
900 | weatherSource.append(QLatin1Char('|') + place.XMLurl); | 905 | weatherSource.append(QLatin1Char('|') + place.sourceExtraArg); | ||
901 | 906 | | |||
902 | Plasma::DataEngine::Data data; | 907 | Plasma::DataEngine::Data data; | ||
903 | 908 | | |||
904 | data.insert(QStringLiteral("Place"), weatherData.stationName); | 909 | // work-around for buggy observation RSS feed missing the station name | ||
905 | data.insert(QStringLiteral("Station"), weatherData.stationName); | 910 | QString stationName = weatherData.stationName; | ||
911 | if (stationName.isEmpty() || stationName == QLatin1String(",")) { | ||||
912 | stationName = source.section(QLatin1Char('|'), 1, 1); | ||||
913 | } | ||||
914 | | ||||
915 | data.insert(QStringLiteral("Place"), stationName); | ||||
916 | data.insert(QStringLiteral("Station"), stationName); | ||||
906 | if (weatherData.observationDateTime.isValid()) { | 917 | if (weatherData.observationDateTime.isValid()) { | ||
907 | data.insert(QStringLiteral("Observation Timestamp"), weatherData.observationDateTime); | 918 | data.insert(QStringLiteral("Observation Timestamp"), weatherData.observationDateTime); | ||
908 | } | 919 | } | ||
909 | if (!weatherData.obsTime.isEmpty()) { | 920 | if (!weatherData.obsTime.isEmpty()) { | ||
910 | data.insert(QStringLiteral("Observation Period"), weatherData.obsTime); | 921 | data.insert(QStringLiteral("Observation Period"), weatherData.obsTime); | ||
911 | } | 922 | } | ||
912 | if (!weatherData.condition.isEmpty()) { | 923 | if (!weatherData.condition.isEmpty()) { | ||
913 | // db uses original strings normalized to lowercase, but we prefer the unnormalized if without translation | 924 | // db uses original strings normalized to lowercase, but we prefer the unnormalized if without translation | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |
Space after +