Skip to content

Commit 1a78ab1

Browse files
committed
Added network publisher.
1 parent 6883f7e commit 1a78ab1

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

ircb/publishers/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from ircb.publishers.logs import MessageLogPublisher
3+
from ircb.publishers.networks import NetworkPublisher
34

45
if __name__ == '__main__':
56
import asyncio
@@ -15,7 +16,11 @@
1516
except:
1617
print("Usage: __init__.py '<hostname>' '<roomname>' '<user_id>'")
1718
sys.exit(1)
18-
publisher = MessageLogPublisher(hostname, roomname, int(user_id))
19-
publisher.run()
19+
message_log_pub = MessageLogPublisher(hostname, roomname, int(user_id))
20+
message_log_pub.run()
21+
22+
network_pub = NetworkPublisher(int(user_id))
23+
network_pub.run()
24+
2025
loop = asyncio.get_event_loop()
2126
loop.run_forever()

ircb/publishers/networks.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from ircb.storeclient import NetworkStore
4+
5+
from .base import BasePublisher
6+
7+
8+
class NetworkPublisher(BasePublisher):
9+
10+
name = 'networks'
11+
store = NetworkStore
12+
13+
def __init__(self, user_id):
14+
super().__init__()
15+
self.user_id = user_id
16+
17+
@property
18+
def id(self):
19+
return '{name}::{user_id}'.format(
20+
name=self.name, user_id=self.user_id)
21+
22+
def fetch(self):
23+
results = yield from NetworkStore.get({
24+
'query': {
25+
'user_id': self.user_id
26+
}
27+
}, raw=True)
28+
return results
29+
30+
def skip_create(self, data):
31+
return self.skip_update(data)
32+
33+
def skip_update(self, data):
34+
return data['user_id'] != self.user_id

0 commit comments

Comments
 (0)