MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / from_json

Method from_json

archivebox/index/schema.py:74–101  ·  view source on GitHub ↗
(cls, json_info, guess=False)

Source from the content-addressed store, hash-verified

72
73 @classmethod
74 def from_json(cls, json_info, guess=False):
75 from ..util import parse_date
76
77 info = {
78 key: val
79 for key, val in json_info.items()
80 if key in cls.field_names()
81 }
82 if guess:
83 keys = info.keys()
84 if "start_ts" not in keys:
85 info["start_ts"], info["end_ts"] = cls.guess_ts(json_info)
86 else:
87 info['start_ts'] = parse_date(info['start_ts'])
88 info['end_ts'] = parse_date(info['end_ts'])
89 if "pwd" not in keys:
90 info["pwd"] = str(Path(OUTPUT_DIR) / ARCHIVE_DIR_NAME / json_info["timestamp"])
91 if "cmd_version" not in keys:
92 info["cmd_version"] = "Undefined"
93 if "cmd" not in keys:
94 info["cmd"] = []
95 else:
96 info['start_ts'] = parse_date(info['start_ts'])
97 info['end_ts'] = parse_date(info['end_ts'])
98 info['cmd_version'] = info.get('cmd_version')
99 if type(info["cmd"]) is str:
100 info["cmd"] = [info["cmd"]]
101 return cls(**info)
102
103 def to_dict(self, *keys) -> dict:
104 if keys:

Callers

nothing calls this directly

Calls 4

parse_dateFunction · 0.85
guess_tsMethod · 0.80
field_namesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected