File size: 1,956 Bytes
a906372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3

import urllib3
from bs4 import BeautifulSoup
import json
import sqlite3
import concurrent.futures
from tqdm import tqdm
import traceback

def process_url(url):
  try:
    structure_name = url.split('/minecraft/')[-1].replace('#blueprints', '')
    http = urllib3.PoolManager()
    r = http.request('GET', url)
    soup = BeautifulSoup(r.data.decode('utf-8'), 'html.parser')

    obj = next(s['src'] for s in soup.find_all('script') if 'src' in s.attrs and 'myRenderObject' in s['src'])
    r = http.request('GET', obj)
    data = r.data.decode('utf-8')
    eq = data.find('=')
    d = json.loads(data[eq+1:])

    conn = sqlite3.connect('minecraft_structures.db')
    cur = conn.cursor()

    cur.execute(f'''
      CREATE TABLE IF NOT EXISTS "{structure_name}" (
        x INTEGER,
        y INTEGER,
        z INTEGER,
        block_name TEXT
      )
    ''')

    for level, blocks in d.items():
      for x, z_block in blocks.items():
        for z, block in z_block.items():
          cur.execute(f'INSERT INTO "{structure_name}" (x, y, z, block_name) VALUES (?, ?, ?, ?)',
                (int(x), int(level), int(z), block['name']))

    conn.commit()
    conn.close()
    return None
  except Exception as e:
    return f"Error processing {url}: {str(e)}\n{traceback.format_exc()}"

with open('pages.txt', 'r') as f:
  urls = [line.strip() for line in f if line.strip()]

errors = []
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
  futures = [executor.submit(process_url, url) for url in urls]
  for future in tqdm(concurrent.futures.as_completed(futures), total=len(urls), desc="Processing URLs"):
    result = future.result()
    if result:
      errors.append(result)

if errors:
  with open('errors.log', 'w') as f:
    for error in errors:
      f.write(f"{error}\n")
  print(f"Encountered {len(errors)} errors. Check errors.log for details.")
else:
  print("All URLs processed successfully.")