Skip to content

Commit ae4dccc

Browse files
committed
✨ Script to count log events in a time window.
1 parent 2dda6ea commit ae4dccc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

py/farm_count.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import datetime
2+
import sys
3+
from collections import Counter
4+
from typing import Optional
5+
6+
import parse_logs
7+
8+
9+
def farm_count(location: str, time_from: datetime.datetime, time_to: Optional[datetime.datetime] = None) -> dict[str, int]:
10+
totals = Counter()
11+
time_to = datetime.datetime.now()
12+
for row in parse_logs.parse_logs():
13+
if row.get("results", {}).get("location") != location:
14+
continue
15+
row_ts = datetime.datetime.fromtimestamp(row["ts"] / 1000)
16+
if time_from < row_ts < time_to:
17+
totals[row["type"]] += 1
18+
totals["stamina"] += row.get("results", {}).get("stamina", 0)
19+
return totals
20+
21+
22+
if __name__ == "__main__":
23+
counts = farm_count(sys.argv[1], datetime.datetime.now() - datetime.timedelta(hours=int(sys.argv[2])))
24+
print(counts)

0 commit comments

Comments
 (0)