pup-py commited on
Commit
364dead
·
1 Parent(s): 0b8e234

remove unneeded data; tac a.json (to show newest first)

Browse files
Files changed (2) hide show
  1. fetch.py +7 -5
  2. pyproject.toml +1 -1
fetch.py CHANGED
@@ -36,13 +36,15 @@ app = FastAPI(lifespan=lifespan)
36
  async def log_request(request: Request, call_next: Any):
37
  ts = datetime.now().strftime("%y%m%d%H%M%S%f")
38
  data = {
39
- "day": int(ts[:6]),
40
  "dt": int(ts[:-3]),
41
  "url": request.url,
42
  "query_params": request.query_params,
43
- "client": request.client.host,
 
 
44
  "method": request.method,
45
- "headers": dict(request.headers),
46
  }
47
  output = json.dumps(
48
  obj=data,
@@ -107,9 +109,9 @@ def read_root(request: Request):
107
  @app.get("/a", response_class=PrettyJSONResponse)
108
  def get_analytics(n: int = 5):
109
  if n == 0:
110
- cmd = f"cat {LOGFILE.as_posix()}"
111
  else:
112
- cmd = f"tail -{n} {LOGFILE.as_posix()}"
113
  json_lines = subprocess.run(cmd.split(), capture_output=True).stdout
114
  content = json.loads(f"[{json_lines.replace(b"\n", b",").decode()}]")
115
  return content
 
36
  async def log_request(request: Request, call_next: Any):
37
  ts = datetime.now().strftime("%y%m%d%H%M%S%f")
38
  data = {
39
+ # "day": int(ts[:6]),
40
  "dt": int(ts[:-3]),
41
  "url": request.url,
42
  "query_params": request.query_params,
43
+ "user-agent": request.headers.get("user-agent"),
44
+ "client": request.headers.get("x-forwarded-for"),
45
+ "private_ip": request.client.host,
46
  "method": request.method,
47
+ "headers": str(request.headers),
48
  }
49
  output = json.dumps(
50
  obj=data,
 
109
  @app.get("/a", response_class=PrettyJSONResponse)
110
  def get_analytics(n: int = 5):
111
  if n == 0:
112
+ cmd = f"tac {LOGFILE.as_posix()}"
113
  else:
114
+ cmd = f"tail -{n} {LOGFILE.as_posix()} | tac"
115
  json_lines = subprocess.run(cmd.split(), capture_output=True).stdout
116
  content = json.loads(f"[{json_lines.replace(b"\n", b",").decode()}]")
117
  return content
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
  [project]
2
  name = "fetch"
3
- version = "0.3.5"
4
  description = "Puppy Installer"
5
  authors = [
6
  { name = "Alex Kislukhin" }
 
1
  [project]
2
  name = "fetch"
3
+ version = "0.4.0"
4
  description = "Puppy Installer"
5
  authors = [
6
  { name = "Alex Kislukhin" }