<RequestAction>Track</RequestAction> <RequestOption>activity</RequestOption> </Request> <TrackingNumber>%s</TrackingNumber> </TrackRequest>''' % (num, num) body = body.encode('ascii') status, response = request('POST', 'https://wwwcie.ups.com/ups.app/xml/Track', body) #logging.debug(response) tree = ElementTree.fromstring(response) for status in tree.findall('Shipment/Package/Activity'): city = status.findtext('ActivityLocation/Address/City') state = status.findtext('ActivityLocation/Address/StateProvinceCode') dt = '%s:%s' % (status.findtext('Date'), status.findtext('Time')) dt = datetime.strptime(dt, '%Y%m%d:%H%M%S') desc = status.findtext('Status/StatusType/Description') msg = '%s %s: %s' % (dt.strftime('%a %d - %H:%M'), num, desc) if city and state: msg = '%s (%s, %s)' % (msg, city, state) if not msg in self.cache: self.recv(msg) self.cache.append(msg) self.data['cache'] = json.dumps(self.cache) if __name__ == '__main__': become_daemon() start_app(UPS, user=sys.argv[1])
from netgrowl import GrowlRegistrationPacket, GrowlNotificationPacket, GROWL_UDP_PORT from socket import socket, AF_INET, SOCK_DGRAM import logging class Growl(FooApp): name = 'growl' config_opts = { 'target': 'IP address to send growl notifications to', } def __init__(self, server=None): FooApp.__init__(self, server) self.data = FileStore('/tmp/apps/growl') self.sock = socket(AF_INET, SOCK_DGRAM) p = GrowlRegistrationPacket(application='foobox', password='') p.addNotification('Message', enabled=True) self.sock.sendto(p.payload(), (self.data['target'], GROWL_UDP_PORT)) def send(self, msg): p = GrowlNotificationPacket(application='foobox', notification='Message', title=msg['src'], description=msg['text']) self.sock.sendto(p.payload(), (self.data['target'], GROWL_UDP_PORT)) if __name__ == '__main__': become_daemon() start_app(Growl)
%s''' % (self.config['mail']['from_address'], self.config['mail']['to_address'], '[foobox] %s: %s' % (msg['src'], teaser), msg['text']) host = self.config['mail']['smtp_server'] if host.rfind(':') != -1: host, port = host.rsplit(':', 1) else: port = 25 port = int(port) logging.debug('Sending mail via %s:%s' % (host, port)) try: server = SMTP(host, port) server.sendmail(self.config['mail']['from_address'], self.config['mail']['to_address'], msg) server.quit() logging.info('Sent email to %s' % self.config['mail']['to_address']) except: logging.error('Error sending mail: %s' % format_exc()) def run(self): while True: self.update() sleep(300) def update(self): pass if __name__ == '__main__': become_daemon() start_app(Mail)
'port': 'The port hellanzb is running on. The default is 8760', } def __init__(self, server=None): FooApp.__init__(self, server) self.hellaserver = ServerProxy('http://*****:*****@%s:%s/' % (self.data['password'], self.data['server'], self.data['port'])) self.data = FileStore('/tmp/apps/hella') try: self.cache = json.loads(self.data['cache']) except: self.cache = [] def send(self, msg): response = self.hellaserver.enqueuenewzbin(int(msg['text'])) return def run(self): while True: status = self.hellaserver.status() for entry in status['log_entries']: for key, value in entry.items(): if not value in self.cache: self.recv('%s: %s' % (self.name, value)) self.cache.append(value) self.data['cache'] = json.dumps(self.cache) sleep(10) if __name__ == '__main__': become_daemon() start_app(Hella)
def send(self, msg): if not msg['text'] in self.feeds: self.feeds.append(msg['text']) self.data['feeds'] = json.dumps(self.feeds) self.update() def run(self): while True: self.update() sleep(3600) def update(self): for url in self.feeds: if not url in self.cache: self.cache[url] = [] cache = self.cache[url] d = feedparser.parse(url) for entry in d.entries: msg = '%s: %s' % (d.feed.title, entry.title) if msg in cache: continue self.recv(msg) cache.append(msg) self.data['cache'] = json.dumps(self.cache) if __name__ == '__main__': become_daemon() start_app(RSS, user=sys.argv[1])
def send(self, msg): while True: try: status = self.api.post_message('public', msg['text']) break except: logging.error(format_exc()) sleep(30) continue def run(self): while True: try: timeline = self.api.get_notes(self.data['username']) except: logging.error(format_exc()) sleep(30) continue for note in timeline: msg = '%s %s' % (note.sender.short_name, note.body) if not msg in self.cache: self.recv(msg) self.cache.append(msg) self.data['cache'] = json.dumps(self.cache) sleep(120) if __name__ == '__main__': become_daemon() start_app(Pownce, listen_port=9993)
from fooapp import FooApp, start_app import logging from ncore.daemon import become_daemon from eliza import eliza try: import json except ImportError: import simplejson as json class Bot(FooApp): name = "bot" config_opts = {} def __init__(self, server=None): FooApp.__init__(self, server) self.eliza = eliza() def send(self, msg): # ask eliza a question self.recv(self.eliza.respond(msg["text"])) if __name__ == "__main__": become_daemon() start_app(Bot)
pass sleep(0.4) def recv(self, client, msg): logging.debug('Jabber got message') if not str(msg.getFrom()).startswith(self.data['target']): return if not msg.getBody().startswith('!'): FooApp.recv(self, msg.getBody()) else: prefix, msg = msg.getBody().split(' ', 1) prefix = prefix.lstrip('!') FooApp.recv(self, msg, dst=prefix) return def DisconnectHandler(self): logging.info('Jabber disconnected from server. Reconnecting...') try: self.reconnectAndReauth() logging.info('Connected to server.') except: logging.error('Error attempting to reconnect: %s' % format_exc()) def run(self): while self.client.isConnected(): self.client.Process(1) if __name__ == '__main__': become_daemon() start_app(Jabber)
continue for i in range(count): if 'var message%i' % (i + 1) in line: msg = line.split('=', 1)[1].strip(" ;'\n") msg = [x for x in msg.split('<br>') if x] msg = '; '.join(msg) yield msg if count > 0 and len(messages) == count: break response.close() return def run(self): while True: self.update() sleep(300) def update(self): for q in self.queries: messages = list(self.query(q)) msg = '\n'.join(messages) if not msg in self.cache: self.recv(msg) self.cache.append(msg) self.data['cache'] = json.dumps(self.cache) if __name__ == '__main__': become_daemon() start_app(GoogleSMS, sys.argv[1])