WikiGraph::WikiPage& make_wiki_page(string path_to_html, string path_to_txt) { auto toRet = new WikiGraph::WikiPage; WikiGraph::WikiPage& new_page = *toRet; //get reference to the newly created object ifstream html_file(path_to_html.c_str()); //open html file new_page.title = getPageTitle(html_file); // use already existing method to get title html_file.close(); new_page.txt_location = path_to_txt; //save the path to the txt file new_page.html_location = path_to_html; //save the path to the html file return new_page; }
bool HtmlReaderWriter::WriteHtml(const QString &str, const QString &file) { QFile html_file(file); if (!html_file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { return false; } QTextStream stream(&html_file); stream.setCodec("UTF-8"); stream << str; html_file.close(); return true; }
QString HtmlReaderWriter::ReadHtml(const QString &file) { QString buff; QFile html_file(file); if (!html_file.open(QIODevice::ReadOnly | QIODevice::Text)) { return buff; } QTextStream stream(&html_file); QTextCodec *codec = QTextCodec::codecForName("UTF-8"); stream.setCodec(codec); html_str_ = stream.readAll(); html_file.close(); return html_str_; }
void Manager::processSingle(FetchedInfoScholarship &fis, Database &db) { HtmlGenBase* generator = getGenerator(fis.m_URL); assert (generator != NULL); generator->process(fis); const HtmlResult& result = generator->getHtmlResult(); if (result.getDeadline().get() != NULL) { // write to files const std::string& full_html_code = result.getFullHtmlCode(); std::string full_path = result.getTitle().getFileLocation(result.getDeadline()); std::ofstream html_file(full_path.c_str()); if (html_file.is_open()) { html_file << full_html_code; html_file.close(); // insert to database const Title& title = result.getTitle(); const StorageVec st = db.getStorages(); std::size_t index = title.classifiedIndex(); StoragePtr s = st[index]; db.insert(s, result.getDeadline(), fis.m_Title, fis.m_URL, true /* is_new */); //db.showDatabase(); } else { DBGERR(__FUNCTION__ << ": Cannot write to file \"" << full_path << "\"!") } } // clean up delete generator; generator = NULL; }