2020"""
2121import requests
2222
23- from typing import Union
23+ from typing import Union , Tuple
2424
2525__all__ = ("Map" ,)
2626
@@ -29,7 +29,7 @@ class Map(object):
2929
3030 def __init__ (
3131 self , api_key : str ,
32- coordinates : Union [tuple [float , float ], str ] = (0.0 , 0.0 ),
32+ coordinates : Union [Tuple [float , ... ], str ] = (0.0 , 0.0 ),
3333 zoom : float = 10 , type_of_point : str = "flag" ,
3434 points_city : str = "Moscow"
3535
@@ -69,12 +69,12 @@ def __init__(
6969
7070 self .main_url = self .generate_map_url ()
7171
72- def convert_address_to_coordinates (self , address : str ) -> tuple [float , float ]:
72+ def convert_address_to_coordinates (self , address : str ) -> Tuple [float , ... ]:
7373 request = requests .get (self .generate_api_url (address )).json ()
7474 return request ["data" ][0 ]["latitude" ], request ["data" ][0 ]["longitude" ]
7575
7676 @staticmethod
77- def convert_coordinates_to_text_view (coordinates : tuple [float , float ]) -> str :
77+ def convert_coordinates_to_text_view (coordinates : Tuple [float , ... ]) -> str :
7878 return str (coordinates [1 ]) + "," + str (coordinates [0 ])
7979
8080 def generate_map_url (self ) -> str :
@@ -92,7 +92,7 @@ def generate_api_url(self, address: str) -> str:
9292 query = f"{ self .city } { address } "
9393 )
9494
95- def add_point (self , coordinates : Union [str , tuple [float , float ]]) -> None :
95+ def add_point (self , coordinates : Union [str , Tuple [float , ... ]]) -> None :
9696 if isinstance (coordinates , str ):
9797 self .points .append (self .convert_address_to_coordinates (coordinates ))
9898 else :
@@ -107,9 +107,9 @@ def commit_points(self, map_url: str) -> str:
107107 self .points = []
108108 return map_url
109109
110- def __call__ (self ) -> None :
110+ def __call__ (self , path : str = "" ) -> None :
111111 response = requests .get (self .main_url )
112112 if not response :
113113 raise NameError (f"HTTP Error: { response .status_code } ({ response .reason } )" )
114- with open (" map.png" , "wb" ) as file :
114+ with open (f" { path + '/' if path != '' else '' } map.png" , "wb" ) as file :
115115 file .write (response .content )
0 commit comments