Ejemplo n.º 1
0
void
Database::writeNotification(bool single_line)
{
    StoragePtr homepage = m_Storages[IDX_HOMEPAGE];

    std::string filename = ConfigurationFindscholarships::instance()->pathDatabase() + currentDateTime();
    if (single_line)
    {
        filename = filename + ".single";
    }
    else
    {
        filename = filename + ".multiple";
    }

    std::ofstream file_notification(filename.c_str());
    if (file_notification.is_open())
    {
        Storage::const_iterator beg = homepage->begin();
        Storage::const_iterator end = homepage->end();
        end--;
        for (Storage::const_iterator it = end; it != beg; it--)
        {
            DatePtr deadline = it->first;
            const DataEntry& data = it->second;
            if (data.isNew())
            {
                if (single_line)
                {
                    file_notification << data.getTitle().getSingleLineNotification(deadline) << std::endl << std::endl;
                }
                else
                {
                    file_notification << data.getTitle().getMultipleLineNotification(deadline) << std::endl << std::endl;
                }
            }
        }

        DatePtr deadline = beg->first;
        const DataEntry& data = beg->second;
        if (data.isNew())
        {
            if (single_line)
            {
                file_notification << data.getTitle().getSingleLineNotification(deadline) << std::endl << std::endl;
            }
            else
            {
                file_notification << data.getTitle().getMultipleLineNotification(deadline) << std::endl << std::endl;
            }
        }
    }
    else
    {
        DBGERR(__FUNCTION__ << ": Cannot open file \"" << filename << "\" for writing!")
    }
}
Ejemplo n.º 2
0
void
Database::showStorage(StoragePtr to_show)
{
    std::cout << "Size = " << to_show->size() << std::endl;
    for (Storage::const_iterator it = to_show->begin(); it != to_show->end(); ++it)
    {
        const DatePtr deadline = it->first;
        const DataEntry& data = it->second;

        std::cout << boost::gregorian::to_iso_extended_string(*deadline) << " " << data.getTitle().getTitleNoSpace() << std::endl;
    }
}
Ejemplo n.º 3
0
void
Database::writeToCategoryFile(const std::string& filename,
                              const std::string& title,
                              StoragePtr to_write)
{
    std::ofstream out(filename.c_str());

    if (out.is_open())
    {
        out << ConfigurationFindscholarships::instance()->categoryPart1() << std::endl;
        out << "<title>Findscholarships: " << title << "</title>" << std::endl;

        out << ConfigurationFindscholarships::instance()->categoryPart2() << std::endl;
        out << "<div><center><h2>" << title << "</h2></center></div>" << std::endl;
        out << ConfigurationFindscholarships::instance()->categoryPart3() << std::endl;

        std::string list_new = "";
        std::string list_old = "";

        for (Storage::const_iterator it = to_write->begin(); it != to_write->end(); ++it)
        {
            const DatePtr deadline = it->first;
            const DataEntry& data = it->second;
            const Title& title = data.getTitle();

            if (data.isNew())
            {
                list_new = "<p>" + list_new + title.getHtmlLink(deadline) + "<img src=\"images/new_icon.gif\"></p>\n\n";
            }
            else
            {
                list_old = "<p>" + list_old + title.getHtmlLink(deadline) + "</p>\n\n";
            }
        }

        out << list_new << list_old << std::endl;
        out << ConfigurationFindscholarships::instance()->categoryPart4() << std::endl;
        out.close();
    }
    else
    {
        DBGERR(__FUNCTION__ << ": Cannot write to category file \"" << filename << "\"!")
    }
}
Ejemplo n.º 4
0
void
Database::storeDatabase(const std::string& filename, StoragePtr to_store)
{
    std::ofstream out(filename.c_str());

    if (out.is_open())
    {
        for (Storage::const_iterator it = to_store->begin(); it != to_store->end(); ++it)
        {
            DatePtr deadline = it->first;
            const DataEntry& data_entry = it->second;

            out << boost::gregorian::to_iso_extended_string(*deadline) << std::endl;
            out << data_entry.getTitle().getTitle() << std::endl;
            out << data_entry.getOrigLink() << std::endl;
        }

        out.close();
    }
    else
    {
        DBGERR(__FUNCTION__ << ": Cannot open file \"" << filename << "\" to store database on disk!")
    }
}