#include "bom.hpp" #include "book.hpp" #include "rapidxml/rapidxml.hpp" #include #include #include #include #include #include #include #include #include namespace bom { CURL* curl{NULL}; std::string result; static size_t my_write(void* buffer, std::size_t size, std::size_t nmemb, void* stream) { std::string& text = *static_cast(stream); std::size_t totalsize = size * nmemb; text.append(static_cast(buffer), totalsize); return totalsize; } void initialise() { curl_global_init(CURL_GLOBAL_DEFAULT); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.bom.gov.au/anon/gen/fwo/IDN60920.xml"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); } } void destroy() { curl_global_cleanup(); } void updateBom(std::unordered_map& bs) { CURLcode res; res = curl_easy_perform(curl); curl_easy_cleanup(curl); if (CURLE_OK != res) { fprintf(stderr, "Curl failed: %d\n", res); } rapidxml::xml_document<> d; d.parse<0>(&result[0]); rapidxml::xml_node<>* n = d.first_node(); for (rapidxml::xml_attribute<>* a = n->first_attribute(); a; a = a->next_attribute()) { std::cout << a->name() << ": " << a->value() << std::endl; } } } // namespace bom