From 0877db7cd11027e8d7541b9b40bb0786b482b97c Mon Sep 17 00:00:00 2001
From: MelnikovDM <dimooondimon15@gmail.com>
Date: Mon, 27 May 2024 08:56:29 +0300
Subject: [PATCH] code: datastream

---
 labor01.cpp | 44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/labor01.cpp b/labor01.cpp
index dc00057..44bfe4b 100644
--- a/labor01.cpp
+++ b/labor01.cpp
@@ -5,6 +5,8 @@
 #include "text.h"
 #include "svg.h"
 #include <curl/curl.h>
+#include <sstream>
+#include <string>
 
 using namespace std;
 struct Input {
@@ -40,26 +42,32 @@ input_data(istream& inn, bool promt) {
     return in;
 }
 
+Input
+download(const string& address) {
+    stringstream buffer;
+    CURL* curl = curl_easy_init();
+    if (curl) {
+        CURLcode res;
+        curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
+        res = curl_easy_perform(curl);
+        if (res != CURLE_OK) {
+            cerr << curl_easy_strerror(res);
+            exit(1);
+        }
+        curl_easy_cleanup(curl);
+    }
+    return input_data(buffer, false);
+}
 
 
-int main(int argc, char* argv[1]) {
+int main(int argc, char* argv[]) {
+    Input input;
     if (argc > 1) {
-        CURL* curl = curl_easy_init();
-        if (curl) {
-            CURLcode res;
-            curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
-            res = curl_easy_perform(curl);
-            if (res != CURLE_OK) {
-                cerr << curl_easy_strerror(res);
-                exit(1);
-            }
-            curl_easy_cleanup(curl);
-        }
-        return 0;
+        input = download(argv[1]);
+    }
+    else {
+        input = input_data(cin, true);
     }
-    bool promt = true;
-    auto in = input_data(cin, promt);
-    auto bins = make_histogram(in.numbers, in.bin_count);
-    show_histogram_svg(bins, in.colors);
-    return 0;
+    const auto bins = make_histogram(input.numbers, input.bin_count);
+    show_histogram_svg(bins);
 }
\ No newline at end of file