23 lines
393 B
Python
23 lines
393 B
Python
from dataclasses import dataclass
|
|||
|
|
from typing import cast
|
||
|
|
from cnet import json, text
|
||
|
|
|
||
|
|
|
||
|
|
def get_ip() -> str:
|
||
|
|
return text("https://api.ipify.org/")
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class Geo:
|
||
|
|
lat: str
|
||
|
|
lot: str
|
||
|
|
|
||
|
|
|
||
|
|
def get_geo() -> Geo:
|
||
|
|
geo = cast(dict[str, str], json("https://free.freeipapi.com/api/v1/json/"))
|
||
|
|
|
||
|
|
lat = geo["latitude"]
|
||
|
|
lot = geo["longitude"]
|
||
|
|
|
||
|
|
return Geo(lat=lat, lot=lot)
|