HTTP · JSON · SSE
Presence 接口文档Presence API
Presence 是 now.ignat.ai 背后的服务:把 Mac、手机等设备上报的信号整理成“此刻大致在做什么”,并长期记录每天各类活动的时间。本页只介绍读取数据的接口。
Presence powers now.ignat.ai: it turns signals from a Mac, a phone and other devices into “what I'm roughly doing right now”, and keeps a long-term record of daily activity time. This page covers the read endpoints only.
https://api.ignat.ai/presence/api- 此刻状态
GET /now拿一次当前状态,或用GET /stream实时接收变化。 - Right now
GET /nowonce, or follow changes live withGET /stream. - 某一天
GET /today、GET /day?date=返回当天的时间线和各类别时长。 - One day
GET /todayandGET /day?date=return that day's timeline and per-category totals. - 一段时间
GET /history返回每天的时长汇总和游戏、听歌榜。 - A range
GET /historyreturns daily totals plus game and music charts.
通用约定Conventions
- 公开接口不需要任何凭证,只接受
GET(/media另接受HEAD)。 - 跨域:浏览器里只有
https://now.ignat.ai和https://ignat.ai能直接读取(响应带Access-Control-Allow-Origin);其他网站的前端请求会被浏览器拦下。服务器端脚本、curl不受影响。 - JSON 接口都带
Cache-Control: no-store,每次都是最新数据。 - 时间戳是 Unix 秒(可能带小数);日期写成
YYYY-MM-DD,按Asia/Shanghai时区、凌晨 4 点切分,凌晨 4 点前仍算前一天。 - 时长字段(
*_sec、seconds)是取整后的秒数。
- Public endpoints need no credentials and accept
GETonly (/mediaalso takesHEAD). - CORS: in browsers only
https://now.ignat.aiandhttps://ignat.aimay read responses (they getAccess-Control-Allow-Origin); front-end calls from other sites are blocked by the browser. Server-side scripts andcurlare unaffected. - JSON responses carry
Cache-Control: no-store, so they are always fresh. - Timestamps are Unix seconds (possibly fractional). Dates are
YYYY-MM-DDinAsia/Shanghai, split at 4 a.m.: anything before 4 a.m. belongs to the previous day. - Durations (
*_sec,seconds) are whole seconds.
快速上手Quick start
curl
# Current status curl https://api.ignat.ai/presence/api/now # Follow changes live (Ctrl+C to stop) curl -N https://api.ignat.ai/presence/api/stream # Last week, day by day curl 'https://api.ignat.ai/presence/api/history?from=2026-10-20&to=2026-10-26'
JavaScript
const API = 'https://api.ignat.ai/presence/api' const now = await fetch(`${API}/now`).then(r => r.json()) console.log(now.main.label) // "正在上《最优化方法》" const es = new EventSource(`${API}/stream`) es.addEventListener('now', e => render(JSON.parse(e.data)))
Python
import json, urllib.request API = "https://api.ignat.ai/presence/api" with urllib.request.urlopen(f"{API}/today") as r: day = json.load(r) for cat, sec in day["totals"]["activity"].items(): print(day["names"][cat], round(sec / 60), "min")
GET/now
此刻的状态:一个主状态 main 和若干伴随状态 side。服务器每 2 秒推进一次状态。
The current status: one main item plus any side items. The server advances its state every 2 seconds.
响应 200Response 200
{
"main": {
"type": "anchor", "category": "class", "label": "正在上《最优化方法》",
"since": 1793008800.0, "until": 1793017200.0,
"slacking": { "since": 1793014014.68 }
},
"side": [
{ "type": "activity", "category": "dev", "label": "搞开发", "tier": 1,
"since": 1793014014.68, "detail": "Presence", "today_sec": 20491 }
],
"updated_at": 1793014738.57
}状态项字段Item fields
除 type、category、label 外,其余字段只在有值时出现。
Apart from type, category and label, fields appear only when they have a value.
| 字段 | Field | 类型 | Type | 说明 | Description |
|---|---|---|---|---|---|
type | string | anchor 锚定状态、activity 活动、page 做正事时顺带看的网页、idle 没有任何状态 | anchor, activity, page (a web page viewed during serious work) or idle (nothing going on) | ||
category | string | 类别,见类别;idle 时为 away(设备在线但没在做事)或 offline | See Categories; for idle it is away (devices online but nothing active) or offline | ||
label | string | 直接展示的中文文案 | Ready-to-show Chinese text | ||
since / until | number | 开始时间;预计结束时间(上课时为下课时间) | Start time; expected end (end of class) | ||
tier | number | 活动等级,越小越优先 | Activity tier, lower wins | ||
detail | string | 补充说明,例如科研、开发时的项目名 | Extra detail, e.g. the project name during research or dev | ||
slacking | object | {since}:从什么时候开始摸鱼 | {since}: when slacking started | ||
today_sec | number | 该活动今天累计的秒数(等级 1 的活动,或合并进主状态的活动) | Seconds spent on this activity today (tier-1 activities, or one folded into the main status) | ||
activity / activity_name | string | 锚定状态合并进来的活动及其简称,例如在办公室时的“科研” | Activity folded into an anchor and its short name, e.g. research while at the office | ||
app / icon | string | 刷手机时的前台 App 名;now.ignat.ai 上的本地图标名(/icons/apps/<icon>.png) | Foreground phone app; local icon name on now.ignat.ai (/icons/apps/<icon>.png) | ||
card | object | 详情卡片,见下表 | Detail card, see below |
卡片 cardCards
| 出现于 | On | 字段 | Fields |
|---|---|---|---|
听歌 music | music | player player_name title artist album state position duration cover updated_at session_since | |
看视频 video | video | site site_name id page title owner url state position duration rate viewing cover updated_at session_since | |
游戏 game | game | name appid since cover | |
网页(kind: "web") | Web page (kind: "web") | title domain cover |
position/duration是秒,position是updated_at那一刻的进度;播放中(state: "playing")可按经过的时间自行推算当前进度。session_since是连续听歌 / 看视频的起点,换歌、换视频不重置。cover是完整的图片地址,指向/media/{sha256}。视频标题、封面等是服务器异步查到后补上的,刚开始时可能只有进度。
position/durationare seconds;positionis the progress atupdated_at. Whilestateis"playing", extrapolate from elapsed time.session_sincemarks the start of a continuous listening / watching session; switching tracks or videos does not reset it.coveris a full image URL pointing to/media/{sha256}. Video titles and covers are looked up asynchronously, so early on a card may only have progress.
GET/stream
Server-Sent Events 事件流。连上后立即推送一次当前状态,之后每当状态变化就再推送一次。数据格式与 /now 完全相同。
A Server-Sent Events stream. It sends the current status right after connecting and again whenever it changes. The data is identical to /now.
event: now
data: {"main": {"type": "anchor", "category": "class", …}, "side": [ … ], "updated_at": 1793014771.6}
: ping- 事件名固定为
now,用addEventListener('now', …)接收(不是onmessage)。 - 空闲时每 25 秒发一行
: ping注释保持连接。 - 全站同时最多 200 条连接,满了返回
503。服务器重启时会主动断开,浏览器的EventSource会自动重连。
- The event name is always
now; listen withaddEventListener('now', …), notonmessage. - A
: pingcomment every 25 idle seconds keeps the connection open. - At most 200 streams site-wide; beyond that you get
503. The server closes streams on restart andEventSourcereconnects on its own.
GET/today
今天(凌晨 4 点起)的主状态时间线和各类别时长。
Today's (from 4 a.m.) main-status timeline and per-category totals.
响应 200Response 200
{
"date": "2026-10-26",
"start": 1792958400.0, "end": 1793044800.0,
"timeline": [
{ "start": 1792958400.0, "end": 1792976496.3, "category": "sleep", "label": "睡觉" },
{ "start": 1792994400.0, "end": 1793000400.0, "category": "class", "label": "卫星控制系统建模仿真与数字孪生技术" }
],
"totals": {
"anchor": { "sleep": 18096, "class": 11755 },
"activity": { "dev": 20492, "research": 5984, "music": 438 }
},
"names": { "sleep": "睡觉", "class": "上课", "dev": "开发", "research": "科研", "music": "听歌" },
"updated_at": 1793014739.71
}| 字段 | Field | 说明 | Description |
|---|---|---|---|
start / end | 这一天的起止时间戳 | Bounds of the day | |
timeline | 主状态色块,按时间排序、互不重叠;没有任何状态的时段不出现。今天最后一块的 end 是当前时间。上课的 label 是课程名 | Main-status blocks, sorted and non-overlapping; gaps with no status are left out. Today's last block ends at the current time. For class, label is the course name | |
totals | 每条线各类别的秒数。不同类别可以重叠(边听歌边开发),所以加起来可能超过 24 小时;正事里摸鱼的时间不计入 | Seconds per category on each line. Categories may overlap (music while coding), so sums can exceed 24 h; slacking time inside serious work is excluded | |
names | 本次出现的类别的中文简称 | Chinese short names of the categories present |
GET/day
任意一天的公开时间线和时长,格式与 /today 相同。
Any day's public timeline and totals, in the same shape as /today.
查询参数Query
| 参数 | Param | 说明 | Description |
|---|---|---|---|
date | 必填,YYYY-MM-DD | Required, YYYY-MM-DD |
curl 'https://api.ignat.ai/presence/api/day?date=2026-10-25'
缺少 date 返回 422,格式不对返回 400。没有记录的日子返回空的 timeline 和 totals。
A missing date returns 422; a malformed one returns 400. Days without records return an empty timeline and totals.
GET/history
一段时间内每天的各类别时长和正事时长,以及区间内的游戏榜、听歌榜。不含项目名、网站和视频。
Daily per-category totals and serious-work time over a range, plus game and music charts for the range. No project names, sites or videos.
查询参数Query
| 参数 | Param | 说明 | Description |
|---|---|---|---|
from optional | 开始日期(含)。不写时为 to 往前 182 天(约半年) | First day (inclusive). Defaults to 182 days before to (about six months) | |
to optional | 结束日期(含)。不写时为今天 | Last day (inclusive). Defaults to today |
一次最多 400 天;from 晚于 to 或超过上限返回 400。days 只列到今天为止,将来的日期不出现。
At most 400 days per call; from after to or a longer range returns 400. days stops at today; future dates are omitted.
响应 200Response 200
{
"from": "2026-10-24", "to": "2026-10-26",
"days": [
{ "date": "2026-10-24", "totals": { "anchor": {}, "activity": {} }, "serious_sec": 0 },
{ "date": "2026-10-26",
"totals": { "anchor": { "sleep": 18096 }, "activity": { "dev": 20493, "research": 5984 } },
"serious_sec": 26477 }
],
"games": [],
"music": [
{ "key": "Smile. DK - Butterfly", "title": "Butterfly", "artist": "Smile. DK", "seconds": 174, "plays": 2 }
],
"names": { "sleep": "睡觉", "dev": "开发", "research": "科研" },
"updated_at": 1793014741.0
}serious_sec:当天实际在做正事(科研、开发)的秒数,几种正事重叠只算一次,不含摸鱼。games/music:按时长从多到少,各最多 10 项。plays是播放次数,暂停后继续算同一次。
serious_sec: seconds of actual serious work (research, dev) that day; overlaps count once and slacking is excluded.games/music: sorted by time, top 10 each.playscounts plays; resuming after a pause is the same play.
GET/media/{sha256}
封面、网站图标等图片。地址里是图片内容的 SHA-256(64 位小写十六进制),一般直接使用卡片里的 cover 地址即可,不需要自己拼。
Cover art, site icons and other images. The path is the SHA-256 of the content (64 lowercase hex chars); normally just use the cover URL from a card.
- 返回 JPEG、PNG、WebP 或 SVG 图片,带
Cache-Control: public, max-age=31536000, immutable:内容不会变,可以永久缓存。 - 不存在或地址格式不对时返回
404。
- Returns a JPEG, PNG, WebP or SVG image with
Cache-Control: public, max-age=31536000, immutable; the content never changes, so cache it forever. - Unknown or malformed IDs return
404.
GET/health
检查服务是否在运行。
Checks that the service is up.
{ "ok": true, "time": 1793014740.45, "streams": 0 }time 是服务器当前时间,streams 是当前打开的 /stream 连接数。服务器没运行时返回 502。
time is the server clock; streams is the number of open /stream connections. When the server is down you get 502.
私有接口:访问方式Private endpoints: access
- 需要先在 401.ignat.ai 登录,请求要带上登录 Cookie;浏览器里写
fetch(url, { credentials: 'include' }),并且只接受来自https://now.ignat.ai的跨域请求。 - 未登录返回
401:{"error": "unauthorized", "login": "https://401.ignat.ai/"},可以把用户带到login地址登录。 - 绕过登录直接访问后端时,私有接口一律表现为不存在(
404)。
- Sign in at 401.ignat.ai first and send the session cookie: in a browser use
fetch(url, { credentials: 'include' }). Cross-origin calls are accepted only fromhttps://now.ignat.ai. - Without a session you get
401:{"error": "unauthorized", "login": "https://401.ignat.ai/"}; send the user tologinto sign in. - Requests that bypass the login gate see private endpoints as nonexistent (
404).
const r = await fetch('https://api.ignat.ai/presence/api/private/day?date=2026-10-26', { credentials: 'include' }) if (r.status === 401) location.href = (await r.json()).login
日期参数的写法、默认值和 400 天上限与 /history 相同。
Date parameters follow the same rules, defaults aside, and 400-day cap as /history.
GET/private/day
某一天的完整记录。参数 date 可选,默认今天。
The full record of one day. date is optional and defaults to today.
{
"date": "2026-10-26", "start": 1792958400.0, "end": 1793044800.0,
"segments": [
{ "id": "…", "line": "activity", "category": "dev", "start": …, "end": …,
"tier": 1, "project": "Presence", "source": "…", "slacking": false }
],
"timeline": [ /* same as /today, private records included */ ],
"totals": { "anchor": { … }, "activity": { … } },
"media": [
{ "type": "music", "key": "…", "title": "…", "artist": "…", "player": "…",
"start": …, "end": …, "seconds": 189, "private": false }
],
"web": [ { "domain": "github.com", "title": "…", "start": …, "end": …, "private": false } ],
"names": { /* every category */ },
"updated_at": …
}segments:两条线上的全部原始片段,可能带tier、detail、project、course、domain、source(上报设备),私有片段带private: true。media:播放记录,type为video、music、game、app(手机 App),另可能带album、page、source。web:浏览记录。
segments: every raw segment on both lines, possibly withtier,detail,project,course,domainandsource(reporting device); private ones carryprivate: true.media: playback records withtypevideo,music,gameorapp(phone apps), possibly withalbum,page,source.web: browsing records.
GET/private/summary
区间汇总排行。
Ranked totals over a range.
| 参数 | Param | 说明 | Description |
|---|---|---|---|
from / to optional | 默认最近 7 天 | Defaults to the last 7 days | |
group optional | 按什么排:category(默认)、project、site、video、track、game、app | Group by category (default), project, site, video, track, game or app | |
during optional | 锚定状态,例如 class:只统计那段时间里的活动,回答“上课时在干什么” | An anchor such as class: count only what happened during it (“what was I doing in class?”) |
{
"from": "2026-10-20", "to": "2026-10-26", "group": "category", "during": null,
"items": [
{ "key": "dev", "line": "activity", "title": "开发", "seconds": 20533 }
],
"updated_at": …
}items 按时长从多到少。line 只在 category 分组时出现;site 分组另带 visits(访问次数);媒体分组(video、track、game、app)的项与 /history 的榜单相同(title、artist、plays),且不限 10 项。
items are sorted by time. line appears only for category; site adds visits; media groups (video, track, game, app) return the same items as the /history charts (title, artist, plays) with no top-10 cut.
GET/private/focus
专注度。参数 from / to,默认最近 7 天。
Focus stats. from / to, defaulting to the last 7 days.
{
"from": "2026-10-20", "to": "2026-10-26",
"days": [
{ "date": "2026-10-26", "focus_sec": 26477, "longest_sec": 5400, "longest_start": …,
"interruptions": 6, "slack_sec": 1320 }
],
"channels": [ { "category": "phone", "title": "刷手机", "seconds": 900 } ],
"updated_at": …
}focus_sec正事时长;longest_sec/longest_start最长一段连续专注;interruptions/slack_sec摸鱼次数和时长。channels:摸鱼时主要在做什么(网站按名字、游戏按名字),最多 10 项;后台听歌不算。
focus_secis serious-work time;longest_sec/longest_startthe longest unbroken stretch;interruptions/slack_secthe count and length of slacking.channels: what slacking time went to (sites and games by name), top 10; background music does not count.
GET/private/export
导出区间内的全部记录,作为附件下载(presence-开始_结束.json / .csv)。
Exports every record in the range as a download (presence-FROM_TO.json / .csv).
| 参数 | Param | 说明 | Description |
|---|---|---|---|
from / to optional | 默认今天一天 | Defaults to today only | |
format optional | json(默认):片段、播放记录、浏览记录和时区;csv:只有片段,带 BOM,Excel 直接打开中文不乱码 | json (default): segments, playback, browsing and the time zone; csv: segments only, with a BOM so Excel shows Chinese correctly |
每个片段另带 start_local / end_local(本地时间 ISO 8601)和 seconds。
Each segment also has start_local / end_local (local ISO 8601) and seconds.
类别Categories
当前的类别如下(可能增加)。显示名请以响应里的 names 为准。
Current categories (more may be added). Use names from the response for display.
| category | 线 | Line | 简称 | Meaning | 说明 | Notes |
|---|---|---|---|---|---|---|
custom | anchor / activity | 自定义 | Custom | 文案自定,等级可设 | Free text, tier configurable | |
class | anchor | 上课 | Class | 来自课表,带课程名 | From the timetable, with course name | |
eat | anchor | 吃饭 | Eating | — | ||
sleep | anchor | 睡觉 | Sleeping | — | ||
office | anchor | 办公室 | Office | 合并科研 | Folds in research | |
research | activity · tier 1 | 科研 | Research | 正事,公开项目名 | Serious; project name public | |
dev | activity · tier 1 | 开发 | Dev | 正事,公开项目名 | Serious; project name public | |
game | activity · tier 2 | 游戏 | Gaming | 带游戏名 | With game name | |
out | activity · tier 2 | 出去玩 | Out | — | ||
video | activity · tier 3 | 看视频 | Video | — | ||
browse | activity · tier 3 | 上网 | Browsing | — | ||
phone | activity · tier 4 | 刷手机 | Phone | 带 App 名 | With app name | |
music | activity · tier 4 | 听歌 | Music | — | ||
away / offline | idle | 暂时离开 / 离线 | Away / offline | 只出现在 /now | Only in /now |
错误Errors
错误响应是 JSON:{"detail": "..."},detail 是中文说明;参数缺失时 detail 是一个数组。
Errors are JSON: {"detail": "..."} with a Chinese message; for missing parameters detail is an array.
| 状态码 | Status | 含义 | Meaning |
|---|---|---|---|
400 | 日期格式不对、开始晚于结束、超过 400 天、group / during / format 取值不对 | Bad date, from after to, over 400 days, or an invalid group / during / format | |
401 | 私有接口未登录,见访问方式 | Private endpoint without a session; see Access | |
404 | 路径或图片不存在 | Unknown path or image | |
422 | 缺少必填参数(/day 的 date) | Missing required parameter (date on /day) | |
502 | 服务器没在运行 | The server is not running | |
503 | /stream 连接数已满 | /stream is full |