def create(cls): d = OrderedDict() d['server'] = OrderedDict() d['server']['url'] = 'irc.freenode.net' d['server']['port'] = '6667' d['bot'] = OrderedDict() d['bot']['nick'] = 'QircBug' d['bot']['ident'] = 'QircBug' d['bot']['realname'] = 'QirckyBotBug' d['bot']['password'] = '' d['bot']['owner'] = 'unaffiliated/nbaztec' d['startup'] = OrderedDict() d['startup']['channels'] = '#nbaztec' d['startup']['notice-to'] = 'nbaztec' d['startup']['notice-msg'] = 'Qirc is now online.' #d['global'] = OrderedDict() #d['global']['flags'] = 'ubhkv' #d['global']['logging'] = 'true' d['logs'] = OrderedDict() d['logs']['dir'] = 'logs-ignore/' d['logs']['file-format'] = '{timestamp:[%Y-%m-%d]}{channel}.log' d['logs']['buffer-len'] = '256' ConfigManager.write_config(cls._file, d)
def read(cls, section=None): if os.path.exists(cls._file): d = ConfigManager.read_config(cls._file) if d: config = d config['server']['port'] = int(config['server']['port']) config['bot']['attempt-nick'] = config['bot']['nick'] config['bot']['owner'] = config['bot']['owner'].split(' ') config['startup']['channels'] = config['startup']['channels'].split(' ') config['startup']['notice-to'] = config['startup']['notice-to'].split(' ') if len(config['bot']['password']) == 0: config['bot']['password'] = None if section: if config.has_key(section): return config[section] else: return config return None
def read(cls, section=None): if os.path.exists(cls._file): d = ConfigManager.read_config(cls._file) if d: config = d config['server']['port'] = int(config['server']['port']) config['bot']['attempt-nick'] = config['bot']['nick'] config['bot']['owner'] = config['bot']['owner'].split(' ') config['startup']['channels'] = config['startup'][ 'channels'].split(' ') config['startup']['notice-to'] = config['startup'][ 'notice-to'].split(' ') if len(config['bot']['password']) == 0: config['bot']['password'] = None if section: if config.has_key(section): return config[section] else: return config return None
''' Created on Jan 12, 2013 @author: Nisheeth Barthwal @author: Anurag Panda @summary: Posts IRC message at twitter ''' import urllib import urllib2 import json from Util import OAuth from Util.Config import ConfigManager config = ConfigManager.read_config('extensions.conf', 'twitter') oauth_consumer = OAuth.OAuthConsumer(key=config['consumer-key'], secret=config['consumer-secret']) oauth_token = OAuth.OAuthToken(key=config['access-key'], secret=config['access-secret']) def twitter_api_send(method, url, data, oa_consumer, oa_token=None, host='https://api.twitter.com'): ''' @param method: POST or GET @param url: The url to request against @param data: dict of data to send @param oa_consumer: Instance of OAuthConsumer @param oa_token: Instance of OAuthToken ''' url = host + url headers = {} request = OAuth.OAuthRequest.from_consumer_and_token(oa_consumer, token=oa_token, http_url=url, http_method=method, parameters=data) request.sign_request(OAuth.OAuthSignatureMethod_HMAC_SHA1(), oa_consumer, oa_token)
Created on Jun 30, 2012 @author: Nisheeth ''' import socket import urllib import urllib2 import json import re from Util.Log import Log from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util import htmlx config = ConfigManager.read_config('extensions.conf', 'google') #config = { # 'google' : 'AIzaSyAMajmwMaD4uPv1EuXn_WzC-9T61GZW5gw', # } url_regex = re.compile(r'^https?://([^/]+)(.*)$') def min_url(url, maxlen=20): idx = url.find('://') if idx != -1: url = url[idx+3:] if len(url) > maxlen: url = url[:maxlen/2] + '...' + url[-maxlen/2:] return url def dns(url):
''' Created on Jun 8, 2012 @author: Nisheeth @summary: Provides searches for word definitions ''' import urllib import urllib2 import re from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util import htmlx from Util.Log import Log config = ConfigManager.read_config('extensions.conf') #{ # 'google' : 'AIzaSyAMajmwMaD4uPv1EuXn_WzC-9T61GZW5gw', # 'stands4' : {'userid': '2263', 'token': 'zMYpRyvDST3POUPd'} # } def googledefine(query, num=1): ''' @param query: Query for searching @param num: Return the (n)th result @summary: Performs a Google search and returns the first result @attention: Google's description requires unescaping twice ''' try: response = urllib2.urlopen('https://www.googleapis.com/customsearch/v1?key=%s&cx=013036536707430787589:_pqjad5hr1a&q=define+%s&alt=atom&num=%d' % (config['google']['app-id'], urllib.quote(query), num)) page = response.read() response.close()
''' Created on Jun 8, 2012 @author: Nisheeth @summary: Provides provision for location tracking ''' import urllib import urllib2 from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util.Log import Log config = ConfigManager.read_config('extensions.conf', 'ipinfo') #config = { # 'ipinfo' : '7cc52ff3504c129fd61b2de112874fe54c020a57e981fbb20fc41d200e8c4c7d' # } def iplocate(ip): ''' @param ip: The IP address @summary: Performs a IP lookup and obtains the location of the user ''' try: response = urllib2.urlopen('http://api.ipinfodb.com/v3/ip-city/?key=%s&format=xml&ip=%s' % (config['app-id'], urllib.quote(ip))) page = response.read() response.close() soup = BeautifulSoup(page) reply = soup.find('response') if reply.find('statuscode').find(text=True) == "OK": r_lat = str((reply.find('latitude').find(text=True))) r_long = str(reply.find('longitude').find(text=True))
''' Created on Jun 8, 2012 @author: Nisheeth @summary: Provides calculation provisions using various sites ''' import re import urllib import urllib2 from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util import htmlx from Util.Log import Log import json config = ConfigManager.read_config('extensions.conf', 'wolfram') #config = { # 'wolf' : 'RU4KX6-XJY2PPE93Y', # } def wolfram(query): ''' @param query: Query for calculation @summary: Performs calculation on Wolfram Alpha and returns the results ''' try: response = urllib2.urlopen('http://api.wolframalpha.com/v2/query?appid=%s&input=%s&format=plaintext' % (config['app-id'], urllib.quote(query))) page = response.read() response.close()
''' Created on Jan 12, 2013 @author: Nisheeth Barthwal @author: Anurag Panda @summary: Posts IRC message at twitter ''' import urllib import urllib2 import json from Util import OAuth from Util.Config import ConfigManager config = ConfigManager.read_config('extensions.conf', 'twitter') oauth_consumer = OAuth.OAuthConsumer(key=config['consumer-key'], secret=config['consumer-secret']) oauth_token = OAuth.OAuthToken(key=config['access-key'], secret=config['access-secret']) def twitter_api_send(method, url, data, oa_consumer, oa_token=None, host='https://api.twitter.com'): ''' @param method: POST or GET @param url: The url to request against @param data: dict of data to send
Created on Jun 30, 2012 @author: Nisheeth ''' import socket import urllib import urllib2 import json import re from Util.Log import Log from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util import htmlx config = ConfigManager.read_config('extensions.conf', 'google') #config = { # 'google' : 'AIzaSyAMajmwMaD4uPv1EuXn_WzC-9T61GZW5gw', # } url_regex = re.compile(r'^https?://([^/]+)(.*)$') def min_url(url, maxlen=20): idx = url.find('://') if idx != -1: url = url[idx + 3:] if len(url) > maxlen: url = url[:maxlen / 2] + '...' + url[-maxlen / 2:] return url
''' Created on Jun 8, 2012 @author: Nisheeth @summary: Provides provisions for weather and forecasting ''' import urllib import urllib2 from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util.Log import Log config = ConfigManager.read_config('extensions.conf', 'worldweather') #config = { # 'worldweather' : '8c7d2c19fc192331121509', # } def to_celcius(f): return (float(f) - 32) * 5 / 9 def google_weather(place): ''' @param term: Term for searching @summary: Performs a urban dictionary search and returns the first result ''' try: response = urllib2.urlopen('http://www.google.com/ig/api?weather=%s' % urllib.quote(place)) page = response.read()
""" Created on Jun 8, 2012 @author: Nisheeth @summary: Provides provisions for weather and forecasting """ import urllib import urllib2 from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util.Log import Log config = ConfigManager.read_config("extensions.conf", "worldweather") # config = { # 'worldweather' : '8c7d2c19fc192331121509', # } def to_celcius(f): return (float(f) - 32) * 5 / 9 def google_weather(place): """ @param term: Term for searching @summary: Performs a urban dictionary search and returns the first result """ try: response = urllib2.urlopen("http://www.google.com/ig/api?weather=%s" % urllib.quote(place)) page = response.read() response.close()
''' Created on Jun 8, 2012 @author: Nisheeth @summary: Provides searches for word definitions ''' import urllib import urllib2 import re from Util.BeautifulSoup import BeautifulSoup from Util.Config import ConfigManager from Util import htmlx from Util.Log import Log config = ConfigManager.read_config('extensions.conf') #{ # 'google' : 'AIzaSyAMajmwMaD4uPv1EuXn_WzC-9T61GZW5gw', # 'stands4' : {'userid': '2263', 'token': 'zMYpRyvDST3POUPd'} # } def googledefine(query, num=1): ''' @param query: Query for searching @param num: Return the (n)th result @summary: Performs a Google search and returns the first result @attention: Google's description requires unescaping twice ''' try: response = urllib2.urlopen( 'https://www.googleapis.com/customsearch/v1?key=%s&cx=013036536707430787589:_pqjad5hr1a&q=define+%s&alt=atom&num=%d'