def subprocess_task_twitter_user(li, queue, redis_task, target_language='zh-cn'): #[[uid, description, location], ...] text_list = [] for l in li: text_list.extend(l[1:]) results = trans(text_list, target_language) if results: for i in range(len(li)): description, location = results[2*i : 2*i + 2] # queue.put([li[i][0], description, location]) queue.put([li[i][0], traditional2simplified(description), traditional2simplified(location)]) return True else: #翻译失败,如果任务出错,则重新加入队列中 for l in li: r.lpush(redis_task, l) time.sleep(10) return False
def subprocess_task_facebook_user(li, queue, redis_task, target_language='zh-cn'): text_list = [] for l in li: text_list.extend(l[1:]) results = trans(text_list, target_language) if results: for i in range(len(li)): bio_list = results[4*i : 4*i + 4] bio_str = '_'.join(bio_list) # queue.put([li[i][0], bio_str]) queue.put([li[i][0], traditional2simplified(bio_str)]) return True else: #翻译失败,如果任务出错,则重新加入队列中 for l in li: r.lpush(redis_task, l) time.sleep(10) return False
def subprocess_task(li, queue, redis_task, target_language='zh-cn'): text_list = [] id_list = [] for l in li: id_list.append(l[0]) text_list.append(l[1]) results = trans_with_detail(text_list, target_language) if results: for i in range(len(li)): if results[i][1] == 'zh-CN': flag_ch = 1 else: flag_ch = 0 #[id, text_ch, flag_ch, date] queue.put([li[i][0], results[i][0], flag_ch, li[i][2]]) return True else: #翻译失败,如果任务出错,则重新加入队列中 for l in li: r.lpush(redis_task, l) time.sleep(10) return False
def init_data(redis_task, length): for i in range(length): r.lpush(redis_task, [i, i + 1])