jordan martin-hall b7590e30db move to pc
2023-07-15 18:35:27 +10:00

548 lines
20 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "'module' object is not callable",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn [2], line 27\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[39mreturn\u001b[39;00m data\n\u001b[1;32m 26\u001b[0m directory \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39m/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m---> 27\u001b[0m json_data \u001b[39m=\u001b[39m generate_json(directory)\n\u001b[1;32m 29\u001b[0m \u001b[39m# Save the JSON data to a file\u001b[39;00m\n\u001b[1;32m 30\u001b[0m \u001b[39mwith\u001b[39;00m \u001b[39mopen\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mgame_consoles.json\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mw\u001b[39m\u001b[39m'\u001b[39m) \u001b[39mas\u001b[39;00m json_file:\n",
"Cell \u001b[0;32mIn [2], line 12\u001b[0m, in \u001b[0;36mgenerate_json\u001b[0;34m(directory)\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mgenerate_json\u001b[39m(directory):\n\u001b[1;32m 5\u001b[0m data \u001b[39m=\u001b[39m {\n\u001b[1;32m 6\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmetadata\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[1;32m 7\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mpage\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mmain\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mroms\u001b[39m\u001b[39m\"\u001b[39m: {}\n\u001b[1;32m 11\u001b[0m }\n\u001b[0;32m---> 12\u001b[0m \u001b[39mfor\u001b[39;00m root, dirs, files \u001b[39min\u001b[39;00m os\u001b[39m.\u001b[39;49mpath(directory):\n\u001b[1;32m 13\u001b[0m console_name \u001b[39m=\u001b[39m os\u001b[39m.\u001b[39mpath\u001b[39m.\u001b[39mbasename(root)\n\u001b[1;32m 14\u001b[0m rom_count \u001b[39m=\u001b[39m \u001b[39mlen\u001b[39m(files)\n",
"\u001b[0;31mTypeError\u001b[0m: 'module' object is not callable"
]
}
],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"metadata\": {\n",
" \"page\": \"main\",\n",
" \"author\": \"Benjamyn Love\"\n",
" },\n",
" \"roms\": {}\n",
" }\n",
" for root, dirs, files in os.walk(directory):\n",
" console_name = os.path.basename(root)\n",
" rom_count = len(files)\n",
" uri = \"/\" + console_name.lower().replace(\" \", \"-\")\n",
" \n",
" console = {\n",
" \"name\": console_name,\n",
" \"uri\": uri,\n",
" \"count\": rom_count\n",
" }\n",
" data[\"roms\"][console_name.lower()] = console\n",
" \n",
" return data\n",
"\n",
"directory = '/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('game_consoles.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"metadata\": {\n",
" \"page\": \"main\",\n",
" \"author\": \"Benjamyn Love\"\n",
" },\n",
" \"roms\": {}\n",
" }\n",
" for root, dirs, files in os.walk(directory):\n",
" for dir_name in dirs:\n",
" console_name = dir_name\n",
" dir_path = os.path.join(root, dir_name)\n",
" rom_count = len(os.listdir(dir_path))\n",
" uri = \"/\" + console_name.lower().replace(\" \", \"-\")\n",
" \n",
" console = {\n",
" \"name\": console_name,\n",
" \"uri\": uri,\n",
" \"count\": rom_count\n",
" }\n",
" data[\"roms\"][console_name.lower()] = console\n",
" \n",
" return data\n",
"\n",
"directory = '/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('game_consoles.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"metadata\": {\n",
" \"page\": \"main\",\n",
" \"author\": \"Benjamyn Love\"\n",
" },\n",
" \"roms\": {}\n",
" }\n",
" for dir_name in os.listdir(directory):\n",
" dir_path = os.path.join(directory, dir_name)\n",
" if os.path.isdir(dir_path):\n",
" console_name = dir_name\n",
" subdirectories = 0\n",
" files = 0\n",
" for entry in os.scandir(dir_path):\n",
" if entry.is_dir():\n",
" subdirectories += 1\n",
" elif entry.is_file():\n",
" files += 1\n",
"\n",
" uri = \"/\" + console_name.lower().replace(\" \", \"-\")\n",
" \n",
" console = {\n",
" \"name\": console_name,\n",
" \"uri\": uri,\n",
" \"subdirectories\": subdirectories,\n",
" \"files\": files\n",
" }\n",
" data[\"roms\"][console_name.lower()] = console\n",
" \n",
" return data\n",
"\n",
"directory = '/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('game_consoles.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"metadata\": {\n",
" \"page\": \"main\",\n",
" \"author\": \"Benjamyn Love\"\n",
" },\n",
" \"roms\": {}\n",
" }\n",
" excluded_dirs = [\"excluded_dir1\", \"excluded_dir2\"] # Add your excluded directory names here\n",
" for dir_name in os.listdir(directory):\n",
" if dir_name in excluded_dirs:\n",
" continue\n",
"\n",
" dir_path = os.path.join(directory, dir_name)\n",
" if os.path.isdir(dir_path):\n",
" console_name = dir_name\n",
" subdirectories = 0\n",
" files = 0\n",
" for entry in os.scandir(dir_path):\n",
" if entry.is_dir():\n",
" subdirectories += 1\n",
" elif entry.is_file():\n",
" files += 1\n",
"\n",
" uri = \"/\" + console_name.lower().replace(\" \", \"-\")\n",
"\n",
" console = {\n",
" \"name\": console_name,\n",
" \"uri\": uri,\n",
" \"subdirectories\": subdirectories,\n",
" \"files\": files\n",
" }\n",
" data[\"roms\"][console_name.lower()] = console\n",
"\n",
" return data\n",
"\n",
"directory = '/path/to/your/directory'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('game_consoles.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"metadata\": {\n",
" \"page\": \"main\",\n",
" \"author\": \"Benjamyn Love + JMH\"\n",
" },\n",
" \"roms\": {},\n",
" \"utilities\": []\n",
" }\n",
" excluded_dirs = [\"emulation\", \"@recycle\", \"poobs\"] # Add your excluded directory names here\n",
" for dir_name in os.listdir(directory):\n",
" dir_path = os.path.join(directory, dir_name)\n",
" uri = \"/\" + dir_name.lower().replace(\" \", \"-\")\n",
" if os.path.isdir(dir_path):\n",
" if dir_name in excluded_dirs:\n",
" utilities_entry = {\n",
" \"name\": dir_name,\n",
" \"uri\": uri\n",
" }\n",
" data[\"utilities\"].append(utilities_entry)\n",
" else:\n",
" console_name = dir_name\n",
" subdirectories = 0\n",
" files = 0\n",
" for entry in os.scandir(dir_path):\n",
" if entry.is_dir():\n",
" subdirectories += 1\n",
" elif entry.is_file():\n",
" files += 1\n",
"\n",
" uri = \"/\" + console_name.lower().replace(\" \", \"-\")\n",
"\n",
" console = {\n",
" \"name\": console_name,\n",
" \"uri\": uri,\n",
" \"subdirectories\": subdirectories,\n",
" \"files\": files\n",
" }\n",
" data[\"roms\"][console_name.lower()] = console\n",
"\n",
" return data\n",
"\n",
"directory = '/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('game_consoles2.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"roms\": []\n",
" }\n",
"\n",
" for dir_name in os.listdir(directory):\n",
" dir_path = os.path.join(directory, dir_name)\n",
" if os.path.isdir(dir_path):\n",
" console_entry = {\n",
" \"name\": dir_name,\n",
" \"uri\": \"/\" + dir_name.lower().replace(\" \", \"-\"),\n",
" \"contents\": {\n",
" \"base\": {},\n",
" \"updates\": [],\n",
" \"dlc\": []\n",
" }\n",
" }\n",
" base_rom = None\n",
" updates = []\n",
" dlc = []\n",
" \n",
" for entry in os.scandir(dir_path):\n",
" if entry.is_file():\n",
" file_name = entry.name\n",
" file_path = entry.path\n",
" file_size = os.path.getsize(file_path)\n",
"\n",
" if file_name.lower().endswith(\".nsp\"):\n",
" if \"[v0]\" in file_name:\n",
" base_rom = {\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" }\n",
" elif \"[v\" in file_name:\n",
" updates.append({\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" })\n",
" else:\n",
" dlc.append({\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" })\n",
"\n",
" console_entry[\"contents\"][\"base\"] = base_rom\n",
" console_entry[\"contents\"][\"updates\"] = updates\n",
" console_entry[\"contents\"][\"dlc\"] = dlc\n",
"\n",
" data[\"roms\"].append(console_entry)\n",
"\n",
" return data\n",
"\n",
"directory = '/path/to/your/directory'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('roms.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'name': 'ps4', 'path': '/ps4'}, {'name': '@recycle', 'path': '/@recycle'}, {'name': 'switch', 'path': '/switch'}]\n"
]
}
],
"source": [
"import json\n",
"\n",
"def generate_directory_list(json_file):\n",
" directories = []\n",
"\n",
" with open(json_file, 'r') as file:\n",
" data = json.load(file)\n",
"\n",
" roms_data = data.get('roms', {})\n",
" for console_name, console_entry in roms_data.items():\n",
" console_path = console_entry.get('uri', '')\n",
"\n",
" directory = {\n",
" 'name': console_name,\n",
" 'path': console_path\n",
" }\n",
" directories.append(directory)\n",
"\n",
" return directories\n",
"\n",
"json_file = 'game_consoles2.json' # Replace with the path to your JSON file\n",
"directory_list = generate_directory_list(json_file)\n",
"\n",
"print(directory_list)\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directories):\n",
" data = {\n",
" \"roms\": []\n",
" }\n",
"\n",
" for directory in directories:\n",
" dir_name = directory[\"name\"]\n",
" dir_path = directory[\"path\"]\n",
" console_entry = {\n",
" \"name\": dir_name,\n",
" \"uri\": \"/\" + dir_name.lower().replace(\" \", \"-\"),\n",
" \"contents\": {\n",
" \"base\": {},\n",
" \"updates\": [],\n",
" \"dlc\": []\n",
" }\n",
" }\n",
" base_rom = None\n",
" updates = []\n",
" dlc = []\n",
"\n",
" for entry in os.scandir(dir_path):\n",
" if entry.is_file():\n",
" file_name = entry.name\n",
" file_path = entry.path\n",
" file_size = os.path.getsize(file_path)\n",
"\n",
" if file_name.lower().endswith(\".nsp\"):\n",
" if \"[v0]\" in file_name:\n",
" base_rom = {\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" }\n",
" elif \"[v\" in file_name:\n",
" updates.append({\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" })\n",
" else:\n",
" dlc.append({\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" })\n",
"\n",
" console_entry[\"contents\"][\"base\"] = base_rom\n",
" console_entry[\"contents\"][\"updates\"] = updates\n",
" console_entry[\"contents\"][\"dlc\"] = dlc\n",
"\n",
" data[\"roms\"].append(console_entry)\n",
"\n",
" return data\n",
"\n",
"# List of directories obtained from previous JSON file\n",
"directories = [\n",
" {\n",
" \"name\": \"Shin Megami Tensai V\",\n",
" \"path\": \"/path/to/Shin Megami Tensai V\"\n",
" },\n",
" {\n",
" \"name\": \"Astral Chain\",\n",
" \"path\": \"/path/to/Astral Chain\"\n",
" },\n",
" {\n",
" \"name\": \"Dead Cells\",\n",
" \"path\": \"/path/to/Dead Cells\"\n",
" }\n",
"]\n",
"\n",
"json_data = directory_list\n",
"\n",
"# Save the JSON data to a file\n",
"with open('roms.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"def generate_json(directory):\n",
" data = {\n",
" \"roms\": []\n",
" }\n",
"\n",
" for dir_name in os.listdir(directory):\n",
" dir_path = os.path.join(directory, dir_name)\n",
" if os.path.isdir(dir_path):\n",
" console_entry = {\n",
" \"name\": dir_name,\n",
" \"uri\": \"/\" + dir_name.lower().replace(\" \", \"-\"),\n",
" \"contents\": {\n",
" \"base\": {},\n",
" \"updates\": [],\n",
" \"dlc\": []\n",
" }\n",
" }\n",
" base_rom = None\n",
" updates = []\n",
" dlc = []\n",
" \n",
" for entry in os.scandir(dir_path):\n",
" if entry.is_file():\n",
" file_name = entry.name\n",
" file_path = entry.path\n",
" file_size = os.path.getsize(file_path)\n",
"\n",
" if file_name.lower().endswith(\".nsp\"):\n",
" if \"[v0]\" in file_name:\n",
" base_rom = {\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" }\n",
" elif \"[v\" in file_name:\n",
" updates.append({\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" })\n",
" else:\n",
" dlc.append({\n",
" \"name\": file_name,\n",
" \"size\": file_size\n",
" })\n",
"\n",
" console_entry[\"contents\"][\"base\"] = base_rom\n",
" console_entry[\"contents\"][\"updates\"] = updates\n",
" console_entry[\"contents\"][\"dlc\"] = dlc\n",
"\n",
" data[\"roms\"].append(console_entry)\n",
"\n",
" return data\n",
"\n",
"directory = '/Users/jordanmartin/stuff/rm_site_dir_test/10.6.9.5/'\n",
"json_data = generate_json(directory)\n",
"\n",
"# Save the JSON data to a file\n",
"with open('roms.json', 'w') as json_file:\n",
" json.dump(json_data, json_file, indent=4)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.11.0"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}