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)
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ # Pylons paths from ConfigObject import ConfigObject cfg = ConfigObject(filename=os.path.expanduser('~/.afpy.cfg')) app_conf['beaker.session.secret'] = '%s' % cfg.authtkt.shared_secret root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='members', paths=paths) config['routes.map'] = make_map() config['pylons.app_globals'] = app_globals.Globals() config['pylons.h'] = members.lib.helpers # Create the Mako TemplateLookup, with the default auto-escaping config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], error_handler=handle_mako_error, module_directory=os.path.join(app_conf['cache_dir'], 'templates'), input_encoding='utf-8', output_encoding='utf-8', imports=['from webhelpers.html import escape'], default_filters=['escape']) # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) config['pylons.strict_tmpl_context'] = False
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))
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'))
def __init__(self, filename=None, name=None): if name is None: name, _ = os.path.splitext(os.path.basename(filename)) h = md5(name).hexdigest() data = os.path.expanduser(os.path.join('~/.freeboxtv', 'data', h[:2], h[2:4], h[4:6], h)) if not os.path.isdir(os.path.dirname(data)): os.makedirs(os.path.dirname(data)) self.config = ConfigObject(filename=data) self.data = data = self.config.data self.write = self.config.write if not self.file and filename: data.name = name data.file = filename self.write()
def get_config(): filename = join(os.path.dirname(__file__), 'config.ini') return ConfigObject(filename=filename)
# -*- 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()
# -*- coding: utf-8 -*- from ConfigObject import ConfigObject import sys import os filename = os.path.expanduser(os.path.join('~/.freeboxtv', 'config.ini')) dirname = os.path.dirname(filename) if not os.path.isdir(dirname): os.makedirs(dirname) config = ConfigObject(filename=filename) config.__name__ = __name__ config.__file__ = __file__ config.__path__ = __file__ sys.modules[__name__] = config