Exemplo n.º 1
0
def test_set_date_taken_without_header():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/text.txt' % folder
    shutil.copyfile(helper.get_file('valid-without-header.txt'), origin)

    text = Text(origin)
    metadata = text.get_metadata()

    with open(origin, 'r') as f:
        contents = f.read()

    assert helper.time_convert(
        (2013, 9, 30, 7, 6, 5, 0, 273,
         0)) != metadata['date_taken'], metadata['date_taken']

    status = text.set_date_taken(datetime(2013, 9, 30, 7, 6, 5))
    assert status == True, status

    text_new = Text(origin)
    metadata_new = text_new.get_metadata()

    with open(origin, 'r') as f:
        f.readline()
        contents_new = f.read()
        assert contents == contents_new, contents_new

    shutil.rmtree(folder)

    assert helper.time_convert(
        (2013, 9, 30, 7, 6, 5, 0, 273,
         0)) == metadata_new['date_taken'], metadata_new['date_taken']
Exemplo n.º 2
0
def test_set_date_taken_without_header():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/text.txt' % folder
    shutil.copyfile(helper.get_file('valid-without-header.txt'), origin)

    text = Text(origin)
    metadata = text.get_metadata()

    with open(origin, 'r') as f:
        contents = f.read()

    assert helper.time_convert((2013, 9, 30, 7, 6, 5, 0, 273, 0)) != metadata['date_taken'], metadata['date_taken']

    status = text.set_date_taken(datetime(2013, 9, 30, 7, 6, 5))
    assert status == True, status

    text_new = Text(origin)
    metadata_new = text_new.get_metadata()

    with open(origin, 'r') as f:
        f.readline()
        contents_new = f.read()
        assert contents == contents_new, contents_new

    shutil.rmtree(folder)

    assert helper.time_convert((2013, 9, 30, 7, 6, 5, 0, 273, 0)) == metadata_new['date_taken'], metadata_new['date_taken']
