From 511108c2db9835730fcddd84d813fb087b60c301 Mon Sep 17 00:00:00 2001
From: Andrey <AnikeevAnA@mpei.ru>
Date: Mon, 15 May 2023 17:00:40 +0300
Subject: [PATCH] ---

---
 main.cpp | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/main.cpp b/main.cpp
index 0a2e78e..dd949d2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,3 +1,5 @@
+#include <sstream>
+#include <string>
 #include <curl/curl.h>
 #include <iostream>
 #include <vector>
@@ -35,16 +37,15 @@ input_data(istream& in, bool prompt)
     return rez;
 }
 
-int
-main(int argc, char* argv[])
-{
-    if (argc > 1)
-    {
+Input
+download(const string& address) {
+    stringstream buffer;
+
     CURL* curl = curl_easy_init();
     if(curl)
     {
         CURLcode res;
-        curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
+        curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
         res = curl_easy_perform(curl);
         if (res != 0)
             {
@@ -53,13 +54,23 @@ main(int argc, char* argv[])
             }
         curl_easy_cleanup(curl);
     }
-    return 0;
+    return input_data(buffer, false);
+}
+
+int
+main(int argc, char* argv[])
+{
+    Input input;
+    if (argc > 1) {
+        input = download(argv[1]);
+    } else {
+        input = input_data(cin, true);
     }
 
     curl_global_init(CURL_GLOBAL_ALL);
     bool prompt = false;
     auto in = input_data(cin, prompt);
-    auto bins = make_histogram(in.numbers, in.bin_count);
-    //show_histogram_svg(bins);
-    show_histogram_text(bins, in.numbers, in.bin_count);
+    const auto bins = make_histogram(in.numbers, in.bin_count);
+    show_histogram_svg(bins);
+    //show_histogram_text(bins, in.numbers, in.bin_count);
 }