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