Make things work #1
|
@ -1,3 +1,4 @@
|
|||
cmake-build*
|
||||
|
||||
.idea
|
||||
build
|
||||
.cache
|
||||
.idea
|
||||
|
|
|
@ -2,13 +2,28 @@ cmake_minimum_required(VERSION 3.30)
|
|||
project(nutri)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||
|
||||
find_package(fmt REQUIRED)
|
||||
find_package(cpr REQUIRED)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
|
||||
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(
|
||||
nutri
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -1,8 +1,18 @@
|
|||
#include "ArgParser.hpp"
|
||||
#include "Helpers/WolframAlpha.hpp"
|
||||
#include <ctre.hpp>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#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[]) {
|
||||
try {
|
||||
|
@ -13,13 +23,15 @@ int main(const int argc, char* argv[]) {
|
|||
args.addArg("-h", "--help", "Print help", false);
|
||||
args.parse(argc, argv);
|
||||
|
||||
const auto food = args.get<std::string>("--food");
|
||||
const double amount = args.get<double>("--amount") / 100;
|
||||
// const auto food = args.get<std::string>("--food");
|
||||
// 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) {
|
||||
std::println(stderr, "Error: {}", e.what());
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue