Guest User

Untitled

a guest
Jun 26th, 2022
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.64 KB | None | 0 0
  1. from typing import Any, Dict, List, Optional, Union
  2.  
  3. class PexelsType:
  4.     """Base class for all pexels objects"""
  5.  
  6.     def __str__(self) -> str:
  7.         return f'<{self.__class__.__name__}: {self.__dict__}'
  8.    
  9.     def __repr__(self) -> str:
  10.         return self.__str__()
  11.  
  12. class Src(PexelsType):
  13.  
  14.     original: str
  15.     "The image without any size changes. It will be the same as the width and height attributes."
  16.     large: str
  17.     "The image resized to W 940px X H 650px DPR 1."
  18.     large2x: str
  19.     "The image resized W 940px X H 650px DPR 2."
  20.     medium: str
  21.     "The image resized W 940px X H 650px DPR 2."
  22.     small: str
  23.     "The image scaled proportionally so that it's new height is 130px."
  24.     portrait: str
  25.     "The image cropped to W 800px X H 1200px."
  26.     landscape: str
  27.     "The image cropped to W 1200px X H 627px."
  28.     tiny: str
  29.     "The image cropped to W 280px X H 200px."
  30.  
  31.     def __init__(
  32.         self,
  33.         original: str,
  34.         large: str,
  35.         large2x: str,
  36.         medium: str,
  37.         small: str,
  38.         portrait: str,
  39.         landscape: str,
  40.         tiny: str,
  41.         **kwargs
  42.     ) -> None:
  43.  
  44.         self.original = original
  45.         self.large = large
  46.         self.large2x = large2x
  47.         self.medium = medium
  48.         self.small = small
  49.         self.portrait = portrait
  50.         self.landscape = landscape
  51.         self.tiny = tiny
  52.  
  53. class Photo(PexelsType):
  54.  
  55.     id: int
  56.     "The id of the photo."
  57.     width: int
  58.     "The real width of the photo in pixels."
  59.     height: int
  60.     "The real height of the photo in pixels."
  61.     url: str
  62.     "The Pexels URL where the photo is located."
  63.     photographer: str
  64.     "The name of the photographer who took the photo."
  65.     photographer_url: str
  66.     "The URL of the photographer's Pexels profile."
  67.     photographer_id: str
  68.     "The id of the photographer."
  69.     avg_color: str
  70.     "The average color of the photo. Useful for a placeholder while the image loads"
  71.     src: Src
  72.     "An assortment of different image sizes that can be used to display this Photo."
  73.     alt: str
  74.     "Text description of the photo for use in the alt attribute."
  75.  
  76.     def __init__(
  77.         self,
  78.         id: int,
  79.         width: int,
  80.         height: int,
  81.         url: str,
  82.         photographer: str,
  83.         photographer_url: str,
  84.         photographer_id: int,
  85.         avg_color: str,
  86.         src: Any,
  87.         alt: str,
  88.         **kwargs
  89.     ) -> None:
  90.  
  91.         self.id = id
  92.         self.width = width
  93.         self.height = height
  94.         self.url = url
  95.         self.photographer = photographer
  96.         self.photographer_url = photographer_url
  97.         self.photographer_id = photographer_id
  98.         self.avg_color = avg_color
  99.         self.src = Src(**src)
  100.         self.alt = alt
  101.  
  102. class SearchResponse(PexelsType):
  103.  
  104.     photos = List[Photo]
  105.     "A list of `Photo` object"
  106.     page = int
  107.     "The current page number"
  108.     per_page = int
  109.     "The number of results returned with each page"
  110.     total_results = int
  111.     "The total number of results for the request"
  112.     prev_page = str
  113.     "URL for the previous page of results, if applicable"
  114.     next_page = str
  115.     "URL for the next page of results, if applicable"
  116.  
  117.     def __init__(
  118.         self,
  119.         photos: List[Photo],
  120.         page: int,
  121.         per_page: int,
  122.         total_results: int,
  123.         prev_page: str = "",
  124.         next_page: str = "",
  125.         **kwargs
  126.         ):
  127.         self.photos = photos
  128.         self.page = page
  129.         self.per_page = per_page
  130.         self.total_results = total_results
  131.         self.prev_page = prev_page
  132.         self.next_page = next_page
Advertisement
Add Comment
Please, Sign In to add comment