def main(): config = ConfigObject(defaults=dict(here=os.getcwd())) config.read(os.path.expanduser('~/.alainrc')) conn = IRCConnection('irc.freenode.net', 6667, config.bot.nick + '_', verbosity=config.bot.verbosity.as_int(), logfile=config.bot.logfile or None) conn.config = config conn.channel = config.bot.channel conn.services = services conn.connect() time.sleep(3) conn.ghost() bot = Alain(conn) bot.config = config bot.channel = config.bot.channel bot.sudoers = sudoers bot.messages = [] conn.join(config.bot.channel) time.sleep(2) conn.respond('matin', config.bot.channel) try: conn.enter_event_loop() except Exception, e: conn.logger.exception(e)
class Connection(object): node_class = Node user_class = User group_class = GroupOfNames perm_class = None def __init__(self, section='ldap', prefix='ldap.', filename=os.path.expanduser('~/.ldap.cfg')): self.config = ConfigObject() self.config.read([filename]) self.prefix = prefix self.section = self.config[section] self._conn = self.connection_factory() try: self.bind_dn = self.get('bind_dn') self.bind_pw = self.get('bind_pwd') self.base_dn = self.get('base_dn', self.bind_dn.split(',', 1)[1]) except Exception, e: raise e.__class__('Invalid configuration %s - %s' % (section, self.section)) for name in ('user', 'group', 'perm', 'node'): attr = '%s_class' % name klass = self.get('%s_class' % name, None) if klass: klass = resolve_class(klass) if getattr(self, attr) is not klass: setattr(self, attr, klass) self.bind(klass) log.warn('Setting %s to %s', attr, klass) if self.group_class.member_nodes.item_class is not self.user_class: self.group_class.member_nodes.item_class = self.user_class
def ldap2map(): """store google maps coords in a dumped dict """ config = ConfigObject() config.read(os.path.expanduser('~/.afpy.cfg')) conn = ldap.get_conn() api_key = config.get('api_keys', 'maps.google.com') filename = '/tmp/google.maps.coords.dump' users = [] for i in range(1, 10): users.extend( conn.search_nodes(filter='(&(postalCode=%s*)(street=*))' % i, attrs=['postalCode', 'st'])) addresses = {} for user in users: try: short_address = '%s, %s' % (user.postalCode.strip(), user.st.strip()) addresses[short_address] = '' except: pass if os.path.isfile(filename): coords = cPickle.load(open(filename)) else: coords = {} opener = urllib2.build_opener() for address in addresses: if address in coords: continue cp, country = address.split(', ') url = 'http://ws.geonames.org/postalCodeLookupJSON?postalcode=%s&country=%s' % ( cp, country) request = urllib2.Request(url) request.add_header('User-Agent', 'Mozilla Firefox') datas = None while not datas: try: datas = opener.open(request).read() except: time.sleep(4) coord = eval(datas) if coord and coord.get('postalcodes'): codes = coord.get('postalcodes') if codes: coords[address] = codes[0] cPickle.dump(coords, open(filename, 'w'))
# -*- coding: utf-8 -*- from ConfigObject import ConfigObject import feedparser import os config = ConfigObject(defaults=dict(here=os.getcwd())) config.read(os.path.expanduser('~/.alainrc')) cred = config.plone.user def awaiting(): feed = feedparser.parse( 'http://%[email protected]/search_rss?review_state=pending' % cred) entries = [str(e.id) for e in feed.entries] entries = [e for e in entries if '/forums/' not in e] if entries: return 'Hey! Il y a des trucs à modérer: %s' % ' - '.join(entries) return '' if __name__ == '__main__': print awaiting()