Skip to content

Instantly share code, notes, and snippets.

@m1irka
Created April 17, 2026 09:40
Show Gist options
  • Select an option

  • Save m1irka/dc377e6eab155c148064476d2c22981b to your computer and use it in GitHub Desktop.

Select an option

Save m1irka/dc377e6eab155c148064476d2c22981b to your computer and use it in GitHub Desktop.
zodiac
#include <windows.h>
#include <winhttp.h>
#include <iostream>
#include <string>
#pragma comment(lib, "winhttp.lib")
using namespace std;
wstring GetHoroscope(const wstring& sign) {
wstring result;
HINTERNET hSession = WinHttpOpen(L"HoroscopeApp/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);
if (hSession) {
HINTERNET hConnect = WinHttpConnect(hSession, L"freehoroscopeapi.com",
INTERNET_DEFAULT_HTTPS_PORT, 0);
if (hConnect) {
wstring params = L"/api/v1/get-horoscope/daily?sign=" + sign;
HINTERNET hRequest = WinHttpOpenRequest(hConnect, L"GET", params.c_str(),
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);
if (hRequest) {
BOOL bResults = WinHttpSendRequest(hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0,
0, 0);
if (bResults) bResults = WinHttpReceiveResponse(hRequest, NULL);
if (bResults) {
DWORD dwSize = 0;
do {
DWORD dwDownloaded = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) break;
if (dwSize == 0) break;
char* buffer = new char[dwSize + 1];
ZeroMemory(buffer, dwSize + 1);
if (WinHttpReadData(hRequest, buffer, dwSize, &dwDownloaded)) {
result += wstring(buffer, buffer + dwDownloaded);
}
delete[] buffer;
} while (dwSize > 0);
}
WinHttpCloseHandle(hRequest);
}
WinHttpCloseHandle(hConnect);
}
WinHttpCloseHandle(hSession);
}
return result;
}
// простая функция для поиска текста по ключу
string ExtractField(const string& json, const string& field) {
size_t pos = json.find("\"" + field + "\"");
if (pos == string::npos) return "";
pos = json.find(":", pos);
if (pos == string::npos) return "";
pos++;
while (pos < json.size() && (json[pos] == ' ' || json[pos] == '\"')) pos++;
size_t end = pos;
while (end < json.size() && json[end] != '\"' && json[end] != ',') end++;
return json.substr(pos, end - pos);
}
int main() {
wcout << L"Enter zodiac sign (e.g. aries, taurus): ";
wstring sign;
wcin >> sign;
wstring today = GetHoroscope(sign);
string utf8(today.begin(), today.end());
cout << "Horoscope for " << string(sign.begin(), sign.end()) << " (Today):\n";
cout << "--------------------------------\n";
cout << "Description: " << ExtractField(utf8, "horoscope") << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment