85def parse_tineye_match(match_json):
86 """Takes parsed JSON from the API server and turns it into a :py:obj:`dict`
87 object.
88
89 Attributes `(class Match) <https://github.com/TinEye/pytineye/blob/main/pytineye/api.py>`__
90
91 - `image_url`, link to the result image.
92 - `domain`, domain this result was found on.
93 - `score`, a number (0 to 100) that indicates how closely the images match.
94 - `width`, image width in pixels.
95 - `height`, image height in pixels.
96 - `size`, image area in pixels.
97 - `format`, image format.
98 - `filesize`, image size in bytes.
99 - `overlay`, overlay URL.
100 - `tags`, whether this match belongs to a collection or stock domain.
101
102 - `backlinks`, a list of Backlink objects pointing to the original websites
103 and image URLs. List items are instances of :py:obj:`dict`, (`Backlink
104 <https://github.com/TinEye/pytineye/blob/main/pytineye/api.py>`__):
105
106 - `url`, the image URL to the image.
107 - `backlink`, the original website URL.
108 - `crawl_date`, the date the image was crawled.
109
110 """
111
112
113
114
115
116 backlinks = []
117 if "backlinks" in match_json:
118
119 for backlink_json in match_json["backlinks"]:
120 if not isinstance(backlink_json, dict):
121 continue
122
123 crawl_date = backlink_json.get("crawl_date")
124 if crawl_date:
125 crawl_date = datetime.strptime(crawl_date, '%Y-%m-%d')
126 else:
127 crawl_date = datetime.min
128
129 backlinks.append(
130 {
131 'url': backlink_json.get("url"),
132 'backlink': backlink_json.get("backlink"),
133 'crawl_date': crawl_date,
134 'image_name': backlink_json.get("image_name"),
135 }
136 )
137
138 return {
139 'image_url': match_json.get("image_url"),
140 'domain': match_json.get("domain"),
141 'score': match_json.get("score"),
142 'width': match_json.get("width"),
143 'height': match_json.get("height"),
144 'size': match_json.get("size"),
145 'image_format': match_json.get("format"),
146 'filesize': match_json.get("filesize"),
147 'overlay': match_json.get("overlay"),
148 'tags': match_json.get("tags"),
149 'backlinks': backlinks,
150 }
151
152