-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·129 lines (102 loc) · 3.66 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Qt
#include <QCoreApplication>
#include <QDebug>
#include <QCommandLineParser>
#include <memory>
// API
#include "weatherapi.h"
// Test
#include <QtNetwork/QDnsLookup>
void showWeather( QString city )
{
WeatherAPI w;
//QString city = "Neu-Isenburg";
QString country_code = "DE";
w.getTemperature( city, country_code );
w.getTempMin( city, country_code );
w.getTempMax( city, country_code );
w.getFeelsLike( city, country_code );
w.getHumidity( city, country_code );
w.getWindSpeed(city, country_code);
w.getWindDeg( city, country_code );
w.getWeatherStatus( city, country_code );
w.getCloudCoverage( city, country_code );
w.getSunriseTime( city, country_code );
w.getPressure( city, country_code );
w.getCoordLong( city, country_code );
w.printJsonDataOneCall("50.05", "8.7");
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("OpenWheaterMap-CLI");
QCoreApplication::setApplicationVersion("1.0.0");
WeatherAPI w;
//QString city = "Neu-Isenburg";
QString country_code = "DE";
// Template:
// https://github.com/typecaster0xf/cppExamples-Qt-00_CommandLineParse/blob/master/commandParse.cpp
QCommandLineParser parser;
parser.setApplicationDescription("Description: OpenWeatherMap console application (CLI)");
parser.addVersionOption();
parser.addHelpOption();
// positional arguments
parser.addPositionalArgument("city", QCoreApplication::translate("main", "City for weather query."));
parser.addPositionalArgument("Country Code", QCoreApplication::translate("main", "Country Code of the city (i.e. DE)."));
// value option (city, cc)
QCommandLineOption cityOption(QStringList() << "c" << "city",
QCoreApplication::translate("main", "Set city to <'City, DE'>."),
QCoreApplication::translate("main", "City"));
parser.addOption( cityOption );
QCommandLineOption allOption(
QStringList() << "a" << "all-values",
QCoreApplication::translate("main", "Show (now, min, max) temperature."));
parser.addOption( allOption );
QCommandLineOption tempOption(
QStringList() << "t" << "temperature",
QCoreApplication::translate("main", "Show (now, min, max) temperature."));
parser.addOption( tempOption );
QCommandLineOption humidtyOption(
QStringList() << "x" << "humidity",
QCoreApplication::translate("main", "Show humidity."));
parser.addOption( humidtyOption );
QCommandLineOption pressureOption(
QStringList() << "p" << "pressure",
QCoreApplication::translate("main", "Show air pressure."));
parser.addOption( pressureOption );
// Process the actual command line arguments given by the user
parser.process(app);
const QStringList args = parser.positionalArguments();
// source is args.at(0), destination is args.at(1)
QString city = parser.value( cityOption );
bool showAll = parser.isSet( allOption );
bool showTemp = parser.isSet( tempOption );
bool showPressure = parser.isSet( pressureOption );
bool showHumidity = parser.isSet( pressureOption );
if ( showAll )
{
showWeather( city );
return 0;
}
else if ( showTemp)
{
w.getTemperature( city, country_code );
return 0;
}
else if ( showPressure )
{
w.getPressure( city, country_code );
return 0;
}
else if ( showHumidity )
{
w.getHumidity( city, country_code );
return 0;
}
else
{
qDebug() << "No valid Option";
return 0;
}
return app.exec();
}