# -*- coding: utf-8 -*-

import os
import shutil
import unicodedata
import webbrowser

import requests
from wox import Wox,WoxAPI
from bs4 import BeautifulSoup

URL = 'http://www.dictionary.com/browse/'

def full2half(uc):
    """Convert full-width characters to half-width characters.
    """
    return unicodedata.normalize('NFKC', uc)

class Main(Wox):
  
    def request(self,url):
	#get system proxy if exists
        if self.proxy and self.proxy.get("enabled") and self.proxy.get("server"):
	    proxies = {
		"http":"http://{}:{}".format(self.proxy.get("server"),self.proxy.get("port")),
		"https":"http://{}:{}".format(self.proxy.get("server"),self.proxy.get("port"))
	    }
	    return requests.get(url,proxies = proxies)
	return requests.get(url)
			
    def query(self, param):
	r = self.request(URL + param.strip())
	bs = BeautifulSoup(r.content, 'html.parser')
	wordType = bs.find('header', 'luna-data-header').text
        means = bs.find('section', 'def-pbk ce-spot').find_all('div', 'def-set')
	result = []
	for m in means:

            title = m.text
            subtitle = wordType
            
            item = {
                'Title': full2half(title),
                'SubTitle': subtitle,
                'IcoPath': os.path.join('img', 'dc.png')
            }
            result.append(item)
        
	return result
    
    def open_url(self, url):
	webbrowser.open(url) #use default browser

if __name__ == '__main__':
    Main()

@@ -816,16 +816,8 @@
 aram
-.strip()
 )%0A%09b
@@ -871,16 +871,35 @@
 rdType =
+ %22%22%0A%09means = %5B%5D%0A%09if
  bs.find
@@ -928,22 +928,147 @@
 header')
-.text%0A
+:%0A            wordType = bs.find('header', 'luna-data-header').get_text(strip=True)%0A%09if bs.find('section', 'def-pbk ce-spot'):%0A    
         
@@ -1140,16 +1140,17 @@
 f-set')%0A
+%0A
 %09result 
@@ -1154,16 +1154,27 @@
 lt = %5B%5D%0A
+%09index = 0%0A
 %09for m i
@@ -1182,17 +1182,16 @@
  means:%0A
-%0A
         
@@ -1208,57 +1208,55 @@
 = m.
-text%0A            subtitle = wordType%0A            
+find('div', 'def-content').get_text(strip=True)
 %0A   
@@ -1308,16 +1308,40 @@
 ll2half(
+str(index + 1) + %22: %22 + 
 title),%0A
@@ -1364,23 +1364,23 @@
 'Sub
-T
+t
 itle': 
-subtitl
+wordTyp
 e,%0A 
@@ -1489,16 +1489,41 @@
         
+    index+=1%0A            
 %0A%09return

fix None exception