def test_get_file_content():
    """Valid file"""
    script_folder = os.path.dirname(os.path.abspath(__file__))
    file_name = os.path.join(script_folder, "data", "demo.txt")
    expected = "hello world"
    actual = file_utils.get_file_content(file_name)
    print_test_results(file_utils.get_file_content, expected, actual)

    """Non-existent file"""
    script_folder = os.path.dirname(os.path.abspath(__file__))
    file_name = os.path.join(script_folder, "data", "bogus.txt")
    expected = '{} does not exist'.format (file_name)
    actual = file_utils.get_file_content(file_name)
    print_test_results(file_utils.get_file_content, expected, actual)
Ejemplo n.º 2
0
def test_get_file_content():
    file_name = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "data", "demo.txt")
    desc = "read the file contents"
    expected = "Today is snowy"
    actual = fu.get_file_content(file_name)
    print_test_results(fu.get_file_content, desc, expected, actual)
Ejemplo n.º 3
0
def start_producing():
    args = parser.parse_args()

    all_persons = get_file_content(args.json_file)
    if all_persons is None:
        return

    kafka_producer = connect_kafka_producer()
    if kafka_producer:
        for person in all_persons:
            publish_message(kafka_producer, args.topic, person)
        if kafka_producer is not None:
            kafka_producer.close()
Ejemplo n.º 4
0
 def get_one(self, report_id):
     """
     根据ReportId获取单个报告的xml信息
     :param report_id:
     """
     # 如果本地存在,则不再重复读取
     try:
         content = get_file_content(report_id, report_id + '.xml')
     except FileNotExist, ex:
         r = self._get_service.get_report(report_id)
         content = r.text
         # 保存到本地
         save_file(content, report_id, report_id + '.xml')
Ejemplo n.º 5
0
 def get_items_by_report_id(self, report_id, start_day=None):
     # 保存到本地的文件名
     if start_day:
         name = 'week_%s_%s.txt' % (start_day, report_id)
     else:
         name = 'week_%s.txt' % report_id
     content = get_file_content('advertising', name)
     if not content:
         r = self.get_by_report_id(report_id)
         # 保存到本地
         save_file(r.text, 'advertising', name)
         content = r.text
     parser = AdvertisingParser(content)
     return parser.get_items()
Ejemplo n.º 6
0
def decrypt(file, key):
    try:
        file_content = file_utils.get_file_content(file)

        if file_content:
            new_file = file_utils.store_file_content(
                caesar_cipher.decrypt(file_content, key), 'decripted.txt')
            print(f'Content stored on {new_file}')

        else:
            print(f'The file {file} is empty')

    except FileNotFoundError:
        print(f'The file {file} does not exists')
    except ValueError:
        print('The selected key does not exists in the alphabet')