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