-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProjectDriver.cpp
190 lines (177 loc) · 4.67 KB
/
ProjectDriver.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include "weatherdata.h"
using namespace std;
/* Main menu */
void printMainMenu() {
cout << "====Main Menu====" << endl;
cout << "1. Add city" << endl;
cout << "2. Delete city" << endl;
cout << "3. Print all cities" << endl;
cout << "4. Get current weather" << endl;
cout << "5. Get detailed weather information" << endl;
cout << "6. Quit" << endl;
}
/* Weather menu */
void printWeatherMenu() {
cout << "====Weather Options====" << endl;
cout << "1. Astronomy data" << endl;
cout << "2. Atmospheric data"<< endl;
cout << "3. 5 Day Forecast" << endl;
cout << "4. Location data" << endl;
cout << "5. Wind data" << endl;
cout << "6. All Weather data" << endl;
cout << "7. Back to main menu" << endl;
}
/* Calls addCity in class WeatherData to add city to the database */
void inputCity(string city, WeatherData * wData) {
//Set command argument to pass to system command line to call python file that gets weather data.
string filename = "./getWeatherData.py";
string baseCommand = "python3.4 ";
baseCommand += filename;
//Call Python file to get weather data.
string command = baseCommand + " " + "\"" + city + "\"";
system(command.c_str());
//Read output file.
ifstream fileReader;
fileReader.open((city + ".txt").c_str());
//Put city into weatherdata database.
string temp;
string cityInfo;
while(getline(fileReader, temp)) {
cityInfo += temp;
}
remove((city + ".txt").c_str());
if (cityInfo.length() < 600 )
cout << city + " not found. Please enter a valid city." << endl;
else wData->addCity(cityInfo);
}
/* Called when use selects detailed weather options. */
void weatherOptions(WeatherData * wData) {
cout << "Which city do you want information about?" << endl;
//cin.ignore();
string cityName;
cin >> cityName;
if (wData->foundCity(cityName)) {
printWeatherMenu();
int userArg;
while (cin >> userArg) {
if (userArg == 1) {
wData->getAstronomyData(cityName);
}
if (userArg == 2) {
wData->getAtmosphericData(cityName);
}
if (userArg == 3) {
wData->getForecast(cityName);
}
if (userArg == 4) {
wData->getLocation(cityName);
}
if (userArg == 5) {
wData->getWindData(cityName);
}
if (userArg == 6) {
wData->getAllWeatherData(cityName);
}
if (userArg == 7) {
break;
}
printWeatherMenu();
}
}
else {
inputCity(cityName, wData);
printWeatherMenu();
int userArg;
while (cin >> userArg) {
if (userArg == 1) {
wData->getAstronomyData(cityName);
}
if (userArg == 2) {
wData->getAtmosphericData(cityName);
}
if (userArg == 3) {
wData->getForecast(cityName);
}
if (userArg == 4) {
wData->getLocation(cityName);
}
if (userArg == 5) {
wData->getWindData(cityName);
}
if (userArg == 6) {
wData->getAllWeatherData(cityName);
}
if (userArg == 7) {
break;
}
printWeatherMenu();
}
}
}
int main() {
WeatherData * wData = new WeatherData();
cout << "Adding initial cities to network..." << endl;
inputCity("Denver", wData);
inputCity("New York", wData);
inputCity("Los Angeles", wData);
inputCity("Portland", wData);
inputCity("New Orleans", wData);
inputCity("Miami", wData);
inputCity("Washington, D.C.", wData);
inputCity("Seattle", wData);
inputCity("San Diego", wData);
inputCity("San Francisco", wData);
inputCity("Chicago", wData);
inputCity("Atlanta", wData);
inputCity("Boston", wData);
inputCity("Cincinnati", wData);
inputCity("Dallas", wData);
inputCity("Salt Lake City", wData);
int userArg;
printMainMenu();
while (cin >> userArg) {
if (userArg == 1) {
cout << "Enter city name:" << endl;
cin.ignore();
string city;
getline(cin, city);
if (!wData->foundCity(city))
inputCity(city, wData);
}
if (userArg == 2) {
cout << "Enter city to be removed from memory: " << endl;
cin.ignore();
string city;
getline(cin, city);
wData->deleteCity(city);
}
if (userArg == 3) {
wData->printCitiesByName();
}
if (userArg == 4) {
cout << "Enter city: " << endl;
string city;
cin.ignore();
getline(cin, city);
if (wData->foundCity(city)) {
wData->getCurrentWeather(city);
}
else {
inputCity(city, wData);
wData->getCurrentWeather(city);
}
}
if (userArg == 5) {
weatherOptions(wData);
}
if (userArg == 6) {
cout << "Goodbye!" << endl;
break;
}
printMainMenu();
}
delete wData;
}