Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions ghunt/helpers/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from PIL import Image
import hashlib
from typing import *
from time import time
Expand All @@ -11,8 +10,6 @@
from packaging.version import parse as parse_version

import httpx
import imagehash
from io import BytesIO

from ghunt import globals as gb
from ghunt import version as current_version
Expand Down Expand Up @@ -57,23 +54,6 @@ def is_headers_syntax_good(headers: Dict[str, str]) -> bool:
except:
return False

async def get_url_image_flathash(as_client: httpx.AsyncClient, image_url: str) -> str:
req = await as_client.get(image_url)
img = Image.open(BytesIO(req.content))
flathash = imagehash.average_hash(img)
return str(flathash)

async def is_default_profile_pic(as_client: httpx.AsyncClient, image_url: str) -> Tuple[bool, str]:
"""
Returns a boolean which indicates if the image_url
is a default profile picture, and the flathash of
the image.
"""
flathash = await get_url_image_flathash(as_client, image_url)
if imagehash.hex_to_flathash(flathash, 8) - imagehash.hex_to_flathash("000018183c3c0000", 8) < 10 :
return True, str(flathash)
return False, str(flathash)

def get_class_name(obj) -> str:
return str(obj).strip("<>").split(" ")[0]

Expand Down
8 changes: 3 additions & 5 deletions ghunt/parsers/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from datetime import datetime

from ghunt.errors import *
from ghunt.helpers.utils import is_default_profile_pic, unicode_patch
from ghunt.helpers.utils import unicode_patch
from ghunt.objects.apis import Parser

import httpx
import imagehash


class PersonGplusExtendedData(Parser):
Expand Down Expand Up @@ -51,14 +50,13 @@ class PersonPhoto(Parser):
def __init__(self):
self.url: str = ""
self.isDefault: bool = False
self.flathash: str = None

async def _scrape(self, as_client: httpx.AsyncClient, photo_data: Dict[str, any], photo_type: str):
if photo_type == "profile_photo":
self.url = photo_data.get("url")
if (isDefault := photo_data.get("isDefault")):
self.isDefault = isDefault

self.isDefault, self.flathash = await is_default_profile_pic(as_client, self.url)

elif photo_type == "cover_photo":
self.url = '='.join(photo_data.get("imageUrl").split("=")[:-1])
if (isDefault := photo_data.get("isDefault")):
Expand Down