8 #include <QApplication>
23 const QString& program)
25 QStringList arguments(
"-t");
26 const QString loc = QString(
"WeatherSource::ProbeTypes(%1 %2): ")
27 .arg(program).arg(arguments.join(
" "));
37 LOG(VB_GENERAL, LOG_ERR, loc +
"Cannot run script");
41 QByteArray result = ms.
ReadAll();
42 QTextStream text(result);
46 QString
tmp = text.readLine();
48 while (
tmp.endsWith(
'\n') ||
tmp.endsWith(
'\r'))
56 LOG(VB_GENERAL, LOG_ERR, loc +
"Invalid output from -t option");
62 const QString& program,
66 QStringList arguments(
"-T");
67 const QString loc = QString(
"WeatherSource::ProbeTimeouts(%1 %2): ")
68 .arg(program).arg(arguments.join(
" "));
80 LOG(VB_GENERAL, LOG_ERR, loc +
"Cannot run script");
84 QByteArray result = ms.
ReadAll();
85 QTextStream text(result);
90 QString
tmp = text.readLine();
92 while (
tmp.endsWith(
'\n') ||
tmp.endsWith(
'\r'))
101 LOG(VB_GENERAL, LOG_ERR, loc +
"Invalid Script Output! No Lines");
105 QStringList temp = lines[0].split(
',');
106 if (temp.size() != 2)
108 LOG(VB_GENERAL, LOG_ERR, loc +
109 QString(
"Invalid Script Output! '%1'").
arg(lines[0]));
113 std::array<bool,2> isOK {};
114 uint ut = temp[0].toUInt(&isOK[0]);
115 uint st = temp[1].toUInt(&isOK[1]);
116 if (!isOK[0] || !isOK[1])
118 LOG(VB_GENERAL, LOG_ERR, loc +
119 QString(
"Invalid Script Output! '%1'").
arg(lines[0]));
131 QStringList arguments(
"-v");
133 const QString loc = QString(
"WeatherSource::ProbeInfo(%1 %2): ")
134 .arg(info.
program).arg(arguments.join(
" "));
143 LOG(VB_GENERAL, LOG_ERR, loc +
"Cannot run script");
147 QByteArray result = ms.
ReadAll();
148 QTextStream text(result);
151 while (!text.atEnd())
153 QString
tmp = text.readLine();
155 while (
tmp.endsWith(
'\n') ||
tmp.endsWith(
'\r'))
164 LOG(VB_GENERAL, LOG_ERR, loc +
"Invalid Script Output! No Lines");
168 QStringList temp = lines[0].split(
',');
169 if (temp.size() != 4)
171 LOG(VB_GENERAL, LOG_ERR, loc +
172 QString(
"Invalid Script Output! '%1'").
arg(lines[0]));
179 info.
email = temp[3];
198 if (!fi.isReadable() || !fi.isExecutable())
202 info.
path = fi.absolutePath();
203 info.
program = fi.absoluteFilePath();
210 "SELECT sourceid, source_name, update_timeout, retrieve_timeout, "
211 "path, author, version, email, types FROM weathersourcesettings "
212 "WHERE hostname = :HOST AND source_name = :NAME;";
219 LOG(VB_GENERAL, LOG_ERR,
"Invalid response from database");
231 QString dbver = db.
value(6).toString();
234 info.
types = db.
value(8).toString().split(
",");
239 LOG(VB_GENERAL, LOG_INFO,
"New version of " + info.
name +
" found");
240 query =
"UPDATE weathersourcesettings SET source_name = :NAME, "
241 "path = :PATH, author = :AUTHOR, version = :VERSION, "
242 "email = :EMAIL, types = :TYPES WHERE sourceid = :ID";
267 query =
"INSERT INTO weathersourcesettings "
268 "(hostname, source_name, update_timeout, retrieve_timeout, "
269 "path, author, version, email, types) "
270 "VALUES (:HOST, :NAME, :UPDATETO, :RETTO, :PATH, :AUTHOR, "
271 ":VERSION, :EMAIL, :TYPES);";
296 query =
"SELECT sourceid FROM weathersourcesettings "
297 "WHERE source_name = :NAME AND hostname = :HOST;";
310 LOG(VB_GENERAL, LOG_ERR,
"Error getting weather sourceid");
326 : m_ready(info != nullptr),
327 m_inuse(info != nullptr),
329 m_updateTimer(new QTimer(this))
332 if (!
dir.exists(
"MythWeather"))
333 dir.mkdir(
"MythWeather");
334 dir.cd(
"MythWeather");
335 if (info !=
nullptr) {
370 disconnect(
this,
nullptr, ws,
nullptr);
381 const QString loc = QString(
"WeatherSource::getLocationList(%1 %2): ")
382 .arg(program).arg(
args.join(
" "));
392 LOG(VB_GENERAL, LOG_ERR, loc +
"Cannot run script");
393 return QStringList();
397 QByteArray result = ms.
ReadAll();
398 QTextStream text(result);
400 QTextCodec *codec = QTextCodec::codecForName(
"UTF-8");
401 while (!text.atEnd())
403 QString
tmp = text.readLine();
405 while (
tmp.endsWith(
'\n') ||
tmp.endsWith(
'\r'))
410 QString loc_string = codec->toUnicode(
tmp.toUtf8());
423 LOG(VB_GENERAL, LOG_INFO,
"Starting update of " +
m_info->
name);
427 LOG(VB_GENERAL, LOG_ERR, QString(
"%1 process exists, skipping.")
434 db.
prepare(
"SELECT updated FROM weathersourcesettings "
435 "WHERE sourceid = :ID AND "
436 "TIMESTAMPADD(SECOND,update_timeout-15,updated) > NOW()");
440 LOG(VB_GENERAL, LOG_NOTICE, QString(
"%1 recently updated, skipping.")
446 locale_file.replace(
"/",
"-");
450 if (cache.exists() && cache.open( QIODevice::ReadOnly ))
463 LOG(VB_GENERAL, LOG_NOTICE,
464 QString(
"No cachefile for %1, forcing update.")
470 QString program =
"nice";
476 if (!
m_dir.isEmpty())
516 LOG(VB_GENERAL, LOG_ERR, QString(
"script exit status %1").
arg(status));
522 LOG(VB_GENERAL, LOG_ERR,
"Script returned no data");
529 locale_file.replace(
"/",
"-");
533 if (cache.open( QIODevice::WriteOnly ))
540 LOG(VB_GENERAL, LOG_ERR, QString(
"Unable to save data to cachefile: %1")
548 db.
prepare(
"UPDATE weathersourcesettings "
549 "SET updated = NOW() WHERE sourceid = :ID;");
571 QTextCodec *codec = QTextCodec::codecForName(
"UTF-8");
572 QString unicode_buffer = codec->toUnicode(
m_buffer);
573 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
574 QStringList data = unicode_buffer.split(
'\n', QString::SkipEmptyParts);
576 QStringList data = unicode_buffer.split(
'\n', Qt::SkipEmptyParts);
581 for (
int i = 0; i < data.size(); ++i)
583 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
584 QStringList temp = data[i].split(
"::", QString::SkipEmptyParts);
586 QStringList temp = data[i].split(
"::", Qt::SkipEmptyParts);
589 LOG(VB_GENERAL, LOG_ERR,
"Error parsing script file, ignoring");
592 LOG(VB_GENERAL, LOG_ERR,
593 QString(
"Unrecoverable error parsing script output %1")
595 LOG(VB_GENERAL, LOG_ERR, QString(
"data[%1]: '%2'")
600 if (temp[1] !=
"---")
602 if (!
m_data[temp[0]].isEmpty())
604 m_data[temp[0]].append(
"\n" + temp[1]);
607 m_data[temp[0]] = temp[1];