from pymongo import MongoClient
import mysql.connector as mc
import json


client = MongoClient("mongodb://192.168.31.176:27017/")
db = client["zerodha_test"]
collection = db["bse_data"]

db = mc.connect(user="root", host="localhost", password="", database="instruments", port=3307)
cursor = db.cursor()
get_tokens = "SELECT instrument_token, exchange_token, tradingsymbol FROM `instrument_list` WHERE `segment` LIKE 'BSE' AND `exchange` LIKE 'BSE' AND `instrument_type` LIKE 'EQ';"
cursor.execute(get_tokens)
tokens = cursor.fetchall()

for data in tokens:
    instrument_token, exchange_token, tradingsymbol = data
    collection.update_many(
        { "symbol": f"{tradingsymbol}" },  # Match all documents
        {
            "$set": {
                "exchange_token": int(exchange_token),  # Add or update new_field_1
                "instrument_token": int(instrument_token)     # Add or update new_field_2
            }
        }
    )



