feat: geo/ip client
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user