-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (42 loc) · 1.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import datetime
import os
import sys
from urllib.parse import unquote
import csv
import argparse
def convert_time(timestamp: int):
return datetime.datetime.fromtimestamp(timestamp / 1000.0).strftime(
"%Y-%m-%d %H:%M:%S"
)
def parse_history(source, destination):
jsonData = json.load(open(f"{source}/entries.json", "r"))
originalFileName = jsonData["resource"].split("/")[-1]
originalFilePath = jsonData["resource"].split("///")[-1]
with open(f"{destination}/{originalFileName}_edits.csv", "w", newline="") as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(["original_path", "original_name", "temp_name", "saved_at"])
for entry in jsonData["entries"]:
csvwriter.writerow(
[
f"{unquote(originalFilePath)}/{unquote(originalFileName)}",
unquote(originalFileName),
entry["id"],
convert_time(entry["timestamp"]),
]
)
def main(source, destination):
if source[-1] != "/":
source = source+"/"
if destination[-1] != "/":
destination = destination + "/"
for directory in os.listdir(source):
parse_history(f"{source}{directory}", destination)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="VSCode History Parser",
description="Parses the different versions of files in VSCode, for use with KAPE", epilog="Outputs a CSV file for each file that was worked on in VSCode")
parser.add_argument('-s','--src', help="Source directory. Must be C:\\Users\\user\\AppData\\Roaming\\Code\\User\\History")
parser.add_argument('-d','--dst', help="Output directory, where the CSV files are output")
args = parser.parse_args()
main(args.src, args.dst)