PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Scrap Mechanic Mod Search Using Python 3

Go down

Scrap Mechanic Mod Search Using Python 3 Empty Scrap Mechanic Mod Search Using Python 3

Post by jamied_uk 16th May 2023, 16:33

Code Example



Code:
# Stage 1
import requests

response=requests.get("https://scrapmechanicmods.com/blueshap.txt")
shapeids=response.text.splitlines()

# Stage 2
import os

if not os.path.exists("iconxml"):
    os.makedirs("iconxml")

for shapeid in shapeids:
    url=f"https://scrapmechanicmods.com/iconmap/{shapeid}.xml"
    response=requests.get(url)
    with open(f"iconxml/{shapeid}.xml", "w") as file:
        file.write(response.text)

# Stage 3
with open("blue.jso", "rb") as file:
    raw_data=file.read()

byte_array=list(raw_data)
byte_positions=range(0, len(byte_array), 16)

bm_values=[]
for byte_position in byte_positions:
    bm_values.append(",".join(str(byte_array[i]) for i in range(byte_position, byte_position + 16)))

with open("blue.txt", "w") as file:
    file.write(" ".join(bm_values))

# Stage 4
import os

saved=[]
with open("blueshap.txt", "r") as file:
    shapeids=file.read().splitlines()

with open("modsused.htm", "w") as file:
    file.write("")  # Clear the file if it exists

for shapcount, shapeid in enumerate(shapeids, start=1):
    shapnum=str(shapcount).zfill(3)
    print(f"[{shapnum}] locate: {shapeid}  ", end="")
    foundshape=False
    foundinfile=""

    with open("xmlindex.txt", "r") as index_file:
        for xml_filename in index_file.read().splitlines():
            with open(f"iconxml/{xml_filename}", "r") as xml_file:
                for line in xml_file:
                    for i in range(len(line) - 35):
                        if shapeid.lower() == line[i:i+36].lower():
                            foundshape=True
                            foundinfile=os.path.splitext(xml_filename)[0]
                            break
                    if foundshape:
                        break
                if foundshape:
                    break

    if foundshape:
        with open("modsused.htm", "a") as file:
            file.write(f'<a href="https://steamcommunity.com/workshop/filedetails/?id={foundinfile}">click me</a><br>')

        print(f"in: {foundinfile}  <{len(saved) + 1}>")
        saved.append(foundinfile)
    else:
        with open("modsused.htm", "a") as file:
            file.write("** NOT FOUND **<br>")
        print("** NOT FOUND **")

print(saved)


jamied_uk
jamied_uk
Admin

Posts : 2952
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum