Skip to content

Commit

Permalink
summarized list generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks-gaming committed Jan 1, 2025
1 parent a9b7537 commit 2576094
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/generate_singlefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@
from datetime import datetime
import os

async def append_to_json(file_path, new_data):
# Check if the file exists and create if not
if not os.path.exists(file_path):
async with aiofiles.open(file_path, 'w') as f:
await f.write(json.dumps([], indent=4))

# Read and update the existing data
async with aiofiles.open(file_path, 'r') as f:
try:
existing_data = json.loads(await f.read())
except json.JSONDecodeError:
existing_data = [] # In case of empty or invalid JSON

existing_data.extend(new_data) # Efficiently append new data

# Write the updated data back to the file
async with aiofiles.open(file_path, 'w') as f:
await f.write(json.dumps(existing_data, indent=4))


async def process_region(region: str):
try:
region_file_path = os.path.join("regions", region, f'amnezia-{region}-voice-list.json')
Expand All @@ -32,6 +12,15 @@ async def process_region(region: str):
except Exception as e:
print(f"Error processing region {region}: {e}")
return [] # Return empty list on failure

async def process_base():
try:
region_file_path = 'amnezia-base-list.json'
async with aiofiles.open(region_file_path, 'r') as f:
return json.loads(await f.read())
except Exception as e:
print(f"Error processing base domains: {e}")
return [] # Return empty list on failure


async def main():
Expand All @@ -41,6 +30,7 @@ async def main():
# Process regions concurrently
tasks = [process_region(region) for region in regions]
region_data = await asyncio.gather(*tasks)
base_data = await process_base()

for row in region_data:
if row:
Expand All @@ -57,7 +47,11 @@ async def main():
await f.write(domain_list + "\n")

# Append new data to the JSON file
await append_to_json('amnezia-voice-list.json', data)
async with aiofiles.open('amnezia-voice-list.json', 'w') as f:
await f.write(json.dumps(data, indent=4))

async with aiofiles.open('amnezia-everything-list.json', 'w') as f:
await f.write(json.dumps(base_data + data, indent=4))


if __name__ == "__main__":
Expand Down

0 comments on commit 2576094

Please sign in to comment.