ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/zoe/trunk/Publisher.cpp
Revision: 38
Committed: 2004-07-22T22:42:40-07:00 (20 years, 11 months ago) by douglas
File size: 1947 byte(s)
Log Message:
Yeah, did stuff.

File Contents

# Content
1 // Zoe AIM Away Message RSS Feed Generator
2 //
3 // Seth King and Douglas Thrift
4 //
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, bool start) : buddies(buddies),
12 database(database), start(start)
13 {
14 if (start) publisher.Spawn(etl::Bind<0>(&Publisher::publish, this));
15 }
16
17 int Publisher::publish()
18 {
19 cerr << bright << green << "Started publisher daemon at " << Stamp()
20 << ".\n" << reset;
21
22 while (true)
23 {
24 Stamp now, next(now + Hour(1));
25 api::Thread thread(etl::Bind<0>(&Publisher::update, this));
26
27 next.setSeconds(0);
28 next.setMinutes(0);
29
30 if (Zoe::debug) cerr << "now = " << now << "\nnext = " << next << '\n';
31
32 while (now < next - Minute(1))
33 {
34 sleep(Minute(1));
35
36 now = Stamp();
37 }
38
39 while (now < next)
40 {
41 sleep(1);
42
43 now = Stamp();
44 }
45
46 thread.Join();
47 }
48 }
49
50 int Publisher::update()
51 {
52 cerr << bright << yellow << "Started updating feeds at " << Stamp()
53 << ".\n" << reset;
54
55 Stamp stamp;
56 ext::Handle<dbi::Connection> db(dbi::Connect(database.driver, database.host,
57 database.user, database.password, database.db));
58
59 db->Execute("DELETE FROM messages WHERE stamp<'" + ext::String(stamp - Day(30)) + "'");
60
61 for (std::set<Buddy>::const_iterator buddy(buddies.begin());
62 buddy != buddies.end(); ++buddy)
63 {
64 ext::Handle<dbi::ResultSet> messages(db->Execute("SELECT stamp, message FROM messages WHERE id='"
65 + lexical_cast<ext::String>(buddy->getId()) + "'"));
66 std::vector<AwayMessage> messages_;
67
68 while (messages->MoveNext()) messages_.push_back(AwayMessage(messages->GetString("message"),
69 messages->GetString("stamp")));
70
71 Rss rss(*buddy, messages_, stamp);
72 Atom atom(*buddy, messages_, stamp);
73
74 cerr << bright << yellow << "Updated feeds for " << blue << *buddy
75 << yellow << ".\n" << reset;
76 }
77
78 cerr << bright << yellow << "Finished updating feeds at " << Stamp()
79 << ".\n" << reset;
80 }

Properties

Name Value
svn:eol-style native
svn:keywords Id