If i dream about something, that is trying out something new at a leasurly pace and once I have something working, take a break and cherish it by having a refreshing swim in the beach.
While I don't live by the beach and my day job doesn't allow much wiggle room to do big projects, I am not too sad about it as I still have time to churn out small projects now and then. I regret that I haven't taken this seriously till now, but I am happy that I am taking some action. I am not having any high expectations for myself, but I am completely surrending myself to the magic of compounding, and hope to chip away few lines of code every day or week at the least.
Today life provided one such opportunity, while I kept staring at my work laptop. There was one minor inconvenience which was bothering me for couple of weeks. I cloned new repos this month. It is a microservices architecture and all the apis are written using .net core, and we have to constantly change keys to connect to QA environment to reproduce bugs or test some functionality which can be done only in QA due to data issues in dev. Ha ha, I know, the era of AI right. Yeah, somethings never change.
So, this is an easy problem if u have admin access and you can pass appsetting keys from environment variables by writing a simple bash script to setting them or clearing them. But this is not your laptop. So, env and bash script are no go. I do have powershell though. This is perfect since, the appSettings file is a json file and I can update file using powershell. But how about python ? I quickly asked chatgeepeetee can i read json in python. It is fucking simple, three lines of code. I am amazed. I decided I would write some python code now. By the way i am not completely alien to python. I did some fiddling with servomotors and raspberry pi, but I have used a script from online to do it. I have never envisioned any idea with python as a tool to crack it. That changes today. I have decided to build something to soothe my inconvenience.
I asked gpt, how to open a file, and how to save a file and then got to write my first productive 12 lines of python code to change my environment to QA.
----------------------code begins----------------------------------------------
import json
appSettingsPath = '<mypath>'
with open(appSettingsPath, 'r') as file:
data = json.load(file)
data["CacheSettings"]["Endpoints"][0] = "qa-conn-string-redis:6379"
data["CacheSettings"]["AbortOnConnectFail"] = False
#some more changes
with open(appSettingsPath, 'w') as file:
json.dump(data, file, indent = 4)
----------------------code ends----------------------------------------------
That's it. I ran it and felt accomplished and just like that I am also a python dev now :P
PS: I have to build on this, I need to make it more dynamic to pass api name and then automate it to get the path on its own.