예제 #1
0
class shanbay_study():
    def __init__(self, client_id):
        self.client_id = client_id
        f = open("token.json", "r")
        self.token = json.loads(f.read())
        f.close()
        self.api = None
        self.search_words = []

    def connect(self):
        self.api = API(self.client_id, self.token)

    def batch_add_search_words(self, words):
        not_found_word = []
        added_word = []
        if self.api and len(words) != 0:
            for word in words:
                word_search = self.api.word(word)
                # there is no need add word  had been added
                if word_search["msg"] == 'SUCCESS' and (
                        'learning_id' not in word_search['data']):
                    result = self.api.add_word(word_search["data"]["id"])
                    print result
                    if result['msg'] == 'SUCCESS':
                        print "%s add word success " % word
                    else:
                        print "%s add word faile " % word

                elif word_search["msg"] != 'SUCCESS':
                    print " %s add word faile  add to no_result_word" % word
                    not_found_word.append(word)
                elif word_search["msg"] == 'SUCCESS' and (
                        'learning_id' in word_search['data']):
                    print " %s  had been added befor ,overleap it" % word
                    added_word.append(word)

        else:
            print "api has not init\n"
            sys.exit()
        return (not_found_word, added_word)
예제 #2
0
class shanbay_study():
    def __init__(self,client_id):
        self.client_id = client_id
        f=open("token.json","r")
        self.token=json.loads(f.read())
        f.close()
        self.api=None
        self.search_words=[]
        
    
    def connect(self): 
        self.api = API(self.client_id,self.token)

    def batch_add_search_words(self,words):
        not_found_word=[]
        added_word=[]
        if   self.api and len(words) != 0:
            for word in words:
                word_search = self.api.word(word)
                # there is no need add word  had been added
                if word_search["msg"] == 'SUCCESS' and  ('learning_id' not in word_search['data']):
                    result=self.api.add_word(word_search["data"]["id"])
                    print result
                    if result['msg'] == 'SUCCESS':
                        print "%s add word success " % word
                    else:
                        print "%s add word faile " % word

                elif word_search["msg"] != 'SUCCESS' :
                    print " %s add word faile  add to no_result_word" % word 
                    not_found_word.append(word)
                elif word_search["msg"] == 'SUCCESS' and  ('learning_id'  in word_search['data']):
                    print " %s  had been added befor ,overleap it" % word 
                    added_word.append(word)

        else:
            print "api has not init\n"
            sys.exit()
        return (not_found_word,added_word) 
예제 #3
0
 def connect(self):
     self.api = API(self.client_id, self.token)
예제 #4
0
 def connect(self): 
     self.api = API(self.client_id,self.token)