yash123321

Untitled

Jan 28th, 2025
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. import json
  2. import requests
  3. import mariadb
  4. from requests.auth import HTTPBasicAuth
  5.  
  6.  
  7. # Connect to database
  8. connection = mariadb.connect(
  9. user= "", #use your username
  10. password="", # user your password
  11. host="dr-mr-kaardb-r01.mykaarma.com",
  12. port=3306,
  13. database="KaarDBProd"
  14. )
  15.  
  16. # Create a cursor object
  17. mycursor = connection.cursor()
  18.  
  19. # Define the SQL query to fetch the UUIDs
  20. uuid_list = [
  21. 'c01970c3e2d71b286448b5ff903aab59ae6f9a912747b03c7efb4218993573f2',
  22. '30f192e0d6fd87094762648d4b0862295daf5bf461f2ecbed9ff63fbbf44238d',
  23. 'b7491719a270d02dcc3307f0dbc4cf64dd6d6d1db491cde2feee1d1ac7409f32',
  24. 'eef22d545592fe6bf922ace06573dc1946e10b24db922e2241cbecdc586637ac',
  25. 'acaf6b97884abc93ac8781243aa709b135706d6ecd1f2c1edf68d29fa55cae82',
  26. '998ae04405dc39a8e441b33e3eb534d121abf17786224fe6a2c9909856f99a8c',
  27. 'accbd110aa8f9f3d97df3e8b4b70024774bfeb49b9ce0cd9b4ef3cc087de9c7c',
  28. '0494af3a4a9093579ae6d154e004effd4c66215eb60ae2d9ead25b44576f52b2',
  29. '667264d47cf5dadeba1496d7ed6f984e331ef2236795419c6065e187675d14ee',
  30. '40903dd4265fad5b29b1c413cadd77d1dbf5a0386e1aed9ad815b0f271cbf7d6',
  31. 'c507514438e83bb6055a8c5dd80b0182090e3bdb6924d08f5039c9dac0d20d8b',
  32. 'ce8c9b6417dfce9336ef242bd875b8388566ca0512aa10794d5daaa564f3f6e2',
  33. '43f0b6645d2dfba8af832610716f456d46f90d588791e0c603ccc7325b66be6c',
  34. '83522999954d3b6f591417d6a3bbdb8cfd9ca9934c2dee58e97267cd9d8a719c',
  35. '88472afa879d8163964ecbb68a10fc365e7f1dc547c46b681c910ea60e37e8c8',
  36. '63264da32049447bab38a02b31e7ac81af2ed83762d526144590a5bee63dd5ef',
  37. 'd88d2b8b28c73a8bb27b585aff8df3ea6bea07a46fe60abedb8b8b524fc827f1',
  38. '4c680b06c6e9ececbe6c66a21b40268f61d1bb7bce6ac114d540c4f5ddf9f6a1',
  39. '10ecfd71b3b5d32d4b91e1294145634cb5af6c683d7f4cbdf4fdb6a33043c581',
  40. '298a42a0ab1be41870af02a6813586c371ddacb987668ebf459112c35c291b8d',
  41. '457cbcbb55f129a5253a5ead8049b3cb26b6bde0794044f785bd8d02d93861f1',
  42. '2a2d6bbf177831a1811951a5a83197a5fa483a4514358bf5889e36ee29a5a214',
  43. '68742b4c90ccdd5859eda29b9b84f2568f5d6e310a643eaba5590bafb62852a0',
  44. '1ab062b650b0972b0878be7d4a3910d7eeb2317857a12cdd987c7aa3ec4c8905',
  45. '51da5b55ea4cce0c44d6e0b940323b99dacca0f1f73b1f51f12306c66935ade9',
  46. 'e080def589e6514a92b24c2cc33064cac0615ad3d2352695f3df6f6c02ade1f3',
  47. 'b526567241f4d785044b8dc47472f0e63bd78ae13bd496263fc23b3a90e53f56',
  48. 'a3a6e2029e5b50484e40e4b6d0d8624f53b815aa2405b261981336b5fea70c28',
  49. 'd732ae3dd8da2f1164ac37788a01021e722773135d04eff3c16f611fae4c833c',
  50. '9e866ef11910897abafd6e62b519221626237db1d5fe7832a1e5c1d269ca4d0a'
  51. ]
  52.  
  53.  
  54. sql = """select Dealer.UUID from Dealer where UUID in ({})""".format(
  55. ",".join(['"' + uuid + '"' for uuid in uuid_list])
  56. )
  57.  
  58. # Execute the query
  59. mycursor.execute(sql)
  60.  
  61. # Fetch all the results
  62. results = mycursor.fetchall()
  63.  
  64. print(results)
  65.  
  66. # Close the cursor and the connection
  67. mycursor.close()
  68. connection.close()
  69.  
  70. # Create an empty dictionary to store the JSON data
  71. data = {}
  72.  
  73. print("Dealers selected:")
  74.  
  75. # Loop through the results and add them to the dictionary
  76. for i, result in enumerate(results):
  77. # Get the UUID from the result tuple
  78. uuid = result[0]
  79. print(uuid)
  80. # Create a sub-dictionary for each UUID
  81. data[uuid] = {
  82. "updateDSORequestDTOList": [
  83. {
  84. "optionKey": "appointments.populate.appointmentview.mongo.rollout",
  85. "optionValue": "true",
  86. "validate": True
  87. },
  88. # {
  89. # "optionKey": "rollout.stage",
  90. # "optionValue": "canary",
  91. # "validate": True
  92. # }
  93.  
  94.  
  95. # {
  96. # "optionKey": "appointments.ledger.view.backend.redesigned.rollout",
  97. # "optionValue": "false",
  98. # "validate": True
  99. # },
  100. # {
  101. # "optionKey": "mci.generic.eventbus.publish.rollout",
  102. # "optionValue": "false",
  103. # "validate": True
  104. # }
  105. ]
  106. }
  107.  
  108. data = {"dealerUuidAndUpdateDealerSetupOptionCollectionMap": data}
  109.  
  110. # Add the validate key to the main dictionary
  111. data["validate"] = True
  112.  
  113. # Convert the dictionary to a JSON string
  114. json_data = json.dumps(data, indent=4)
  115.  
  116. print("Request Body: ")
  117. # Print the JSON string
  118. print(json_data)
  119.  
  120. url = 'https://api.mykaarma.com/manage/v2/dealers/dsos/bulk'
  121. auth = HTTPBasicAuth('mk-admin-tool','W4vqUxuzYSg_clNvEt_nn0oHZFTJGjGRxwQ8CxV7y7c')
  122.  
  123. response = requests.put(url, auth = auth, json = data)
  124. print('Response Status Code:', response.status_code)
  125. print('Response Content:', response.text)
Advertisement
Add Comment
Please, Sign In to add comment