Exemple #1
0
void FiveDayForecast(wstring city)
{
	WeatherInfo weather;
	Weather weatherI;
	auto result(async(SendRequest, L"forecast?q=" + city));
	cls();
	Center(16, true); cout << "Fetching data";
	cursorPos = getCursorPos();
	for (int i = 0; result.wait_for(span) != future_status::ready; i++)
	{
		SetConsoleCursorPosition(ConsoleH, cursorPos);
		switch (i % 4)
		{
		case 0:
			cout << "   ";
			break;
		case 1:
			cout << ".  ";
			break;
		case 2:
			cout << ".. ";
			break;
		case 3:
			cout << "...";
		}
		if (i > 50)
		{
			Center(16, true);
			cout << "  Fetch failed  ";
			SetConsoleTextAttribute(ConsoleH, 240);
			Center(4, 4);
			cout << "Back";
			SetConsoleTextAttribute(ConsoleH, 15);
			while (_getch() != 13);
			return;
		}
	}
	weather = ParseFiveDay(result.get());
	if (weather.cityName.size() < 1)
	{
		Center(16, true);
		cout << "  Fetch failed  ";
		SetConsoleTextAttribute(ConsoleH, 240);
		Center(4, 4);
		cout << "Back";
		SetConsoleTextAttribute(ConsoleH, 15);
		while (_getch() != 13);
		return;
	}
	int choice;
	for (;;)
	{
		choice = WeatherList(weather);
		if (choice != weather.ToDateTimeList().size())
		{
			weatherI = TimeList(weather.ToDateTimeList()[choice], weather.cityName);
			if (weatherI.main != "back")
				PrintWeather(weatherI, weather.cityName);
		}
		else break;
	}
}