11import requests
22import time
3+ from typing import Dict , List , Any , Optional
34
4- DSL_API_BASE_URL = "https://test.deepskylog.org/api/" # Change this as needed
5+ DSL_API_BASE_URL : str = "https://test.deepskylog.org/api/" # Change this as needed
56
67# Simple in-memory cache: {url: (timestamp, data)}
7- _DSL_API_CACHE = {}
8- _DSL_API_CACHE_TTL = 300 # seconds (5 minutes)
8+ _DSL_API_CACHE : Dict [ str , tuple [ float , Any ]] = {}
9+ _DSL_API_CACHE_TTL : int = 300 # seconds (5 minutes)
910
10- def dsl_instruments (username : str ) -> dict :
11+ def dsl_instruments (username : str ) -> Dict [ str , Any ] :
1112 """
1213 Get all defined instruments of a DeepskyLog user.
1314
@@ -21,7 +22,7 @@ def dsl_instruments(username: str) -> dict:
2122 """
2223 return _dsl_api_call ("instrument" , username )
2324
24- def dsl_eyepieces (username : str ) -> dict :
25+ def dsl_eyepieces (username : str ) -> Dict [ str , Any ] :
2526 """
2627 Get all defined eyepieces of a DeepskyLog user.
2728
@@ -35,7 +36,7 @@ def dsl_eyepieces(username: str) -> dict:
3536 """
3637 return _dsl_api_call ("eyepieces" , username )
3738
38- def dsl_lenses (username : str ) -> dict :
39+ def dsl_lenses (username : str ) -> Dict [ str , Any ] :
3940 """
4041 Get all defined lenses of a DeepskyLog user.
4142
@@ -49,7 +50,7 @@ def dsl_lenses(username: str) -> dict:
4950 """
5051 return _dsl_api_call ("lenses" , username )
5152
52- def dsl_filters (username : str ) -> dict :
53+ def dsl_filters (username : str ) -> Dict [ str , Any ] :
5354 """
5455 Get all defined filters of a DeepskyLog user.
5556
@@ -64,7 +65,7 @@ def dsl_filters(username: str) -> dict:
6465 return _dsl_api_call ("filters" , username )
6566
6667
67- def calculate_magnifications (instrument : dict , eyepieces : dict ) -> list :
68+ def calculate_magnifications (instrument : Dict [ str , Any ], eyepieces : List [ Dict [ str , Any ]] ) -> List [ float ] :
6869 """
6970 Calculate possible magnifications for a given telescope and eyepieces.
7071
@@ -87,7 +88,7 @@ def calculate_magnifications(instrument: dict, eyepieces: dict) -> list:
8788 Returns:
8889 list: A list of possible magnifications for the telescope.
8990 """
90- magnifications = []
91+ magnifications : List [ float ] = []
9192 # Check if the instrument has a fixed magnification
9293 if instrument ["fixedMagnification" ]:
9394 magnifications .append (instrument ["fixedMagnification" ])
@@ -105,7 +106,7 @@ def convert_instrument_type_to_int(instrument_type: str) -> int:
105106 :param instrument_type: The instrument type as a string.
106107 :return: The instrument type as an integer.
107108 """
108- instrument_types = {
109+ instrument_types : Dict [ str , int ] = {
109110 "Naked Eye" : 0 ,
110111 "Binoculars" : 1 ,
111112 "Refractor" : 2 ,
@@ -126,7 +127,7 @@ def convert_instrument_type_to_string(instrument_type: int) -> str:
126127 :param instrument_type: The instrument type as an integer.
127128 :return: The instrument type as a string.
128129 """
129- instrument_types = {
130+ instrument_types : Dict [ str , int ] = {
130131 0 : "Naked Eye" ,
131132 1 : "Binoculars" ,
132133 2 : "Refractor" ,
@@ -141,7 +142,7 @@ def convert_instrument_type_to_string(instrument_type: int) -> str:
141142
142143 return instrument_types [instrument_type ]
143144
144- def _dsl_api_call (api_call : str , username : str ) -> dict :
145+ def _dsl_api_call (api_call : str , username : str ) -> Dict [ str , Any ] :
145146 """
146147 Make an API call to the DeepskyLog system.
147148
@@ -155,8 +156,8 @@ def _dsl_api_call(api_call: str, username: str) -> dict:
155156 Returns:
156157 dict: The response from the API call, parsed as a JSON dictionary.
157158 """
158- api_url = f"{ DSL_API_BASE_URL } { api_call } /{ username } "
159- now = time .time ()
159+ api_url : str = f"{ DSL_API_BASE_URL } { api_call } /{ username } "
160+ now : float = time .time ()
160161
161162 # Check cache
162163 cache_entry = _DSL_API_CACHE .get (api_url )
0 commit comments