Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:wolfi323:branches:KDE:Frameworks5
kdebase4-workspace
weather-fix-bbcukmet.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File weather-fix-bbcukmet.patch of Package kdebase4-workspace
From 55644fae34ab49834dd52c834c211e765d41f8ab Mon Sep 17 00:00:00 2001 From: Raphael Geissert <atomo64@gmail.com> Date: Sat, 15 Feb 2014 15:20:26 +0100 Subject: [PATCH 1/3] Update to BBC's new json-based search and modified xml BUG:330773 --- .../weather/ions/bbcukmet/ion_bbcukmet.cpp | 93 ++++++++++++-------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp index 746a734..c656e40 100644 --- a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp +++ b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp @@ -80,6 +80,7 @@ QMap<QString, IonInterface::ConditionIcons> UKMETIon::setupDayIconMappings(void) //dayList["sunny intervals night"] = ClearNight; dayList["partly cloudy"] = PartlyCloudyDay; dayList["cloudy"] = Overcast; + dayList["light cloud"] = Overcast; dayList["white cloud"] = Overcast; dayList["grey cloud"] = Overcast; //dayList["low level cloud"] = NotAvailable; @@ -131,6 +132,7 @@ QMap<QString, IonInterface::ConditionIcons> UKMETIon::setupNightIconMappings(voi nightList["sunny intervals"] = PartlyCloudyDay; // it's not really sunny nightList["sunny"] = ClearDay; nightList["cloudy"] = Overcast; + nightList["light cloud"] = Overcast; nightList["white cloud"] = Overcast; nightList["grey cloud"] = Overcast; nightList["partly cloudy"] = PartlyCloudyNight; @@ -252,7 +254,8 @@ void UKMETIon::getXMLData(const QString& source) void UKMETIon::findPlace(const QString& place, const QString& source) { KUrl url; - url = "http://news.bbc.co.uk/weather/util/search/SearchResultsNode.xhtml?&search=" + place + "®ion=world&startIndex=0&count=500"; + /* There's a page= parameter, results are limited to 10 by page */ + url = "http://www.bbc.com/locator/default/en-GB/search.json?search="+place+"&filter=international&postcode_unit=false&postcode_district=true"; m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); m_job->addMetaData("cookies", "none"); // Disable displaying cookies @@ -281,7 +284,7 @@ void UKMETIon::getFiveDayForecast(const QString& source) int splitIDPos = xmlPath.lastIndexOf('/'); QString stationID = xmlPath.midRef(splitIDPos + 1).toString(); - m_place[source].XMLforecastURL = "http://newsrss.bbc.co.uk/weather/forecast/" + stationID + "/Next3DaysRSS.xml" + xmlMap.query(); + m_place[source].XMLforecastURL = "http://open.live.bbc.co.uk/weather/feeds/en/" + stationID + "/3dayforecast.rss" + xmlMap.query(); KUrl url(m_place[source].XMLforecastURL); m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); @@ -303,47 +306,43 @@ void UKMETIon::readSearchHTMLData(const QString& source, const QByteArray& html) QStringList tokens; QString url; QString tmp; - int flag = 0; int counter = 2; - // "<p><a id="result_40" href ="/weather/forecast/4160?count=200">Vitoria, Brazil</a></p>" - QRegExp grabURL("/[a-z]+/[a-z]+/([0-9]+)(\\?[^\"]+)?"); - QRegExp grabPlace(">([^<]*[a-z()])"); // FIXME: It would be better to strip away the extra '>' +#ifdef __GNUC__ +#warning FIXME: use a json parser instead of regexes +#endif + + QRegExp grabURL("\"id\":\\s*\"([0-9]+)\""); + QRegExp grabPlace("\"fullName\":\\s*\"([^\"]+)\""); while (!stream.atEnd()) { line = stream.readLine(); - if (line.contains("<p class=\"response\">") > 0) { - flag = 1; - } - if (line.contains("There are no forecasts matching") > 0) { + if (line.contains("Sorry, no results found for")) { break; } - if (flag) { + if (line.contains("\"results\"")) { if (grabURL.indexIn(line.trimmed()) > 0) { - url = "http://newsrss.bbc.co.uk/weather/forecast/" + grabURL.cap(1) + "/ObservationsRSS.xml"; - if (grabURL.captureCount() > 1) { - url += grabURL.cap(2); - } - grabPlace.indexIn(line.trimmed()); - tmp = QString("bbcukmet|").append(grabPlace.cap(1)); - // Duplicate places can exist - if (m_locations.contains(tmp)) { - tmp = QString("bbcukmet|").append(QString("%1 (#%2)").arg(grabPlace.cap(1)).arg(counter)); - counter++; - } + for (int captureIndex = 1; captureIndex <= grabURL.captureCount(); captureIndex++) { - m_place[tmp].XMLurl = url; - m_place[tmp].place = grabPlace.cap(1); - m_locations.append(tmp); - } - } + url = "http://open.live.bbc.co.uk/weather/feeds/en/" + grabURL.cap(captureIndex) + "/observations.rss"; + grabPlace.indexIn(line.trimmed()); + tmp = QString("bbcukmet|").append(grabPlace.cap(captureIndex)); + + // Duplicate places can exist + if (m_locations.contains(tmp)) { + tmp = QString("bbcukmet|").append(QString("%1 (#%2)").arg(grabPlace.cap(captureIndex)).arg(counter)); + counter++; + } - if (line.contains("<div class=\"line\">") > 0) { - flag = 0; + m_place[tmp].XMLurl = url; + m_place[tmp].place = grabPlace.cap(captureIndex); + m_locations.append(tmp); + } + } } } @@ -557,12 +556,13 @@ void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, QStringRef conditionData = conditionString.midRef(splitIndex + 1); // Include ':' data.obsTime = conditionString.midRef(0, splitIndex).toString(); - // Friday at 0200 GMT - m_dateFormat = QDateTime::fromString(data.obsTime.split("at")[1].trimmed(), "hhmm 'GMT'"); + // Saturday - 13:00 CET + // Saturday - 12:00 GMT + m_dateFormat = QDateTime::fromString(data.obsTime.split("-")[1].trimmed(), "hh:mm 'GMT'"); data.iconPeriodHour = m_dateFormat.toString("hh").toInt(); data.iconPeriodMinute = m_dateFormat.toString("mm").toInt(); - data.condition = conditionData.toString().split('.')[0].trimmed(); + data.condition = conditionData.toString().split(',')[0].trimmed(); } else if (xml.name() == "link") { m_place[source].forecastHTMLUrl = xml.readElementText(); @@ -575,21 +575,32 @@ void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, #endif data.temperature_C = observeData[1].split(QChar(176))[0].trimmed(); - - // Temperature might be not available - if (data.temperature_C.contains("N/A")) { + if (data.temperature_C.contains("N/A") || data.temperature_C.contains("null")) { data.temperature_C = i18n("N/A"); } data.windDirection = observeData[2].split(',')[0].trimmed(); + if (data.windDirection.contains("null")) { + data.windDirection = ""; + } + data.windSpeed_miles = observeData[3].split(',')[0].split(' ')[1].remove("mph"); + if (data.windSpeed_miles.contains("null")) { + data.windSpeed_miles = "N/A"; + } data.humidity = observeData[4].split(',')[0].split(' ')[1]; if (data.humidity.endsWith('%')) { data.humidity.chop(1); } + if (data.humidity.contains("null")) { + data.humidity = "N/A"; + } data.pressure = observeData[5].split(',')[0].split(' ')[1].split("mb")[0]; + if (data.pressure.contains("null")) { + data.pressure = "N/A"; + } data.pressureTendency = observeData[5].split(',')[1].trimmed(); data.visibilityStr = observeData[6].trimmed(); @@ -600,6 +611,10 @@ void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, } else if (xml.name() == "long") { const QString ordinate = xml.readElementText(); data.longitude = ordinate.toDouble(); + } else if (xml.name() == "georss:point") { + const QString ordinates = xml.readElementText(); + data.latitude = ordinates.split(' ')[0].toDouble(); + data.longitude = ordinates.split(' ')[1].toDouble(); } else { parseUnknownElement(xml); } @@ -675,8 +690,8 @@ void UKMETIon::parseFiveDayForecast(const QString& source, QXmlStreamReader& xml QString line; QString period; QString summary; - QRegExp high("-?\\d+"); - QRegExp low("-?\\d+"); + QRegExp high("-?\\d+.C"); + QRegExp low("-?\\d+.C"); while (!xml.atEnd()) { xml.readNext(); if (xml.name() == "title") { @@ -687,8 +702,8 @@ void UKMETIon::parseFiveDayForecast(const QString& source, QXmlStreamReader& xml period = line.split(',')[0].split(':')[0]; summary = line.split(',')[0].split(':')[1].trimmed(); - high.indexIn(line.split(',')[1]); - low.indexIn(line.split(',')[2]); + high.indexIn(line.split(',')[1].split(':')[1]); + low.indexIn(line.split(',')[1].split(':')[2]); forecast->period = period; forecast->iconName = getWeatherIcon(dayIcons(), summary.toLower()); -- 1.7.10 diff -ur kde-workspace-4.11.7-weather-fix-bbcukmet/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp kde-workspace-4.11.7-weather-fix-bbcukmet-temp/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp --- kde-workspace-4.11.7-weather-fix-bbcukmet/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp 2014-03-16 00:49:44.000000000 +0100 +++ kde-workspace-4.11.7-weather-fix-bbcukmet-temp/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp 2014-03-16 00:53:22.000000000 +0100 @@ -690,8 +690,8 @@ QString line; QString period; QString summary; - QRegExp high("-?\\d+.C"); - QRegExp low("-?\\d+.C"); + QRegExp high("Maximum Temperature: (-?\\d+).C", Qt::CaseInsensitive); + QRegExp low("Minimum Temperature: (-?\\d+).C", Qt::CaseInsensitive); while (!xml.atEnd()) { xml.readNext(); if (xml.name() == "title") { @@ -702,15 +702,22 @@ period = line.split(',')[0].split(':')[0]; summary = line.split(',')[0].split(':')[1].trimmed(); - high.indexIn(line.split(',')[1].split(':')[1]); - low.indexIn(line.split(',')[1].split(':')[2]); + + // Sometimes only one of min or max are reported + if (high.indexIn(line.split(',')[1]) == -1) + forecast->tempHigh = 0; + else + forecast->tempHigh = high.cap(1).toInt(); + + if (low.indexIn(line.split(',')[1]) == -1) + forecast->tempLow = 0; + else + forecast->tempLow = low.cap(1).toInt(); forecast->period = period; forecast->iconName = getWeatherIcon(dayIcons(), summary.toLower()); forecast->summary = i18nc("weather forecast", summary.toUtf8()); kDebug() << "i18n summary string: " << qPrintable(forecast->summary); - forecast->tempHigh = high.cap(0).toInt(); - forecast->tempLow = low.cap(0).toInt(); m_weatherData[source].forecasts.append(forecast); forecast = new WeatherData::ForecastInfo; } diff -ur kde-workspace-4.11.7-weather-fix-bbcukmet-clear-sky/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp kde-workspace-4.11.7-weather-fix-bbcukmet-crash-kde#332392/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp --- kde-workspace-4.11.7-weather-fix-bbcukmet-clear-sky/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp 2014-03-24 02:27:37.000000000 +0100 +++ kde-workspace-4.11.7-weather-fix-bbcukmet-crash-kde#332392/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp 2014-03-25 16:00:40.000000000 +0100 @@ -23,6 +23,13 @@ #include <KIO/Job> #include <KUnitConversion/Converter> +#include <KDateTime> + +WeatherData::WeatherData() + : obsTime("N/A"), iconPeriodHour(12), iconPeriodMinute(0), + longitude(0.), latitude(0.), condition("N/A") +{ +} // ctor, dtor UKMETIon::UKMETIon(QObject *parent, const QVariantList &args) @@ -553,16 +560,31 @@ // Get the observation time and condition int splitIndex = conditionString.lastIndexOf(':'); - QStringRef conditionData = conditionString.midRef(splitIndex + 1); // Include ':' - data.obsTime = conditionString.midRef(0, splitIndex).toString(); + if (splitIndex >= 0) { + QString conditionData = conditionString.mid(splitIndex + 1); // Skip ':' + data.obsTime = conditionString.left(splitIndex); + + if (data.obsTime.contains('-')) { + // Saturday - 13:00 CET + // Saturday - 12:00 GMT + m_dateFormat = KDateTime::fromString(data.obsTime.section('-', 1, 1).trimmed(), + "%H:%M %Z").toLocalZone().dateTime(); + if (m_dateFormat.isValid()) { + data.iconPeriodHour = m_dateFormat.toString("hh").toInt(); + data.iconPeriodMinute = m_dateFormat.toString("mm").toInt(); + } + } else { + m_dateFormat = QDateTime(); + } - // Saturday - 13:00 CET - // Saturday - 12:00 GMT - m_dateFormat = QDateTime::fromString(data.obsTime.split("-")[1].trimmed(), "hh:mm 'GMT'"); - data.iconPeriodHour = m_dateFormat.toString("hh").toInt(); - data.iconPeriodMinute = m_dateFormat.toString("mm").toInt(); + if (conditionData.contains(',')) { + data.condition = conditionData.section(',', 0, 0).trimmed(); - data.condition = conditionData.toString().split(',')[0].trimmed(); + if (data.condition == "null") { + data.condition = "N/A"; + } + } + } } else if (xml.name() == "link") { m_place[source].forecastHTMLUrl = xml.readElementText(); @@ -705,12 +727,12 @@ // Sometimes only one of min or max are reported if (high.indexIn(line.split(',')[1]) == -1) - forecast->tempHigh = 0; + forecast->tempHigh = UNKNOWN_TEMPERATURE; else forecast->tempHigh = high.cap(1).toInt(); if (low.indexIn(line.split(',')[1]) == -1) - forecast->tempLow = 0; + forecast->tempLow = UNKNOWN_TEMPERATURE; else forecast->tempLow = low.cap(1).toInt(); @@ -777,16 +799,21 @@ const double lati = periodLatitude(source); const double longi = periodLongitude(source); - const Plasma::DataEngine::Data timeData = m_timeEngine->query( - QString("Local|Solar|Latitude=%1|Longitude=%2|DateTime=%3") - .arg(lati).arg(longi).arg(m_dateFormat.toString(Qt::ISODate))); - - // Tell applet which icon to use for conditions and provide mapping for condition type to the icons to display - if (timeData["Corrected Elevation"].toDouble() >= 0.0) { - //kDebug() << "Using daytime icons\n"; - data.insert("Condition Icon", getWeatherIcon(dayIcons(), condition(source))); + + if (m_dateFormat.isValid()) { + const Plasma::DataEngine::Data timeData = m_timeEngine->query( + QString("Local|Solar|Latitude=%1|Longitude=%2|DateTime=%3") + .arg(lati).arg(longi).arg(m_dateFormat.toString(Qt::ISODate))); + + // Tell applet which icon to use for conditions and provide mapping for condition type to the icons to display + if (timeData["Corrected Elevation"].toDouble() >= 0.0) { + //kDebug() << "Using daytime icons\n"; + data.insert("Condition Icon", getWeatherIcon(dayIcons(), condition(source))); + } else { + data.insert("Condition Icon", getWeatherIcon(nightIcons(), condition(source))); + } } else { - data.insert("Condition Icon", getWeatherIcon(nightIcons(), condition(source))); + data.insert("Condition Icon", getWeatherIcon(dayIcons(), condition(source))); } data.insert("Latitude", lati); @@ -969,12 +996,22 @@ m_weatherData[source].forecasts[i]->period.replace("Friday", i18nc("Short for Friday", "Fri")); } + int tempHigh = m_weatherData[source].forecasts[i]->tempHigh; + QString tempHighStr = (tempHigh == UNKNOWN_TEMPERATURE) + ? QString::fromLatin1("N/A") + : QString::number(tempHigh); + + int tempLow = m_weatherData[source].forecasts[i]->tempLow; + QString tempLowStr = (tempLow == UNKNOWN_TEMPERATURE) + ? QString::fromLatin1("N/A") + : QString::number(tempLow); + forecastData.append(QString("%1|%2|%3|%4|%5|%6") \ .arg(m_weatherData[source].forecasts[i]->period) \ .arg(m_weatherData[source].forecasts[i]->iconName) \ .arg(m_weatherData[source].forecasts[i]->summary) \ - .arg(m_weatherData[source].forecasts[i]->tempHigh) \ - .arg(m_weatherData[source].forecasts[i]->tempLow) \ + .arg(tempHighStr) \ + .arg(tempLowStr) \ .arg("N/U")); //.arg(m_weatherData[source].forecasts[i]->windSpeed) //arg(m_weatherData[source].forecasts[i]->windDirection)); diff -ur kde-workspace-4.11.7-weather-fix-bbcukmet-clear-sky/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h kde-workspace-4.11.7-weather-fix-bbcukmet-crash-kde#332392/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h --- kde-workspace-4.11.7-weather-fix-bbcukmet-clear-sky/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h 2014-02-28 00:09:20.000000000 +0100 +++ kde-workspace-4.11.7-weather-fix-bbcukmet-crash-kde#332392/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h 2014-03-24 22:34:59.000000000 +0100 @@ -24,6 +24,7 @@ #include <QtXml/QXmlStreamReader> #include <QDateTime> +#include <climits> #include "../ion.h" #include "../dataengineconsumer.h" @@ -39,6 +40,8 @@ { public: + WeatherData(); + QString place; QString stationName; // Current observation information. @@ -171,6 +174,8 @@ QDateTime m_dateFormat; QStringList m_sourcesToReset; + + static const int UNKNOWN_TEMPERATURE = INT_MIN; }; K_EXPORT_PLASMA_DATAENGINE(bbcukmet, UKMETIon) diff -ur kde-workspace-4.11.7-weather-fix-bbcukmet-temp/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp kde-workspace-4.11.7-weather-fix-bbcukmet-clear-sky/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp --- kde-workspace-4.11.7-weather-fix-bbcukmet-temp/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp 2014-03-16 00:53:22.000000000 +0100 +++ kde-workspace-4.11.7-weather-fix-bbcukmet-clear-sky/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp 2014-03-24 02:27:37.000000000 +0100 @@ -75,7 +75,7 @@ dayList["sunny"] = ClearDay; //dayList["sunny night"] = ClearNight; dayList["clear"] = ClearDay; - dayList["clar sky"] = ClearDay; + dayList["clear sky"] = ClearDay; dayList["sunny intervals"] = PartlyCloudyDay; //dayList["sunny intervals night"] = ClearNight; dayList["partly cloudy"] = PartlyCloudyDay; From 558a29efc4c9f055799d23ee6c75464e24489e5a Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" <kossebau@kde.org> Date: Fri, 30 Mar 2018 17:10:32 +0200 Subject: [PATCH] [weather dataengine] Fix BBC provider to adapt to change RSS feed Summary: The urls of the BBC weather feeds seem to have changed, resulting in the dataengine to use no longer existing urls. I could not find the change documented somewhere and also do not know about a contact person with BBC, so done based on examples on website, trial & error. There are some data issues visible in the new data feeds, so chance is the feeds might see more rework and might break things again. But without any contract or formal agreement we can just play catch-up. BUG: 392510 Test Plan: Existing configured weather applets using a location from a BBC weather service work again. Newly configured weather applets using a BBC weather service also work. Reviewers: #plasma, jriddell, cfeck Reviewed By: cfeck Subscribers: cfeck, plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D11808 --- .../weather/ions/bbcukmet/ion_bbcukmet.cpp | 47 ++++++++++++------- .../weather/ions/bbcukmet/ion_bbcukmet.h | 4 +- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp index 6acaa9bb3..fcf0bae8d 100644 --- a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp +++ b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp @@ -218,7 +218,19 @@ bool UKMETIon::updateIonSource(const QString& source) setData(source, "validate", "bbcukmet|malformed"); return true; } - m_place[QString("bbcukmet|%1").arg(sourceAction[2])].XMLurl = sourceAction[3]; + + XMLMapInfo& place = m_place[QString("bbcukmet|%1").arg(sourceAction[2])]; + + // backward compatibility after rss feed url change in 2018/03 + place.sourceExtraArg = sourceAction[3]; + if (place.sourceExtraArg.startsWith(QLatin1String("http://open.live.bbc.co.uk/"))) { + // Old data source id stored the full (now outdated) observation feed url + // http://open.live.bbc.co.uk/weather/feeds/en/STATIOID/observations.rss + // as extra argument, so extract the id from that + place.stationId = place.sourceExtraArg.section(QLatin1Char('/'), -2, -2); + } else { + place.stationId = place.sourceExtraArg; + } getXMLData(QString("%1|%2").arg(sourceAction[0]).arg(sourceAction[2])); return true; } else { @@ -243,7 +255,7 @@ void UKMETIon::getXMLData(const QString& source) } KUrl url; - url = m_place[source].XMLurl; + url = "https://weather-broker-cdn.api.bbci.co.uk/en/observation/rss/" + m_place[source].stationId; m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); m_job->addMetaData("cookies", "none"); // Disable displaying cookies @@ -285,14 +297,7 @@ void UKMETIon::findPlace(const QString& place, const QString& source) void UKMETIon::getFiveDayForecast(const QString& source) { - KUrl xmlMap(m_place[source].forecastHTMLUrl); - - QString xmlPath = xmlMap.path(); - - int splitIDPos = xmlPath.lastIndexOf('/'); - QString stationID = xmlPath.midRef(splitIDPos + 1).toString(); - m_place[source].XMLforecastURL = "http://open.live.bbc.co.uk/weather/feeds/en/" + stationID + "/3dayforecast.rss" + xmlMap.query(); - KUrl url(m_place[source].XMLforecastURL); + KUrl url("https://weather-broker-cdn.api.bbci.co.uk/en/forecast/rss/3day/" + m_place[source].stationId); m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); m_job->addMetaData("cookies", "none"); // Disable displaying cookies @@ -335,7 +340,6 @@ void UKMETIon::readSearchHTMLData(const QString& source, const QByteArray& html) for (int captureIndex = 1; captureIndex <= grabURL.captureCount(); captureIndex++) { - url = "http://open.live.bbc.co.uk/weather/feeds/en/" + grabURL.cap(captureIndex) + "/observations.rss"; grabPlace.indexIn(line.trimmed()); tmp = QString("bbcukmet|").append(grabPlace.cap(captureIndex)); @@ -345,7 +349,7 @@ void UKMETIon::readSearchHTMLData(const QString& source, const QByteArray& html) counter++; } - m_place[tmp].XMLurl = url; + m_place[tmp].stationId = grabURL.cap(captureIndex); m_place[tmp].place = grabPlace.cap(captureIndex); m_locations.append(tmp); } @@ -536,6 +540,9 @@ void UKMETIon::parseWeatherForecast(const QString& source, QXmlStreamReader& xml if (xml.isStartElement()) { if (xml.name() == "item") { parseFiveDayForecast(source, xml); + } else if (xml.name() == "link" && + xml.namespaceUri().isEmpty()) { + m_place[source].forecastHTMLUrl = xml.readElementText(); } else { parseUnknownElement(xml); } @@ -586,9 +593,6 @@ void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, } } - } else if (xml.name() == "link") { - m_place[source].forecastHTMLUrl = xml.readElementText(); - } else if (xml.name() == "description") { QString observeString = xml.readElementText(); QStringList observeData = observeString.split(':'); @@ -762,10 +766,10 @@ void UKMETIon::validate(const QString& source) QString placeList; foreach(const QString &place, m_locations) { if (beginflag) { - placeList.append(QString("%1|extra|%2").arg(place.split('|')[1]).arg(m_place[place].XMLurl)); + placeList.append(QString("%1|extra|%2").arg(place.split('|')[1]).arg(m_place[place].stationId)); beginflag = false; } else { - placeList.append(QString("|place|%1|extra|%2").arg(place.split('|')[1]).arg(m_place[place].XMLurl)); + placeList.append(QString("|place|%1|extra|%2").arg(place.split('|')[1]).arg(m_place[place].stationId)); } } if (m_locations.count() > 1) { @@ -783,17 +787,23 @@ void UKMETIon::updateWeather(const QString& source) { QString weatherSource = source; weatherSource.replace("bbcukmet|", "bbcukmet|weather|"); - weatherSource.append(QString("|%1").arg(m_place[source].XMLurl)); + weatherSource.append(QString("|%1").arg(m_place[source].sourceExtraArg)); QMap<QString, QString> dataFields; QStringList fieldList; QVector<QString> forecastList; int i = 0; Plasma::DataEngine::Data data; - data.insert("Place", place(source)); - data.insert("Station", station(source)); + // work-around for buggy observation RSS feed missing the station name + QString stationName = station(source); + if (stationName.isEmpty() || stationName == QLatin1String(",")) { + stationName = source.section(QLatin1Char('|'), 1, 1); + } + + data.insert("Place", stationName); + data.insert("Station", stationName); data.insert("Observation Period", observationTime(source)); data.insert("Current Conditions", i18nc("weather condition", condition(source).toUtf8())); kDebug() << "i18n condition string: " << qPrintable(i18nc("weather condition", condition(source).toUtf8())); diff --git a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h index a1026f43b..d9d3ad36b 100644 --- a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h +++ b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h @@ -155,10 +155,10 @@ private: void deleteForecasts(); struct XMLMapInfo { + QString stationId; QString place; - QString XMLurl; QString forecastHTMLUrl; - QString XMLforecastURL; + QString sourceExtraArg; }; // Key dicts -- GitLab From 715870b35227ceac9dc3f180e429d7d105fd7bcf Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" <kossebau@kde.org> Date: Sat, 31 Mar 2018 13:53:17 +0200 Subject: [PATCH] [weather] BBCUKMET: add missing "light rain showers"/"heavy rain showers" --- dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp | 4 ++++ dataengines/weather/ions/data/bbcukmet_i18n.dat | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp index fcf0bae8d..d8eed1006 100644 --- a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp +++ b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp @@ -102,12 +102,14 @@ QMap<QString, IonInterface::ConditionIcons> UKMETIon::setupDayIconMappings() con dayList["hazy"] = NotAvailable; dayList["light shower"] = Showers; dayList["light rain shower"] = Showers; + dayList["light rain showers"] = Showers; dayList["light showers"] = Showers; dayList["light rain"] = Showers; dayList["heavy rain"] = Rain; dayList["heavy showers"] = Rain; dayList["heavy shower"] = Rain; dayList["heavy rain shower"] = Rain; + dayList["heavy rain showers"] = Rain; dayList["thundery shower"] = Thunderstorm; dayList["thunder storm"] = Thunderstorm; dayList["cloudy with sleet"] = RainSnow; @@ -152,12 +154,14 @@ QMap<QString, IonInterface::ConditionIcons> UKMETIon::setupNightIconMappings() c nightList["hazy"] = NotAvailable; nightList["light shower"] = Showers; nightList["light rain shower"] = Showers; + nightList["light rain showers"] = Showers; nightList["light showers"] = Showers; nightList["light rain"] = Showers; nightList["heavy rain"] = Rain; nightList["heavy showers"] = Rain; nightList["heavy shower"] = Rain; nightList["heavy rain shower"] = Rain; + nightList["heavy rain showers"] = Rain; nightList["thundery shower"] = Thunderstorm; nightList["thunder storm"] = Thunderstorm; nightList["cloudy with sleet"] = NotAvailable; diff --git a/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat b/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat index 417014822..a15ef09cb 100644 --- a/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat +++ b/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat @@ -17,6 +17,7 @@ weather condition|hail showers weather condition|hazy weather condition|heavy rain weather condition|heavy rain shower +weather condition|heavy rain showers weather condition|heavy shower weather condition|heavy showers weather condition|heavy snow @@ -24,6 +25,7 @@ weather condition|heavy snow showers weather condition|heavy snow showers weather condition|light rain weather condition|light rain shower +weather condition|light rain showers weather condition|light shower weather condition|light showers weather condition|light snow @@ -64,6 +66,7 @@ weather forecast|hail showers weather forecast|hazy weather forecast|heavy rain weather forecast|heavy rain shower +weather forecast|heavy rain showers weather forecast|heavy shower weather forecast|heavy showers weather forecast|heavy snow @@ -71,6 +74,7 @@ weather forecast|heavy snow showers weather forecast|heavy snow showers weather forecast|light rain weather forecast|light rain shower +weather forecast|light rain showers weather forecast|light shower weather forecast|light showers weather forecast|light snow -- GitLab From 96cc6a68a05bde5b203d65bc1272251a741d4dd0 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" <kossebau@kde.org> Date: Wed, 4 Apr 2018 18:39:45 +0200 Subject: [PATCH] [weather] BBCUKMET: add missing "thundery showers" --- dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp | 2 ++ dataengines/weather/ions/data/bbcukmet_i18n.dat | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp index d8eed1006..e863265fe 100644 --- a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp +++ b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp @@ -110,6 +110,7 @@ QMap<QString, IonInterface::ConditionIcons> UKMETIon::setupDayIconMappings() con dayList["heavy rain shower"] = Rain; dayList["heavy rain showers"] = Rain; dayList["thundery shower"] = Thunderstorm; + dayList["thundery showers"] = Thunderstorm; dayList["thunder storm"] = Thunderstorm; dayList["cloudy with sleet"] = RainSnow; dayList["sleet shower"] = RainSnow; @@ -160,6 +161,7 @@ QMap<QString, IonInterface::ConditionIcons> UKMETIon::setupNightIconMappings() c nightList["heavy rain shower"] = Rain; nightList["heavy rain showers"] = Rain; nightList["thundery shower"] = Thunderstorm; + nightList["thundery showers"] = Thunderstorm; nightList["thunder storm"] = Thunderstorm; nightList["cloudy with sleet"] = NotAvailable; nightList["sleet shower"] = NotAvailable; diff --git a/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat b/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat index a15ef09cb..8f6c09d9e 100644 --- a/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat +++ b/plasma/generic/dataengines/weather/ions/data/bbcukmet_i18n.dat @@ -45,6 +45,7 @@ weather condition|sunny intervals weather condition|sunny intervals weather condition|thunder storm weather condition|thundery shower +weather condition|thundery showers weather condition|tropical storm weather condition|white cloud weather forecast|clear sky @@ -93,6 +94,7 @@ weather forecast|sunny intervals weather forecast|sunny intervals weather forecast|thunder storm weather forecast|thundery shower +weather forecast|thundery showers weather forecast|tropical storm weather forecast|white cloud wind direction|N -- GitLab From 500e061366c66e2537f83278585717779addd63b Mon Sep 17 00:00:00 2001 From: Joe Dight <joe.dight@ntmail.uk> Date: Thu, 10 Jun 2021 17:03:40 +0100 Subject: [PATCH] Point bbcukmet to new location API BUG: 430643 --- .../weather/ions/bbcukmet/ion_bbcukmet.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp index c0812b85d..dc121cfee 100644 --- a/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp +++ b/plasma/generic/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp @@ -261,8 +261,7 @@ void UKMETIon::getXMLData(const QString &source) void UKMETIon::findPlace(const QString& place, const QString& source) { KUrl url; - /* There's a page= parameter, results are limited to 10 by page */ - url = "http://www.bbc.com/locator/default/en-GB/search.json?search="+place+"&filter=international&postcode_unit=false&postcode_district=true"; + url = "https://open.live.bbc.co.uk/locator/locations?s=" + place + "&format=json"; m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); m_job->addMetaData("cookies", "none"); // Disable displaying cookies @@ -320,7 +319,9 @@ #endif QRegExp grabURL("\"id\":\\s*\"([0-9]+)\""); - QRegExp grabPlace("\"fullName\":\\s*\"([^\"]+)\""); + QRegExp grabPlace("\"name\":\\s*\"([^\"]+)\""); + QRegExp grabArea("\"container\":\\s*\"([^\"]+)\""); + QRegExp grabCountry("\"country\":\\s*\"([^\"]+)\""); while (!stream.atEnd()) { line = stream.readLine(); @@ -329,23 +330,26 @@ void UKMETIon::readSearchHTMLData(const QString &source, const QByteArray &html) break; } - if (line.contains("\"results\"")) { + if (line.contains("\"locations\"")) { if (grabURL.indexIn(line.trimmed()) > 0) { for (int captureIndex = 1; captureIndex <= grabURL.captureCount(); captureIndex++) { grabPlace.indexIn(line.trimmed()); - tmp = QString("bbcukmet|").append(grabPlace.cap(captureIndex)); + grabArea.indexIn(line.trimmed()); + grabCountry.indexIn(line.trimmed()); + const QString fullName = grabPlace.cap(captureIndex) + ", " + grabArea.cap(captureIndex) + ", " + grabCountry.cap(captureIndex); + tmp = QString("bbcukmet|").append(fullName); // Duplicate places can exist if (m_locations.contains(tmp)) { - tmp = QString("bbcukmet|").append(QString("%1 (#%2)").arg(grabPlace.cap(captureIndex)).arg(counter)); + tmp = QString("bbcukmet|").append(QString("%1 (#%2)").arg(fullName).arg(counter)); counter++; } m_place[tmp].stationId = grabURL.cap(captureIndex); - m_place[tmp].place = grabPlace.cap(captureIndex); + m_place[tmp].place = fullName; m_locations.append(tmp); } } -- GitLab
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor