Files
2024-07-25 12:24:09 -04:00

147 lines
3.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Extracted 241 titles and stored them in titles.txt\n"
]
}
],
"source": [
"import json\n",
"\n",
"# Define the input and output file names\n",
"input_file = 'Chrome\\History.json'\n",
"output_file = 'titles.txt'\n",
"\n",
"# Read the JSON data from the input file\n",
"with open(input_file, 'r') as file:\n",
" data = json.load(file)\n",
"\n",
"# Extract titles from the JSON data\n",
"titles = [entry['title'] for entry in data.get('Browser History', [])]\n",
"\n",
"# Write the extracted titles to the output file\n",
"with open(output_file, 'w') as file:\n",
" for title in titles:\n",
" if len(title.strip()) != 0:\n",
" file.write(f\"{title}\\n\")\n",
"\n",
"print(f\"Extracted {len(titles)} titles and stored them in {output_file}\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2024-03-13 11:57:15\n"
]
}
],
"source": [
"from datetime import datetime\n",
"\n",
"\n",
"def convert_time_usec_to_readable(time_usec):\n",
" # Convert microseconds to seconds\n",
" time_seconds = time_usec / 1000000\n",
"\n",
" # Convert Unix timestamp to a datetime object\n",
" dt_object = datetime.fromtimestamp(time_seconds)\n",
"\n",
" # Format the datetime object to a readable string\n",
" readable_time = dt_object.strftime(\"%Y-%m-%d %H:%M:%S\")\n",
"\n",
" return readable_time\n",
"\n",
"\n",
"# Example time_usec value\n",
"time_usec = 1710345435804090\n",
"print(convert_time_usec_to_readable(time_usec)) # Output: '2024-05-22 14:37:15'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Extracted 241 titles and stored them along with timestamp in titles_with_timestamp.txt\n"
]
}
],
"source": [
"import json\n",
"from datetime import datetime\n",
"\n",
"# Define the input and output file names\n",
"input_file = \"Chrome\\History.json\"\n",
"output_file = \"titles_with_timestamp.txt\"\n",
"\n",
"# Read the JSON data from the input file\n",
"with open(input_file, \"r\") as file:\n",
" data = json.load(file)\n",
"\n",
"# Extract titles from the JSON data\n",
"entries = [\n",
" (entry[\"title\"], entry[\"time_usec\"]) for entry in data.get(\"Browser History\", [])\n",
"]\n",
"\n",
"\n",
"# Write the extracted titles with timestamp to the output file\n",
"with open(output_file, \"w\") as file:\n",
" for title, time_usec in entries:\n",
" if len(title.strip()) != 0:\n",
" readable_timestamp = convert_time_usec_to_readable(time_usec)\n",
" file.write(f\"{readable_timestamp}: {title}\\n\")\n",
"\n",
"print(\n",
" f\"Extracted {len(titles)} titles and stored them along with timestamp in {output_file}\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "torch2",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}