Skip to content

Commit

Permalink
Listens on zerorpc now
Browse files Browse the repository at this point in the history
  • Loading branch information
vranki committed Mar 22, 2015
1 parent 0f54025 commit ffea175
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
pajabot
Pajabot
=======

IRC bot & utilities for hackerspace management. Target hw: Raspberry pi.

Dependencies:
* Python irclib, https://bitbucket.org/jaraco/irc
* Python Imaging Library (PIL), http://www.pythonware.com/products/pil/
* Python Imaging Library fork (Pillow)
* Python Feedparser

Installing dependencies to Raspbian:

* sudo pip install irc
* sudo apt-get install python-imaging
* sudo apt-get install python-feedparser
* pip install irc gevent feedparser Pillow zerorpc pyzmq

Running
=======

Still heavily WIP and undocumented - stay tuned!
cp bot.conf local.conf
./bot/pajabot.py

31 changes: 18 additions & 13 deletions bot/pajabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
import feedparser
import glob
import imp
import gevent
import zerorpc
import zmq

from irc.bot import ServerSpec
from irc.bot import SingleServerIRCBot
from irc.client import SimpleIRCClient
from irc.client import Reactor

from rpi_camera import RPiCamera
from spaceapi import SpaceAPI
Expand Down Expand Up @@ -48,10 +53,12 @@ class PajaBot(SingleServerIRCBot):
def __init__(self):
config = ConfigParser.ConfigParser()

configfile = '/home/pi/pajabot/bot.conf'
if (os.path.isfile('/home/pi/pajabot/local.conf')):
configfile = '/home/pi/pajabot/local.conf'

configfile = '~/pajabot/bot.conf'
if (os.path.isfile('~/pajabot/local.conf')):
configfile = '~/pajabot/local.conf'
if (os.path.isfile('local.conf')):
configfile = 'local.conf'
print "Reading config from " + configfile
config.read(configfile)

self.server = config.get("bot","server")
Expand Down Expand Up @@ -113,7 +120,7 @@ def run(self):
self.checkLights()
if (self.vaasa): self.read_feed()
try:
self.ircobj.process_once(0.2)
self.reactor.process_once(0.2)
except UnicodeDecodeError:
pass
# print 'Somebody said something in non-utf8'
Expand All @@ -132,7 +139,7 @@ def read_feed(self):
latest = rssfeed.entries[len(rssfeed.entries)-1]

if latest.id in self.rss_timestamp:
variable = 2
variable = 2
else:
self.rss_timestamp = latest.id
try:
Expand Down Expand Up @@ -193,9 +200,6 @@ def sayDoorStatus(self):
def on_nicknameinuse(self, c, e):
c.nick(c.get_nickname() + "_")

# def on_disconnect(self, c, e):
# raise SystemExit()

def on_pubmsg(self, c, e):
cmd = e.arguments[0].split()[0]

Expand Down Expand Up @@ -223,10 +227,6 @@ def on_pubmsg(self, c, e):
self.say('printer is offline')
print('p: ' + str(ping_response))

# if (cmd=='!printteri'):
# commands['PRINTTERI'].index(self, c,e)


if cmd=='!shot':
self.camera.takeShotCommand()
c.privmsg(self.channel, self.shoturl + ('' if self.lightStatus else ' (pretty dark, eh)'))
Expand Down Expand Up @@ -255,5 +255,10 @@ def restart_program(self):


bot = PajaBot()
s = zerorpc.Server(bot)
s._events.setsockopt(zmq.IPV4ONLY, 0)
s.bind("tcp://[::1]:4144")
gevent.spawn(s.run)

bot.run()

7 changes: 5 additions & 2 deletions bot/spaceapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def __init__(self, url):

def updateStatus(self, labOpen, topic):
print "Setting lab open " + str(labOpen) + " and topic " + topic
self.c.updateStatus(labOpen, topic)
print "Update ok"
try:
self.c.updateStatus(labOpen, topic)
except:
print "Update failure"


0 comments on commit ffea175

Please sign in to comment.