Last active
May 23, 2025 07:59
-
-
Save 5AMsan/3d24561dbe70239070b3b189fead03d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, browser_cookie3, re, json, datetime, os | |
from dotenv import load_dotenv | |
from urllib.request import urlopen | |
# Load environment variables from the .env file | |
load_dotenv() | |
''' Get cookie from Firefox ''' | |
cj = browser_cookie3.firefox(domain_name='.google.com') | |
headers = { | |
"Host": "kidsmanagement-pa.clients6.google.com", | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0", | |
"Accept": "*/*", | |
"Accept-Language": "en-US", | |
"Accept-Encoding": "gzip, deflate, br, zstd", | |
"Referer": "https://familylink.google.com/", | |
"Origin": "https://familylink.google.com", | |
"Connection": "keep-alive", | |
"Sec-Fetch-Dest": "empty", | |
"Sec-Fetch-Mode": "no-cors", | |
"Sec-Fetch-Site": "same-site", | |
"TE": "trailers", | |
"Priority": "u=4", | |
"Pragma": "no-cache", | |
} | |
''' Get it from dev console on WebApp Page, starts with https://kidsmanagement-pa.clients6.google.com/kidsmanagement/v1/people/.... ''' | |
''' Create a .env file containing SERVICE_URL=https://kidsmanagement-pa.clients6.google.com/kidsmanagement/v1/people/.... ''' | |
url = os.getenv('SERVICE_URL') | |
r = requests.get(url, headers=headers, cookies=cj) | |
class App(object): | |
def __init__(self, name, usedTime, lastUsed): | |
self.name = name | |
self.usedTime = usedTime | |
self.lastUsed = lastUsed | |
def __eq__(self, other): | |
return self.usedTime == other.usedTime and self.name == other.name | |
def __lt__(self, other): | |
return self.usedTime < other.usedTime | |
if r.status_code == 200: | |
''' Read response body and parse ''' | |
datas = json.loads(r.content) | |
today = datetime.datetime.today().date() | |
''' Get app infos ''' | |
appsInfos = datas[1] | |
appsConf = {} | |
for app in appsInfos: | |
appsConf[app[0]] = app[1] | |
''' Get time by apps ''' | |
appsDetails = [] | |
for appData in datas[6]: | |
name = appsConf[appData[1][0]] | |
usedTime = int(appData[0][0]) | |
# remainingTime = appConf[0][1] / 60 | |
date = datetime.date( *appData[4] ) | |
if(today == date): | |
appsDetails.append(App(name, usedTime, date)) | |
print([ [c.name, int(c.usedTime/60)] for c in sorted(appsDetails, reverse=True)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment