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