Exemple #1
0
def handle_omdb(sock, cmd_esc, cmd, line_post_cmd, channel, is_pm):
    if (line_post_cmd != ''):
        title_words = line_post_cmd.rstrip(' ').split(' ')
        for i in range(0, len(title_words)):
            if (title_words[i][0] == title_words[i][0].lower()):
                title_words[i] = title_words[i][0].upper() + title_words[i][1:]
        url = 'http://www.omdbapi.com/?t=' + (
            '+'.join(title_words)) + '&y=&plot=short&r=json'
        try:
            response = http_cat.get_page(url)
        except:
            py3queueln(
                sock, 'PRIVMSG ' + channel +
                ' :Err: Could not retrieve data (weird characters in title?)',
                1)
            return

        response_type = response[0].split("\n")[0].rstrip("\r")
        if (response_type.find('200 OK') < 0):
            py3queueln(
                sock,
                'PRIVMSG ' + channel + ' :Err: \"' + response_type + '\"', 1)
        else:
            try:
                json_tree = json.loads(response[1])
            except ValueError:
                py3queueln(
                    sock, 'PRIVMSG ' + channel +
                    ' :Err: Could not parse json response from omdb', 1)
                return

            #movie information now that retrieval is done
            title = config.get_json_param(json_tree, 'Title')
            title = '' if title == None else title
            rating = config.get_json_param(json_tree, 'imdbRating')
            rating = '' if rating == None else rating
            year = config.get_json_param(json_tree, 'Year')
            year = '' if year == None else year
            #remove unicode to be IRC-friendly
            year = year.replace('–', '-')
            genre = config.get_json_param(json_tree, 'Genre')
            genre = '' if genre == None else genre
            plot = config.get_json_param(json_tree, 'Plot')
            plot = '' if plot == None else plot

            if ((title == '') and (rating == '') and (year == '')
                    and (genre == '') and (plot == '')):
                py3queueln(
                    sock, 'PRIVMSG ' + channel +
                    ' :Err: No information (movie might not be in omdb, or might not exist)',
                    1)
            else:
                py3queueln(
                    sock, 'PRIVMSG ' + channel + ' :' + title + ' / ' +
                    rating + ' / ' + year + ' / ' + genre + ' / ' + plot, 1)
    else:
        py3queueln(
            sock, 'PRIVMSG ' + channel +
            ' :Err: omdb requires a movie title as a parameter', 1)
Exemple #2
0
def handle_omdb(sock,cmd_esc,cmd,line_post_cmd,channel,is_pm):
	if(line_post_cmd!=''):
		title_words=line_post_cmd.rstrip(' ').split(' ')
		for i in range(0,len(title_words)):
			if(title_words[i][0]==title_words[i][0].lower()):
				title_words[i]=title_words[i][0].upper()+title_words[i][1:]
		url='http://www.omdbapi.com/?t='+('+'.join(title_words))+'&y=&plot=short&r=json'
		try:
			response=http_cat.get_page(url)
		except:
			py3queueln(sock,'PRIVMSG '+channel+' :Err: Could not retrieve data (weird characters in title?)',1)
			return
		
		response_type=response[0].split("\n")[0].rstrip("\r")
		if(response_type.find('200 OK')<0):
			py3queueln(sock,'PRIVMSG '+channel+' :Err: \"'+response_type+'\"',1)
		else:
			try:
				json_tree=json.loads(response[1])
			except ValueError:
				py3queueln(sock,'PRIVMSG '+channel+' :Err: Could not parse json response from omdb',1)
				return
			
			#movie information now that retrieval is done
			title=config.get_json_param(json_tree,'Title')
			title='' if title==None else title
			rating=config.get_json_param(json_tree,'imdbRating')
			rating='' if rating==None else rating
			year=config.get_json_param(json_tree,'Year')
			year='' if year==None else year
			#remove unicode to be IRC-friendly
			year=year.replace('–','-')
			genre=config.get_json_param(json_tree,'Genre')
			genre='' if genre==None else genre
			plot=config.get_json_param(json_tree,'Plot')
			plot='' if plot==None else plot
			
			if((title=='') and (rating=='') and (year=='') and (genre=='') and (plot=='')):
				py3queueln(sock,'PRIVMSG '+channel+' :Err: No information (movie might not be in omdb, or might not exist)',1)
			else:
				py3queueln(sock,'PRIVMSG '+channel+' :'+title+' / '+rating+' / '+year+' / '+genre+' / '+plot,1)
	else:
		py3queueln(sock,'PRIVMSG '+channel+' :Err: omdb requires a movie title as a parameter',1)
Exemple #3
0
if (__name__ == '__main__'):
    print('py3_markov version ' + VERSION)

    config_file = config.dflt_cfg
    if (len(sys.argv) > 1):
        config_file = sys.argv[1]
    print('using JSON config file ' + config_file)

    #the state transition array structure,
    #which contains prefixes, suffixes, and probabilities associated with each suffix
    state_change = []

    prefix_len = None
    try:
        prefix_len = int(
            config.get_json_param(config.read_json_file(config_file),
                                  'prefix_len'))
    except ValueError:
        prefix_len = None

    if (prefix_len == None):
        prefix_len = 2
    prefix = []
    for i in range(0, prefix_len):
        prefix.append('')

    use_pg = config.get_json_param(config.read_json_file(config_file),
                                   'use_pg')
    if (use_pg == None):
        use_pg = False

    state_file = None
Exemple #4
0
#runtime
if (__name__ == '__main__'):
    config_file = config.dflt_cfg
    if (len(sys.argv) > 1):
        config_file = sys.argv[1]
    print('using JSON config file ' + config_file)

    #read the configuration from the json configuration file
    json_cfg_tree = config.read_json_file(config_file)

    #set configuration from the config file
    #if configuration for anything is omitted a default value from the code is used

    #nick
    json_bot_nick = config.get_json_param(json_cfg_tree, 'bot_nick')
    if (json_bot_nick != None):
        bot_nick = json_bot_nick

    #channels to join on startup
    json_autojoin_channels = config.get_json_param(json_cfg_tree,
                                                   'autojoin_channels')
    if (json_autojoin_channels != None):
        autojoin_channels = json_autojoin_channels

    #debug channels to join and spam
    json_dbg_channels = config.get_json_param(json_cfg_tree, 'dbg_channels')
    if (json_dbg_channels != None):
        dbg_channels = json_dbg_channels

    #server connection information (host, port, encryption)
Exemple #5
0
if(__name__=='__main__'):
	print('py3_markov version '+VERSION)
	
	config_file=config.dflt_cfg
	if(len(sys.argv)>1):
		config_file=sys.argv[1]
	print('using JSON config file '+config_file)
	
	#the state transition array structure,
	#which contains prefixes, suffixes, and probabilities associated with each suffix
	state_change=[]
	
	prefix_len=None
	try:
		prefix_len=int(config.get_json_param(config.read_json_file(config_file),'prefix_len'))
	except ValueError:
		prefix_len=None
	
	if(prefix_len==None):
		prefix_len=2
	prefix=[]
	for i in range(0,prefix_len):
		prefix.append('')
	
	use_pg=config.get_json_param(config.read_json_file(config_file),'use_pg')
	if(use_pg==None):
		use_pg=False
	
	state_file=None
	db_login=None
Exemple #6
0
#runtime
if(__name__=='__main__'):
	config_file=config.dflt_cfg
	if(len(sys.argv)>1):
		config_file=sys.argv[1]
	print('using JSON config file '+config_file)
	
	#read the configuration from the json configuration file
	json_cfg_tree=config.read_json_file(config_file)
	
	#set configuration from the config file
	#if configuration for anything is omitted a default value from the code is used
	
	#nick
	json_bot_nick=config.get_json_param(json_cfg_tree,'bot_nick')
	if(json_bot_nick!=None):
		bot_nick=json_bot_nick
	
	#channels to join on startup
	json_autojoin_channels=config.get_json_param(json_cfg_tree,'autojoin_channels')
	if(json_autojoin_channels!=None):
		autojoin_channels=json_autojoin_channels
	
	#debug channels to join and spam
	json_dbg_channels=config.get_json_param(json_cfg_tree,'dbg_channels')
	if(json_dbg_channels!=None):
		dbg_channels=json_dbg_channels
	
	#server connection information (host, port, encryption)
	json_host=config.get_json_param(json_cfg_tree,'host')