summaryrefslogtreecommitdiff
path: root/check-ratio.py
blob: 6c852834cb55a75d40acbc26f89e6b487e8f2b65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
from database import Database
from argparse import ArgumentParser


if __name__ == '__main__':
    db = Database()
    parser = ArgumentParser()
    parser.add_argument('--from', type=str, required=True, dest='date_from',
                        help='date formatted as yyyy-mm-dd')
    parser.add_argument('--to', type=str, required=True, dest='date_to',
                        help='date formatted as yyyy-mm-dd')
    args = parser.parse_args()

    docs = db.get_documents((args.date_from, args.date_to))
    for doc in docs:
        pages = db.get_doc_pages(doc['collection_id'], doc['doc_id'])
        for page, width, height, dpi in pages:
            if width == 0 or height == 0:
                print(f'ERROR: {doc["collection_id"]}/{doc["page_id"]}/{page}: width or height is zero')
                continue
            ratio = width/height
            if ratio >= 0.8:
                print(f'{doc["collection_id"]}/{doc["doc_id"]}/{page}: {ratio}')