Exemplo n.º 3
0
def _test_photo_type_get(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

        # downloading for each test is costly so we save it in the working directory
        file_path_save_as = helper.get_file_path(photo_name)
        if os.path.isfile(photo_file):
            shutil.copyfile(photo_file, file_path_save_as)

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(
        date), '{} date {}'.format(type, metadata['date_taken'])
Exemplo n.º 4
0
def test_get_date_taken():
    photo = Photo(helper.get_file('plain.jpg'))
    date_taken = photo.get_date_taken()

    #assert date_taken == (2015, 12, 5, 0, 59, 26, 5, 339, 0), date_taken
    assert date_taken == helper.time_convert(
        (2015, 12, 5, 0, 59, 26, 5, 339, 0)), date_taken
Exemplo n.º 5
0
def _test_photo_type_get(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

        # downloading for each test is costly so we save it in the working directory
        file_path_save_as = helper.get_file_path(photo_name)
        if os.path.isfile(photo_file):
            shutil.copyfile(photo_file, file_path_save_as)

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(date), '{} date {}'.format(type, metadata['date_taken'])
Exemplo n.º 6
0
def test_update_time_on_text():
    temporary_folder, folder = helper.create_working_folder()
    temporary_folder_destination, folder_destination = helper.create_working_folder(
    )

    origin = '%s/text.txt' % folder
    shutil.copyfile(helper.get_file('text.txt'), origin)

    text = Text(origin)
    metadata = text.get_metadata()

    reset_hash_db()
    status = elodie.update_time(text, origin, '2000-01-01 12:00:00')
    restore_hash_db()

    text_processed = Text(origin)
    metadata_processed = text_processed.get_metadata()

    shutil.rmtree(folder)
    shutil.rmtree(folder_destination)

    assert status == True, status
    assert metadata['date_taken'] != metadata_processed['date_taken']
    assert metadata_processed['date_taken'] == helper.time_convert(
        (2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_taken']
Exemplo n.º 7
0
def test_update_time_on_photo():
    temporary_folder, folder = helper.create_working_folder()
    temporary_folder_destination, folder_destination = helper.create_working_folder(
    )

    origin = '%s/plain.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    reset_hash_db()
    status = elodie.update_time(photo, origin, '2000-01-01 12:00:00')
    restore_hash_db()

    photo_processed = Photo(origin)
    metadata_processed = photo_processed.get_metadata()

    shutil.rmtree(folder)
    shutil.rmtree(folder_destination)

    assert status == True, status
    assert metadata['date_taken'] != metadata_processed['date_taken']
    assert metadata_processed['date_taken'] == helper.time_convert(
        (2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_taken']
Exemplo n.º 8
0
def test_get_date_taken():
    text = Text(helper.get_file('valid.txt'))
    text.get_metadata()

    date_taken = text.get_date_taken()

    assert date_taken == helper.time_convert((2016, 4, 7, 11, 15, 26, 3, 98, 0)), date_taken
Exemplo n.º 9
0
def get_related_post(posts, last_timestamp):
    """
    Filter the parsed result after last_timestamp
    # posts[], which includes the html page string, from top to botton
    # Input: posts(list), last_timestamp(string)
    # Return: time_filter_posts(list of dict)
    # [
    #     {
    #         timeStamp:[string]
    #     },
    # ]
    """
    # posts is dict
    LOGGER.info('ENTRY')
    time_filter_posts = []
    #basiclly, first, we flat the dict, posts, to value{{post_content:[], timeStamp:[string]}}
    #second, we convert the timestamp at the flated dict, value, to datetime stamp
    #third, we filter out the content by the time condition
    for post in posts.items():
        # print last_timestamp, value['timeStamp']
        # print 'input: %s', last_timestamp, 't %s', time_convert(value['timeStamp'])
        if (last_timestamp < time_convert(post[0])):
            LOGGER.debug(str(last_timestamp) + ', ' + post[0])
            time_filter_posts.append(post)
            # print value['timeStamp']
    LOGGER.debug('filter_by_time() %s', posts.keys())
    LOGGER.info('EXIT')
    return time_filter_posts
Exemplo n.º 10
0
def test_get_date_taken():
    text = Text(helper.get_file('valid.txt'))
    text.get_metadata()

    date_taken = text.get_date_taken()

    assert date_taken == helper.time_convert((2016, 4, 7, 11, 15, 26, 3, 98, 0)), date_taken
Exemplo n.º 11
0
def _test_photo_type_set(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(date), '{} date {}'.format(type, metadata['date_taken'])
    assert helper.isclose(metadata['latitude'], 11.1111111111), '{} lat {}'.format(type, metadata['latitude'])
    assert helper.isclose(metadata['longitude'], 99.9999999999), '{} lon {}'.format(type, metadata['latitude'])
Exemplo n.º 12
0
def _test_photo_type_set(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(
        date), '{} date {}'.format(type, metadata['date_taken'])
    assert helper.isclose(metadata['latitude'],
                          11.1111111111), '{} lat {}'.format(
                              type, metadata['latitude'])
    assert helper.isclose(metadata['longitude'],
                          99.9999999999), '{} lon {}'.format(
                              type, metadata['latitude'])
Exemplo n.º 13
0
def test_update_time_on_video():
    temporary_folder, folder = helper.create_working_folder()
    temporary_folder_destination, folder_destination = helper.create_working_folder(
    )

    origin = '%s/video.mov' % folder
    shutil.copyfile(helper.get_file('video.mov'), origin)

    video = Video(origin)
    metadata = video.get_metadata()

    helper.reset_dbs()
    status = elodie.update_time(video, origin, '2000-01-01 12:00:00')
    helper.restore_dbs()

    video_processed = Video(origin)
    metadata_processed = video_processed.get_metadata()

    shutil.rmtree(folder)
    shutil.rmtree(folder_destination)

    assert status == True, status
    assert metadata['date_taken'] != metadata_processed['date_taken']
    assert metadata_processed['date_taken'] == helper.time_convert(
        (2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_taken']
Exemplo n.º 14
0
def test_update_time_on_video():
    temporary_folder, folder = helper.create_working_folder()
    temporary_folder_destination, folder_destination = helper.create_working_folder()

    origin = "%s/video.mov" % folder
    shutil.copyfile(helper.get_file("video.mov"), origin)

    video = Video(origin)
    metadata = video.get_metadata()

    reset_hash_db()
    status = elodie.update_time(video, origin, "2000-01-01 12:00:00")
    restore_hash_db()

    video_processed = Video(origin)
    metadata_processed = video_processed.get_metadata()

    shutil.rmtree(folder)
    shutil.rmtree(folder_destination)

    assert status == True, status
    assert metadata["date_taken"] != metadata_processed["date_taken"]
    assert metadata_processed["date_taken"] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed[
        "date_taken"
    ]
Exemplo n.º 15
0
def test_set_metadata_on_arw():
    temporary_folder, folder = helper.create_working_folder()

    photo_file = helper.get_file('photo.arw')
    origin = '%s/photo.arw' % folder

    if not photo_file:
        photo_file = helper.download_file('photo.arw', folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('arw file not downlaoded')

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert((2007, 4, 8, 17, 41, 18, 6, 98, 0)), metadata['date_taken']
    assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
    assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
Exemplo n.º 16
0
def test_set_metadata_on_rw2():
    raise SkipTest('gh-94 Writing to RW2 images is not supported')
    temporary_folder, folder = helper.create_working_folder()

    photo_file = helper.get_file('photo.rw2')
    origin = '%s/photo.rw2' % folder

    if not photo_file:
        photo_file = helper.download_file('photo.rw2', folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('rw2 file not downlaoded')

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert((2014, 11, 19, 23, 7, 44, 2, 323, 0)), metadata['date_taken']
    assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
    assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
Exemplo n.º 17
0
def test_set_date_taken():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    status = photo.set_date_taken(datetime(2013, 9, 30, 7, 6, 5))

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    date_taken = metadata['date_taken']

    shutil.rmtree(folder)

    #assert date_taken == (2013, 9, 30, 7, 6, 5, 0, 273, 0), metadata['date_taken']
    assert date_taken == helper.time_convert((2013, 9, 30, 7, 6, 5, 0, 273, 0)), metadata['date_taken']
Exemplo n.º 18
0
def test_set_date_taken_with_missing_datetimeoriginal():
    # When datetimeoriginal (or other key) is missing we have to add it gh-74
    # https://github.com/jmathai/elodie/issues/74
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('no-exif.jpg'), origin)

    photo = Photo(origin)
    status = photo.set_date_taken(datetime(2013, 9, 30, 7, 6, 5))

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    date_taken = metadata['date_taken']

    shutil.rmtree(folder)

    #assert date_taken == (2013, 9, 30, 7, 6, 5, 0, 273, 0), metadata['date_taken']
    assert date_taken == helper.time_convert((2013, 9, 30, 7, 6, 5, 0, 273, 0)), metadata['date_taken']
Exemplo n.º 19
0
def test_get_metadata_from_arw():
    temporary_folder, folder = helper.create_working_folder()

    photo_file = helper.get_file('photo.arw')
    origin = '%s/photo.arw' % folder

    if not photo_file:
        photo_file = helper.download_file('photo.arw', folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('arw file not downlaoded')

        # downloading for each test is costly so we save it in the working directory
        file_path_save_as = helper.get_file_path('photo.arw')
        if os.path.isfile(photo_file):
            shutil.copyfile(photo_file, file_path_save_as)

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert((2007, 4, 8, 17, 41, 18, 6, 98, 0)), metadata['date_taken']
Exemplo n.º 20
0
def test_get_date_taken():
    photo = Photo(helper.get_file('plain.jpg'))
    date_taken = photo.get_date_taken()

#    assert date_taken == (2015, 12, 5, 0, 59, 26, 5, 339, 0), date_taken
    assert date_taken == helper.time_convert((2015, 12, 5, 0, 59, 26, 5, 339, 0)), date_taken