ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Publisher.cpp
(Generate patch)

Comparing trunk/Publisher.cpp (file contents):
Revision 21 by douglas, 2004-07-16T23:37:41-07:00 vs.
Revision 45 by douglas, 2004-08-16T15:00:28-07:00

# Line 5 | Line 5
5   // $Id$
6  
7   #include "Publisher.hpp"
8 + #include "Rss.hpp"
9 + #include "Atom.hpp"
10  
11 < Publisher::Publisher(const std::set<Buddy>& buddies, const Database& database,
12 <        bool start) : buddies(buddies), database(database), start(start)
11 > Publisher::Publisher(const std::set<Buddy>& buddies, const Database& database, bool start) : buddies(buddies),
12 >        database(database), start(start)
13   {
14 <        if (start)
13 <        {
14 <                publisher.Spawn(etl::Bind<0>(&Publisher::publish, this));
15 <        }
14 >        if (start) publish();
15   }
16  
17 < int Publisher::publish()
17 > void Publisher::publish()
18   {
19 <        cerr << "Publisher::publish()\n";
19 >        cout << bright << yellow << "Started updating feeds at " << Stamp()
20 >                << ".\n" << reset;
21 >
22 >        Stamp stamp;
23 >        ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host,
24 >                database.user, database.password, database.db));
25 >
26 >        db->Execute("DELETE FROM messages WHERE stamp<'"
27 >                + ext::String(stamp - Day(30)) + "'");
28 >
29 >        for (std::set<Buddy>::const_iterator buddy(buddies.begin());
30 >                buddy != buddies.end(); ++buddy)
31 >        {
32 >                ext::Handle<dbi::ResultSet> messages(db->Execute("SELECT stamp, message"
33 >                        " FROM messages WHERE id='"
34 >                        + lexical_cast<ext::String>(buddy->getId()) + "'"));
35 >                std::vector<AwayMessage> messages_;
36 >
37 >                while (messages->MoveNext())
38 >                        messages_.push_back(AwayMessage(messages->GetString("message"),
39 >                        messages->GetString("stamp")));
40 >
41 >                Rss rss(*buddy, messages_, stamp);
42 >                Atom atom(*buddy, messages_, stamp);
43 >
44 >                cout << bright << yellow << "Updated feeds for " << blue << *buddy
45 >                        << yellow << ".\n" << reset;
46 >        }
47  
48 <        // publish
48 >        cout << bright << yellow << "Finished updating feeds at " << Stamp()
49 >                << ".\n" << reset;
50   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines