plugins/fact_plugin.py
changeset 0 93b25987d3e5
child 17 069f7fd5545d
equal deleted inserted replaced
-1:000000000000 0:93b25987d3e5
       
     1 #$ neutron_plugin 01
       
     2 
       
     3 ELEMENT_FILE = 'static/elements.txt'
       
     4 TLD_FILE = 'static/tlds.txt'
       
     5 
       
     6 def fact_element(query):
       
     7 	fp = open(ELEMENT_FILE, 'r')
       
     8 	while 1:
       
     9 		line = fp.readline()
       
    10 		if not line:
       
    11 			return 'Not Found'
       
    12 		(key, value) = string.split(line, ' ', 1)
       
    13 		if string.lower(query).strip() == string.lower(key).strip():
       
    14 			return value.strip()
       
    15 
       
    16 def fact_tld(query):
       
    17 	fp = open(TLD_FILE, 'r')
       
    18 	while 1:
       
    19 		line = fp.readline()
       
    20 		if not line:
       
    21 			return 'Not Found'
       
    22 		(key, value) = string.split(line, ': ', 1)
       
    23 		if string.lower(query).strip() == string.lower(key).strip():
       
    24 			return value.strip()
       
    25 
       
    26 def handler_fact_element(type, source, parameters):
       
    27 	result = fact_element(parameters.strip())
       
    28 	smsg(type, source, result)
       
    29 
       
    30 def handler_fact_tld(type, source, parameters):
       
    31 	result = fact_tld(parameters.strip())
       
    32 	smsg(type, source, result)
       
    33 
       
    34 #register_command_handler(handler_fact_element, '!element', 0, 'Returns the name and number of an atomic element code.', '!element <code>', ['!element Li'])
       
    35 
       
    36 register_command_handler(handler_fact_tld, '!tld', 0, 'Returns the location for a top level domain or a TLD for a location.', '!tld <location/TLD>', ['!tld com', '!tld antarctica'])