Created
May 2, 2026 11:53
-
-
Save NV-Valentine/ab5c18d21f37b3ed6674d35d10699d6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <winhttp.h> | |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| #include <iomanip> | |
| #pragma comment(lib, "winhttp.lib") | |
| // Zodiac signs list | |
| std::vector<std::string> zodiac = { | |
| "aries","taurus","gemini","cancer","leo","virgo", | |
| "libra","scorpio","sagittarius","capricorn","aquarius","pisces" | |
| }; | |
| // Function to perform HTTP GET | |
| std::string GetHoroscope(const std::wstring& sign, const std::wstring& day) { | |
| HINTERNET hSession = WinHttpOpen(L"HoroscopeApp/1.0", | |
| WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); | |
| if (!hSession) return "Error: cannot open session"; | |
| HINTERNET hConnect = WinHttpConnect(hSession, L"freehoroscopeapi.com", | |
| INTERNET_DEFAULT_HTTPS_PORT, 0); | |
| if (!hConnect) return "Error: cannot connect"; | |
| std::wstring path = L"/api/v1/get-horoscope/daily?sign=" + sign + L"&day=" + day; | |
| HINTERNET hRequest = WinHttpOpenRequest(hConnect, L"GET", path.c_str(), | |
| NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE); | |
| if (!hRequest) return "Error: cannot create request"; | |
| BOOL bResults = WinHttpSendRequest(hRequest, | |
| WINHTTP_NO_ADDITIONAL_HEADERS, 0, | |
| WINHTTP_NO_REQUEST_DATA, 0, 0, 0); | |
| if (!bResults) return "Error: cannot send request"; | |
| bResults = WinHttpReceiveResponse(hRequest, NULL); | |
| if (!bResults) return "Error: cannot receive response"; | |
| DWORD dwSize = 0; | |
| std::string response; | |
| do { | |
| WinHttpQueryDataAvailable(hRequest, &dwSize); | |
| if (!dwSize) break; | |
| std::vector<char> buffer(dwSize); | |
| DWORD dwDownloaded = 0; | |
| WinHttpReadData(hRequest, buffer.data(), dwSize, &dwDownloaded); | |
| response.append(buffer.begin(), buffer.begin() + dwDownloaded); | |
| } while (dwSize > 0); | |
| WinHttpCloseHandle(hRequest); | |
| WinHttpCloseHandle(hConnect); | |
| WinHttpCloseHandle(hSession); | |
| return response; | |
| } | |
| // Pretty console output | |
| void PrintBox(const std::string& title, const std::string& text) { | |
| std::cout << "\n╔══════════════════════════════════════════════╗\n"; | |
| std::cout << "║ " << std::setw(40) << std::left << title << " ║\n"; | |
| std::cout << "╠══════════════════════════════════════════════╣\n"; | |
| for (size_t i = 0; i < text.size(); i += 40) { | |
| std::cout << "║ " << std::setw(40) << std::left << text.substr(i, 40) << " ║\n"; | |
| } | |
| std::cout << "╚══════════════════════════════════════════════╝\n"; | |
| } | |
| int main() { | |
| std::cout << "Choose your zodiac sign:\n"; | |
| for (size_t i = 0; i < zodiac.size(); i++) | |
| std::cout << i + 1 << ". " << zodiac[i] << "\n"; | |
| int choice; | |
| std::cin >> choice; | |
| if (choice < 1 || choice > 12) { | |
| std::cout << "Invalid choice!\n"; | |
| return 0; | |
| } | |
| std::wstring sign(zodiac[choice - 1].begin(), zodiac[choice - 1].end()); | |
| // Today and tomorrow dates | |
| SYSTEMTIME st; | |
| GetLocalTime(&st); | |
| wchar_t today[11], tomorrow[11]; | |
| swprintf(today, 11, L"%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); | |
| SYSTEMTIME stTomorrow = st; | |
| FILETIME ft; | |
| SystemTimeToFileTime(&stTomorrow, &ft); | |
| ULARGE_INTEGER uli; | |
| uli.LowPart = ft.dwLowDateTime; | |
| uli.HighPart = ft.dwHighDateTime; | |
| uli.QuadPart += 864000000000ULL; // +1 day in 100ns units | |
| ft.dwLowDateTime = uli.LowPart; | |
| ft.dwHighDateTime = uli.HighPart; | |
| FileTimeToSystemTime(&ft, &stTomorrow); | |
| swprintf(tomorrow, 11, L"%04d-%02d-%02d", stTomorrow.wYear, stTomorrow.wMonth, stTomorrow.wDay); | |
| // Requests | |
| std::string todayHoroscope = GetHoroscope(sign, today); | |
| std::string tomorrowHoroscope = GetHoroscope(sign, tomorrow); | |
| PrintBox("Horoscope for Today", todayHoroscope); | |
| PrintBox("Horoscope for Tomorrow", tomorrowHoroscope); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment