


'''simple docstring'''


import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import DPTImageProcessor






class 		lowerCAmelCase__	(	unittest.TestCase		):




			def __init__(						self     :   Optional[int]		,     lowerCamelCase__     :   Optional[int]		,     lowerCamelCase__     :   Any=7		,     lowerCamelCase__     :   Dict=3		,     lowerCamelCase__     :   Optional[Any]=18		,     lowerCamelCase__     :   Union[str, Any]=30		,     lowerCamelCase__     :   str=4_00		,     lowerCamelCase__     :   Optional[Any]=True		,     lowerCamelCase__     :   str=None		,     lowerCamelCase__     :   Dict=True		,     lowerCamelCase__     :   Tuple=[0.5, 0.5, 0.5]		,     lowerCamelCase__     :   Union[str, Any]=[0.5, 0.5, 0.5]		,     )      ->List[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				int	    =					size if size is not None else {"height": 18, "width": 18}
					_UpperCAmelCase						:				int	    =					parent
					_UpperCAmelCase						:				Union[str, Any]	    =					batch_size
					_UpperCAmelCase						:				Optional[int]	    =					num_channels
					_UpperCAmelCase						:				Optional[Any]	    =					image_size
					_UpperCAmelCase						:				int	    =					min_resolution
					_UpperCAmelCase						:				Union[str, Any]	    =					max_resolution
					_UpperCAmelCase						:				Union[str, Any]	    =					do_resize
					_UpperCAmelCase						:				str	    =					size
					_UpperCAmelCase						:				List[str]	    =					do_normalize
					_UpperCAmelCase						:				str	    =					image_mean
					_UpperCAmelCase						:				List[str]	    =					image_std






			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->Tuple:



					'''simple docstring'''







					return {
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_normalize": self.do_normalize,
					    "do_resize": self.do_resize,
					    "size": self.size,
					}






@require_torch
@require_vision
class 		lowerCAmelCase__	(	UpperCAmelCase__			,				unittest.TestCase		):
			lowerCAmelCase       :		int				      =   DPTImageProcessor if is_vision_available() else None




			def 							lowerCAmelCase__			(						self     :   List[Any]       )      ->Any:



					'''simple docstring'''







					_UpperCAmelCase						:				Union[str, Any]	    =					DPTImageProcessingTester(self       )




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->List[Any]:



					'''simple docstring'''







					return self.image_processor_tester.prepare_image_processor_dict()




			def 							lowerCAmelCase__			(						self     :   int       )      ->str:



					'''simple docstring'''







					_UpperCAmelCase						:				str	    =					self.image_processing_class(**self.image_processor_dict       )
					self.assertTrue(hasattr(lowerCamelCase__		,     "image_mean"       )       )
					self.assertTrue(hasattr(lowerCamelCase__		,     "image_std"       )       )
					self.assertTrue(hasattr(lowerCamelCase__		,     "do_normalize"       )       )
					self.assertTrue(hasattr(lowerCamelCase__		,     "do_resize"       )       )
					self.assertTrue(hasattr(lowerCamelCase__		,     "size"       )       )




			def 							lowerCAmelCase__			(						self     :   int       )      ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[int]	    =					self.image_processing_class.from_dict(self.image_processor_dict       )
					self.assertEqual(image_processor.size		,     {"height": 18, "width": 18}       )

					_UpperCAmelCase						:				str	    =					self.image_processing_class.from_dict(self.image_processor_dict		,     size=42       )
					self.assertEqual(image_processor.size		,     {"height": 42, "width": 42}       )




			def 							lowerCAmelCase__			(						self     :   Union[str, Any]       )      ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[Any]	    =					self.image_processing_class(**self.image_processor_dict       )
					# create random PIL images
					_UpperCAmelCase						:				Optional[Any]	    =					prepare_image_inputs(self.image_processor_tester		,     equal_resolution=lowerCamelCase__       )
					for image in image_inputs:
							self.assertIsInstance(lowerCamelCase__		,     Image.Image       )

					# Test not batched input
					_UpperCAmelCase						:				int	    =					image_processing(image_inputs[0]		,     return_tensors="pt"       ).pixel_values
					self.assertEqual(
					    encoded_images.shape		,     (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size["height"],
					        self.image_processor_tester.size["width"],
					    )		,     )

					# Test batched
					_UpperCAmelCase						:				List[str]	    =					image_processing(lowerCamelCase__		,     return_tensors="pt"       ).pixel_values
					self.assertEqual(
					    encoded_images.shape		,     (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size["height"],
					        self.image_processor_tester.size["width"],
					    )		,     )




			def 							lowerCAmelCase__			(						self     :   List[str]       )      ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				List[str]	    =					self.image_processing_class(**self.image_processor_dict       )
					# create random numpy tensors
					_UpperCAmelCase						:				Any	    =					prepare_image_inputs(self.image_processor_tester		,     equal_resolution=lowerCamelCase__		,     numpify=lowerCamelCase__       )
					for image in image_inputs:
							self.assertIsInstance(lowerCamelCase__		,     np.ndarray       )

					# Test not batched input
					_UpperCAmelCase						:				Tuple	    =					image_processing(image_inputs[0]		,     return_tensors="pt"       ).pixel_values
					self.assertEqual(
					    encoded_images.shape		,     (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size["height"],
					        self.image_processor_tester.size["width"],
					    )		,     )

					# Test batched
					_UpperCAmelCase						:				str	    =					image_processing(lowerCamelCase__		,     return_tensors="pt"       ).pixel_values
					self.assertEqual(
					    encoded_images.shape		,     (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size["height"],
					        self.image_processor_tester.size["width"],
					    )		,     )






			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				str	    =					self.image_processing_class(**self.image_processor_dict       )
					# create random PyTorch tensors
					_UpperCAmelCase						:				List[Any]	    =					prepare_image_inputs(self.image_processor_tester		,     equal_resolution=lowerCamelCase__		,     torchify=lowerCamelCase__       )
					for image in image_inputs:
							self.assertIsInstance(lowerCamelCase__		,     torch.Tensor       )

					# Test not batched input
					_UpperCAmelCase						:				Dict	    =					image_processing(image_inputs[0]		,     return_tensors="pt"       ).pixel_values
					self.assertEqual(
					    encoded_images.shape		,     (
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size["height"],
					        self.image_processor_tester.size["width"],
					    )		,     )

					# Test batched
					_UpperCAmelCase						:				str	    =					image_processing(lowerCamelCase__		,     return_tensors="pt"       ).pixel_values
					self.assertEqual(
					    encoded_images.shape		,     (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.size["height"],
					        self.image_processor_tester.size["width"],
					    )		,     )







'''simple docstring'''


from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

lowerCamelCase__					=   {'UserAgent': UserAgent().random}






def        __lowerCAmelCase       (__lowerCAmelCase      ):
		_UpperCAmelCase						:				List[str]	    =					script.contents[0]
		_UpperCAmelCase						:				Any	    =					json.loads(data[data.find("{\"config\""      ) : -1]      )
		return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]






class 		lowerCAmelCase__	:




			def __init__(						self     :   str		,     lowerCamelCase__     :   List[Any]       )      ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase						:				List[Any]	    =					F"""https://www.instagram.com/{username}/"""
					_UpperCAmelCase						:				Dict	    =					self.get_json()




			def 							lowerCAmelCase__			(						self     :   Any       )      ->dict:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[int]	    =					requests.get(self.url		,     headers=lowerCamelCase__       ).text
					_UpperCAmelCase						:				Any	    =					BeautifulSoup(lowerCamelCase__		,     "html.parser"       ).find_all("script"       )
					try:
							return extract_user_profile(scripts[4]       )
					except (json.decoder.JSONDecodeError, KeyError):
							return extract_user_profile(scripts[3]       )




			def __repr__(						self     :   Optional[Any]       )      ->str:



					'''simple docstring'''







					return F"""{self.__class__.__name__}('{self.username}')"""




			def __str__(						self     :   List[Any]       )      ->str:



					'''simple docstring'''







					return F"""{self.fullname} ({self.username}) is {self.biography}"""




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->str:



					'''simple docstring'''







					return self.user_data["username"]




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->str:



					'''simple docstring'''







					return self.user_data["full_name"]




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->str:



					'''simple docstring'''







					return self.user_data["biography"]




			@property
			def 							lowerCAmelCase__			(						self     :   int       )      ->str:



					'''simple docstring'''







					return self.user_data["business_email"]




			@property
			def 							lowerCAmelCase__			(						self     :   str       )      ->str:



					'''simple docstring'''







					return self.user_data["external_url"]




			@property
			def 							lowerCAmelCase__			(						self     :   Tuple       )      ->int:



					'''simple docstring'''







					return self.user_data["edge_followed_by"]["count"]




			@property
			def 							lowerCAmelCase__			(						self     :   str       )      ->int:



					'''simple docstring'''







					return self.user_data["edge_follow"]["count"]




			@property
			def 							lowerCAmelCase__			(						self     :   Any       )      ->int:



					'''simple docstring'''







					return self.user_data["edge_owner_to_timeline_media"]["count"]




			@property
			def 							lowerCAmelCase__			(						self     :   List[Any]       )      ->str:



					'''simple docstring'''







					return self.user_data["profile_pic_url_hd"]




			@property
			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->bool:



					'''simple docstring'''







					return self.user_data["is_verified"]






			@property
			def 							lowerCAmelCase__			(						self     :   int       )      ->bool:



					'''simple docstring'''







					return self.user_data["is_private"]






def        __lowerCAmelCase       (__lowerCAmelCase = "github"      ):
		import os

		if os.environ.get("CI"      ):
				return  # test failing on GitHub Actions
		_UpperCAmelCase						:				Dict	    =					InstagramUser(__lowerCAmelCase      )
		assert instagram_user.user_data
		assert isinstance(instagram_user.user_data					,       __lowerCAmelCase      )
		assert instagram_user.username == username
		if username != "github":
				return
		assert instagram_user.fullname == "GitHub"
		assert instagram_user.biography == "Built for developers."
		assert instagram_user.number_of_posts > 150
		assert instagram_user.number_of_followers > 120_000
		assert instagram_user.number_of_followings > 15
		assert instagram_user.email == "support@github.com"
		assert instagram_user.website == "https://github.com/readme"
		assert instagram_user.profile_picture_url.startswith("https://instagram."      )
		assert instagram_user.is_verified is True
		assert instagram_user.is_private is False


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						lowerCamelCase__					=   InstagramUser('github')
						print(instagram_user)
						print(F'''{instagram_user.number_of_posts = }''')
						print(F'''{instagram_user.number_of_followers = }''')
						print(F'''{instagram_user.number_of_followings = }''')
						print(F'''{instagram_user.email = }''')
						print(F'''{instagram_user.website = }''')
						print(F'''{instagram_user.profile_picture_url = }''')
						print(F'''{instagram_user.is_verified = }''')
						print(F'''{instagram_user.is_private = }''')



