import random
import time
import logging as logger
from baidu_translate import BaiduTranslator

if __name__ == '__main__':
    translator = BaiduTranslator()
    with open('./test.txt', 'r', encoding='utf-8') as f:
        test_article = f.read()
    f.close()

    paragraphs = test_article.split('\n')
    set_size = len(paragraphs)
    count = 0
    for para in paragraphs:
        para = para.strip()
        if len(para) > 0:
            count += 1
            logger.info('No.%d/%d: %s' % (count, set_size, para))
            translator.run(para)
            sleep_time = 2 + random.random()
            logger.info('-------------------------------')
            time.sleep(sleep_time)
    translator.end_session()
