8 #include <QApplication>
25 QStringList arguments(
"-t");
26 const QString loc = QString(
"WeatherSource::ProbeTypes(%1 %2): ")
27 .arg(program).arg(arguments.join(
" "));
35 if (ms.
Wait() != GENERIC_EXIT_OK)
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");
66 QStringList arguments(
"-T");
67 const QString loc = QString(
"WeatherSource::ProbeTimeouts(%1 %2): ")
68 .arg(program).arg(arguments.join(
" "));
70 updateTimeout = DEFAULT_UPDATE_TIMEOUT;
71 scriptTimeout = DEFAULT_SCRIPT_TIMEOUT;
78 if (ms.
Wait() != GENERIC_EXIT_OK)
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]));
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]));
123 updateTimeout = ut * 1000;
131 QStringList arguments(
"-v");
133 const QString loc = QString(
"WeatherSource::ProbeInfo(%1 %2): ")
134 .arg(info.
program).arg(arguments.join(
" "));
141 if (ms.
Wait() != GENERIC_EXIT_OK)
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");
333 m_updateTimer(new QTimer(this)), m_connectCnt(0)
336 if (!dir.exists(
"MythWeather"))
337 dir.mkdir(
"MythWeather");
338 dir.cd(
"MythWeather");
339 if (!dir.exists(info->
name))
340 dir.mkdir(info->
name);
342 m_dir = dir.absolutePath();
372 disconnect(
this, 0, ws, 0);
383 const QString loc = QString(
"WeatherSource::getLocationList(%1 %2): ")
384 .arg(program).arg(args.join(
" "));
392 if (ms.
Wait() != GENERIC_EXIT_OK)
394 LOG(VB_GENERAL, LOG_ERR, loc +
"Cannot run script");
395 return QStringList();
399 QByteArray result = ms.
ReadAll();
400 QTextStream text(result);
402 QTextCodec *codec = QTextCodec::codecForName(
"UTF-8");
403 while (!text.atEnd())
405 QString
tmp = text.readLine();
407 while (tmp.endsWith(
'\n') || tmp.endsWith(
'\r'))
412 QString loc_string = codec->toUnicode(tmp.toUtf8());
425 LOG(VB_GENERAL, LOG_INFO,
"Starting update of " +
m_info->
name);
429 LOG(VB_GENERAL, LOG_ERR, QString(
"%1 process exists, skipping.")
436 db.
prepare(
"SELECT updated FROM weathersourcesettings "
437 "WHERE sourceid = :ID AND "
438 "TIMESTAMPADD(SECOND,update_timeout-15,updated) > NOW()");
442 LOG(VB_GENERAL, LOG_ERR, QString(
"%1 recently updated, skipping.")
448 locale_file.replace(
"/",
"-");
452 if (cache.exists() && cache.open( QIODevice::ReadOnly ))
467 LOG(VB_GENERAL, LOG_WARNING,
468 QString(
"No cachefile for %1, forcing update.")
479 args << (
m_units == SI_UNITS ?
"SI" :
"ENG");
481 if (!
m_dir.isEmpty())
509 if (status == GENERIC_EXIT_OK)
517 if (status != GENERIC_EXIT_OK)
519 LOG(VB_GENERAL, LOG_ERR, QString(
"script exit status %1").arg(status));
525 LOG(VB_GENERAL, LOG_ERR,
"Script returned no data");
532 locale_file.replace(
"/",
"-");
536 if (cache.open( QIODevice::WriteOnly ))
543 LOG(VB_GENERAL, LOG_ERR, QString(
"Unable to save data to cachefile: %1")
551 db.
prepare(
"UPDATE weathersourcesettings "
552 "SET updated = NOW() WHERE sourceid = :ID;");
569 QTextCodec *codec = QTextCodec::codecForName(
"UTF-8");
570 QString unicode_buffer = codec->toUnicode(
m_buffer);
571 QStringList
data = unicode_buffer.split(
'\n', QString::SkipEmptyParts);
575 for (
int i = 0; i < data.size(); ++i)
577 QStringList temp = data[i].split(
"::", QString::SkipEmptyParts);
579 LOG(VB_GENERAL, LOG_ERR,
"Error parsing script file, ignoring");
582 LOG(VB_GENERAL, LOG_ERR,
583 QString(
"Unrecoverable error parsing script output %1")
585 LOG(VB_GENERAL, LOG_ERR, QString(
"data[%1]: '%2'")
586 .arg(i).arg(data[i]));
590 if (temp[1] !=
"---")
592 if (!
m_data[temp[0]].isEmpty())
594 m_data[temp[0]].append(
"\n" + temp[1]);
597 m_data[temp[0]] = temp[1];