Change Lotus Prices
Enter the path to your Lotus assort.db file and and a multiplier you would like to adjust all prices buy. Effects RUB, USD, and Euro prices.unknown
python
a year ago
3.2 kB
21
Indexable
import json
import shutil
import os
import re
def modify_json_file_interactive():
def get_valid_input(prompt, type_func, error_message):
while True:
try:
return type_func(input(prompt))
except ValueError:
print(error_message)
# Ask for the JSON file path or use the default if none provided
default_file_path = "C:\\Singleplayer Tarkov\\SPT 3.8.1\\user\\mods\\Lotus\\db\\assort.json"
file_path = input(f"Enter the path to the JSON file (press enter to use default {default_file_path}): ")
if not file_path:
file_path = default_file_path
# Ask for the multiplier value
multiplier = get_valid_input("Enter the multiplier to apply to the count values: ", float, "Invalid multiplier. Please enter a numeric value.")
# Tpl values to check
tpl_values = ["5696686a4bdc2da3298b456a", "5449016a4bdc2d6f028b456f", "569668774bdc2da2298b4568"]
changes_count = 0 # Track the number of changes made
# Read the JSON file as plain text
try:
with open(file_path, 'r') as file:
lines = file.readlines()
except Exception as e:
print(f"Failed to open or read JSON file: {str(e)}")
return
i = 0
while i < len(lines):
line = lines[i].strip()
if any(tpl in line for tpl in tpl_values):
# Check if the next line contains "count"
if i + 1 < len(lines) and '"count":' in lines[i + 1]:
count_line = lines[i + 1]
# Extract the count value, modify it, and replace the line
count = int(re.search(r'"count": (\d+)', count_line).group(1))
new_count = int(count * multiplier)
new_count_line = re.sub(r'(\d+)', str(new_count), count_line)
lines[i + 1] = new_count_line
changes_count += 1
i += 1
print(f"Total changes made: {changes_count}")
# Determine how to save the modified data
print("How would you like to handle the modified file?")
print("1: Overwrite the original file")
print("2: Save to a new file")
print("3: Backup the original and overwrite")
choice = input("Enter your choice (1, 2, or 3): ")
# Save the modified lines back to a file based on user choice
if choice == '1':
with open(file_path, 'w') as file:
file.writelines(lines)
print("Original file has been overwritten.")
elif choice == '2':
new_file_path = file_path.replace(".json", "_edited.json")
with open(new_file_path, 'w') as file:
file.writelines(lines)
print(f"Data saved to new file: {new_file_path}")
elif choice == '3':
backup_path = file_path.replace(".json", "_backup.json")
import shutil
shutil.copy(file_path, backup_path)
with open(file_path, 'w') as file:
file.writelines(lines)
print(f"Original file backed up to: {backup_path} and overwritten.")
else:
print("Invalid choice, exiting without saving changes.")
def main():
modify_json_file_interactive()
if __name__ == "__main__":
main()Editor is loading...
Leave a Comment