Hello, I'm currently working on a Python script to automatically update the industry of a script. I'm interested in finding a method in Python that retrieves all the industries and their corresponding IDs. This way, I can avoid manually updating the industry ID for each individual industry
The following is the code to update a script with Industry ID = 5
import win32com.client as win32
import time
# Connect to Amibroker
try:
amibroker = win32.Dispatch('Broker.Application')
print("Connected to AmiBroker")
except Exception as e:
print(f"Error connecting to AmiBroker: {e}")
exit() # Exit the script if there is an error connecting
# Get the stock object
symbol = "MOL"
stock = amibroker.Stocks(symbol)
# Update symbol information
if stock:
stock.Ticker = "MOL"
stock.FullName = "Meghmani Organics Ltd"
stock.IndustryID = 5 # Set IndustryID to 5 (ID for "Coal")
print(f"Updated information for {symbol}")
else:
print(f"Stock not found: {symbol}")
# Refresh the database
amibroker.RefreshAll()
time.sleep(3)
print("Database updated")
Currently, I have to write the industry ID manually. I would like to change this so that I can simply pass the industry name to the script, and the script will fetch the ID itself.
Any help with this would be greatly appreciated.