Make things work #1
|
@ -1,3 +1,4 @@
|
||||||
cmake-build*
|
cmake-build*
|
||||||
|
build
|
||||||
.idea
|
.cache
|
||||||
|
.idea
|
||||||
|
|
|
@ -2,13 +2,28 @@ cmake_minimum_required(VERSION 3.30)
|
||||||
project(nutri)
|
project(nutri)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||||
|
|
||||||
find_package(fmt REQUIRED)
|
|
||||||
find_package(cpr REQUIRED)
|
|
||||||
find_package(nlohmann_json REQUIRED)
|
find_package(nlohmann_json REQUIRED)
|
||||||
|
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/external/ctre/include)
|
include_directories(${CMAKE_SOURCE_DIR}/external/ctre/include)
|
||||||
add_subdirectory(external/ctre/)
|
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
ctre
|
||||||
|
GIT_REPOSITORY https://github.com/hanickadot/compile-time-regular-expressions.git
|
||||||
|
GIT_TAG v3.9.0
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
cpr
|
||||||
|
GIT_REPOSITORY https://github.com/libcpr/cpr.git
|
||||||
|
GIT_TAG 1.11.0
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(ctre cpr)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
nutri
|
nutri
|
||||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -1,8 +1,18 @@
|
||||||
#include "ArgParser.hpp"
|
#include "ArgParser.hpp"
|
||||||
#include "Helpers/WolframAlpha.hpp"
|
#include "Helpers/WolframAlpha.hpp"
|
||||||
|
#include <ctre.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
void getVal(std::string_view sv) {
|
||||||
|
auto m = ctre::search<"(?<=protein\\s)(\\d+)\\s*(\\w+)">(sv);
|
||||||
|
double d = m.get<1>().to_number();
|
||||||
|
std::string u = m.get<2>().to_string();
|
||||||
|
|
||||||
|
std::println("1: {}\n2: {}", d, u);
|
||||||
|
}
|
||||||
|
|
||||||
int main(const int argc, char* argv[]) {
|
int main(const int argc, char* argv[]) {
|
||||||
try {
|
try {
|
||||||
|
@ -13,13 +23,15 @@ int main(const int argc, char* argv[]) {
|
||||||
args.addArg("-h", "--help", "Print help", false);
|
args.addArg("-h", "--help", "Print help", false);
|
||||||
args.parse(argc, argv);
|
args.parse(argc, argv);
|
||||||
|
|
||||||
const auto food = args.get<std::string>("--food");
|
// const auto food = args.get<std::string>("--food");
|
||||||
const double amount = args.get<double>("--amount") / 100;
|
// const double amount = args.get<double>("--amount") / 100;
|
||||||
|
|
||||||
|
// if (!args.has("--source") || args.get<std::string>("--source") == "Wolfram") {
|
||||||
|
// WolframAlpha wa(food, amount);
|
||||||
|
// std::println("Calories: {:.2f} kcal\nProtein: {:.2f} g\nCarbs: {:.2f} g\nFat: {:.2f} g", wa.getCalories(), wa.getProtein(), wa.getCarbs(), wa.getFat());
|
||||||
|
// }
|
||||||
|
getVal("carbs 14 g | protein 20 mg | fat 11 g");
|
||||||
|
|
||||||
if (!args.has("--source") || args.get<std::string>("--source") == "Wolfram") {
|
|
||||||
WolframAlpha wa(food, amount);
|
|
||||||
std::println("Calories: {:.2f} kcal\nProtein: {:.2f} g\nCarbs: {:.2f} g\nFat: {:.2f} g", wa.getCalories(), wa.getProtein(), wa.getCarbs(), wa.getFat());
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::println(stderr, "Error: {}", e.what());
|
std::println(stderr, "Error: {}", e.what());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue