feat(parsing): file dbs
This commit is contained in:
parent
52b0345cb1
commit
89e359ae6f
3 changed files with 24 additions and 9 deletions
|
|
@ -6,15 +6,18 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/08 12:18:18 by rparodi #+# #+# */
|
/* Created: 2025/04/08 12:18:18 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/04/10 16:05:21 by rparodi ### ########.fr */
|
/* Updated: 2025/04/11 12:36:11 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define CLR_RESET "\033[0m"
|
#define CLR_RESET "\033[0m"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
# Updated: 2025/04/11 11:23:29 by rparodi ### ########.fr #
|
# Updated: 2025/04/11 12:35:05 by rparodi ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -66,7 +66,6 @@ clean:
|
||||||
# Clean (make fclean)
|
# Clean (make fclean)
|
||||||
fclean: clean
|
fclean: clean
|
||||||
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
|
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
|
||||||
@$(RM) ./data.csv
|
|
||||||
@$(RM) $(NAME)
|
@$(RM) $(NAME)
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,22 +6,35 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */
|
/* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/04/11 11:47:18 by rparodi ### ########.fr */
|
/* Updated: 2025/04/11 12:38:36 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "BitcoinExchange.hpp"
|
#include "BitcoinExchange.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, float>parse_file(std::string name) {
|
std::map<std::string, float>parse_file(std::string name) {
|
||||||
std::map<std::string, float> to_ret;
|
std::map<std::string, float> to_ret;
|
||||||
std::string tmp;
|
std::string tmpLine;
|
||||||
std::ifstream file(name);
|
std::ifstream file(name);
|
||||||
|
size_t line = 1;
|
||||||
|
|
||||||
while (std::getline(file, tmp)) {
|
while (std::getline(file, tmpLine)) {
|
||||||
;
|
std::size_t limit = tmpLine.find(" | ");
|
||||||
|
if (limit == std::string::npos) {
|
||||||
|
std::cerr << CLR_RED << "Limiter not found at the line " << line << CLR_RESET << std::endl;
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
std::string tmpDate = tmpLine.substr(0, limit);
|
||||||
|
float tmpValue = std::atof(tmpLine.substr(limit + 3).c_str());
|
||||||
|
to_ret.insert(std::pair<std::string, float>(tmpDate, tmpValue));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return to_ret;
|
return to_ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue