From bf7397f810433856b85821c6435f3cffa2e203b6 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Fri, 27 Mar 2026 22:19:19 +0530 Subject: [PATCH 01/19] added system_health.py --- day-01/system_health.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 day-01/system_health.py diff --git a/day-01/system_health.py b/day-01/system_health.py new file mode 100644 index 00000000..d51f2975 --- /dev/null +++ b/day-01/system_health.py @@ -0,0 +1,15 @@ +import psutil + +def check_system_health(): + cpu_threshodld = input("Enter CPU usage threshold (in percentage): ") + print("current cpu threshold is : ", cpu_threshodld) + + current_cpu = psutil.cpu_percent(interval=1) + print("Current CPU %: ", current_cpu) + + if current_cpu > int(cpu_threshodld): + print("CPU usage is above the threshold! sending email aert....") + else: + print("cpu is in normal state") + +check_system_health() \ No newline at end of file From 8cd4c43512af708eff35cb4f6a2544d7a8134452 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Sat, 28 Mar 2026 22:13:13 +0530 Subject: [PATCH 02/19] learning list --- day-02/mypractice/lists_ex.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 day-02/mypractice/lists_ex.py diff --git a/day-02/mypractice/lists_ex.py b/day-02/mypractice/lists_ex.py new file mode 100644 index 00000000..1afd43f6 --- /dev/null +++ b/day-02/mypractice/lists_ex.py @@ -0,0 +1,26 @@ +a=[100,200,3.1,True] + +print(type(a)) +print(a) +print(a[0]) +print(a[1]) +print(a[2]) +print(a[3]) + + +a = [100, 200, 3.1, True] +a.append(500) +for item in a: + print(item) + + + +clouds=list() +clouds.append("aws") +clouds.append("azure") + +#for item in clouds: +print(clouds) +print("length of cloud list:", len(clouds)) +print(dir(clouds)) +print(clouds.count.__doc__) \ No newline at end of file From d8ce3847e04a6e3ab3c2e8c71681ee1f65f4b754 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Mon, 30 Mar 2026 18:47:10 +0530 Subject: [PATCH 03/19] learnt structure with list and directory --- day-02/mypractice/dict_ex.py | 19 +++++++++++++++++++ day-02/mypractice/lists_ex.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 day-02/mypractice/dict_ex.py diff --git a/day-02/mypractice/dict_ex.py b/day-02/mypractice/dict_ex.py new file mode 100644 index 00000000..2933d966 --- /dev/null +++ b/day-02/mypractice/dict_ex.py @@ -0,0 +1,19 @@ +info = { + "name": "Rahul kumar", + "age" : 24, + "city": "Bangalore", + "package" : 3.5, + "married" : False, + "favourites" : ["python", "linux", "devops"] + +} + + +print(info["city"]) +print("I am married: ", info["married"]) + +info.update({"village": "alwalpur"}) +print(info) + +for items, value in info.items(): + print(items,value) \ No newline at end of file diff --git a/day-02/mypractice/lists_ex.py b/day-02/mypractice/lists_ex.py index 1afd43f6..65fa9c8c 100644 --- a/day-02/mypractice/lists_ex.py +++ b/day-02/mypractice/lists_ex.py @@ -8,7 +8,7 @@ print(a[3]) -a = [100, 200, 3.1, True] +a = [100, 200, 3.1, True,"Rahul"] a.append(500) for item in a: print(item) From 332f5a00300752a9cde6dbddb78d406b27857f16 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Tue, 31 Mar 2026 22:39:20 +0530 Subject: [PATCH 04/19] tried writting raw files --- day-02/mypractice/api.py | 2 ++ day-02/mypractice/stock_market_api.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 day-02/mypractice/api.py create mode 100644 day-02/mypractice/stock_market_api.py diff --git a/day-02/mypractice/api.py b/day-02/mypractice/api.py new file mode 100644 index 00000000..1dc49a42 --- /dev/null +++ b/day-02/mypractice/api.py @@ -0,0 +1,2 @@ +# here we will learn how to use API in python + \ No newline at end of file diff --git a/day-02/mypractice/stock_market_api.py b/day-02/mypractice/stock_market_api.py new file mode 100644 index 00000000..ee14d227 --- /dev/null +++ b/day-02/mypractice/stock_market_api.py @@ -0,0 +1,22 @@ +from urllib import response + +import requests + +API_KEY = "DAZR72VR6C6AVTHW" + +API_URL = "https://www.alphavantage.co/" + +symbol = "IBM" + +def get_stock_market_data(): + + query = f"query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={API_KEY}" + + print(API_URL+query) + + response = requests.get(url=API_URL+query) + + print(response.json()) + + +get_stock_market_data() \ No newline at end of file From c9106430d2f1af2564de0e2a505fea088bb5cf41 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Wed, 1 Apr 2026 03:29:03 +0530 Subject: [PATCH 05/19] Here, this code is taking input from user and giving output according to that --- day-02/mypractice/stock_market_api.py | 31 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/day-02/mypractice/stock_market_api.py b/day-02/mypractice/stock_market_api.py index ee14d227..daea946c 100644 --- a/day-02/mypractice/stock_market_api.py +++ b/day-02/mypractice/stock_market_api.py @@ -1,22 +1,33 @@ -from urllib import response - import requests API_KEY = "DAZR72VR6C6AVTHW" API_URL = "https://www.alphavantage.co/" -symbol = "IBM" +#symbol = "IBM" + +def get_stock_market_data(symbol,is_time_series): -def get_stock_market_data(): + query = f"query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={API_KEY}" - print(API_URL+query) + #print(API_URL+query) response = requests.get(url=API_URL+query) - - print(response.json()) - - -get_stock_market_data() \ No newline at end of file + for item,value in response.json().items(): + if is_time_series == "yes": + + print(item,value) + + + else : + if item == "Meta Data": + print(item,value) + +symbol = input("Enter the stock symbol: ") +is_time_series = input("Do you want to see the time series data? (yes/no): ") + + +get_stock_market_data(symbol,is_time_series) + \ No newline at end of file From d7eb76ba4b8f9a1f3311e2f645070fd800436a60 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Wed, 1 Apr 2026 03:47:58 +0530 Subject: [PATCH 06/19] Here, this code is taking input from user and giving output according to that beacuse there are two items with metadata and time stamps so if user is entering yes so it will show full item and value which get response from API and if cx is saying no then it will show just metadata --- day-02/mypractice/stock_market_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/day-02/mypractice/stock_market_api.py b/day-02/mypractice/stock_market_api.py index daea946c..0cbc8a2c 100644 --- a/day-02/mypractice/stock_market_api.py +++ b/day-02/mypractice/stock_market_api.py @@ -25,7 +25,7 @@ def get_stock_market_data(symbol,is_time_series): if item == "Meta Data": print(item,value) -symbol = input("Enter the stock symbol: ") +symbol = input("Enter the stock symbol(IBM,GOGL,AMZN): ") is_time_series = input("Do you want to see the time series data? (yes/no): ") From e6ba3097d2d2284fb26d3e01b5a59689bb4ed305 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Wed, 1 Apr 2026 04:05:35 +0530 Subject: [PATCH 07/19] this code is for practice purpose only to import API request and get the jokes from the API and print the setup and punchline of the joke. --- day-02/mypractice/jokes_api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 day-02/mypractice/jokes_api.py diff --git a/day-02/mypractice/jokes_api.py b/day-02/mypractice/jokes_api.py new file mode 100644 index 00000000..4f247f30 --- /dev/null +++ b/day-02/mypractice/jokes_api.py @@ -0,0 +1,14 @@ +import requests + +url = "https://official-joke-api.appspot.com/random_joke" + +# this code is for practice purpose only to import API reques + +def get_jokes(): + + response = requests.get(url=url) + for item,value in response.json().items(): + if item == "setup" or item == "punchline": + print(item,value) + +get_jokes() \ No newline at end of file From 305e578956b6525fe790ef5210e9a9064547002d Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Wed, 1 Apr 2026 12:14:16 +0530 Subject: [PATCH 08/19] added sample code just to show how to get api call and request --- day-02/mypractice/jokes_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/day-02/mypractice/jokes_api.py b/day-02/mypractice/jokes_api.py index 4f247f30..4d9e1a1c 100644 --- a/day-02/mypractice/jokes_api.py +++ b/day-02/mypractice/jokes_api.py @@ -2,7 +2,7 @@ url = "https://official-joke-api.appspot.com/random_joke" -# this code is for practice purpose only to import API reques +# this code is for practice purpose only to import API request and get the jokes from the API and print the setup and punchline of the joke. def get_jokes(): From 09dde3fbb95887330e5cad6d781189074a02ceac Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Mon, 6 Apr 2026 01:57:39 +0530 Subject: [PATCH 09/19] here we have write the code for anylyzing the log file --- day-08/mypractice/app.log | 22 +++++++++++++++++ day-08/mypractice/log_analyzer.py | 39 +++++++++++++++++++++++++++++++ day-08/mypractice/log_counts.json | 5 ++++ 3 files changed, 66 insertions(+) create mode 100644 day-08/mypractice/app.log create mode 100644 day-08/mypractice/log_analyzer.py create mode 100644 day-08/mypractice/log_counts.json diff --git a/day-08/mypractice/app.log b/day-08/mypractice/app.log new file mode 100644 index 00000000..e6e8c400 --- /dev/null +++ b/day-08/mypractice/app.log @@ -0,0 +1,22 @@ +2025-01-10 09:00:01 INFO Application started successfully +2025-01-10 09:00:05 INFO Connecting to database +2025-01-10 09:00:07 INFO Database connection established + +2025-01-10 09:05:12 WARNING High memory usage detected +2025-01-10 09:05:15 INFO Memory usage back to normal + +2025-01-10 09:10:22 ERROR Failed to fetch user data +2025-01-10 09:10:25 ERROR Database timeout occurred + +2025-01-10 09:15:30 INFO Retrying database connection +2025-01-10 09:15:32 INFO Database connection successful + +2025-01-10 09:20:45 WARNING Disk usage above 75% +2025-01-10 09:20:50 INFO Disk cleanup initiated + +2025-01-10 09:25:10 ERROR Unable to write logs to disk +2025-01-10 09:25:15 INFO Log rotation completed + +2025-01-10 09:30:00 INFO Application shutdown initiated +2025-01-10 09:30:05 INFO Application stopped + diff --git a/day-08/mypractice/log_analyzer.py b/day-08/mypractice/log_analyzer.py new file mode 100644 index 00000000..e3e435b7 --- /dev/null +++ b/day-08/mypractice/log_analyzer.py @@ -0,0 +1,39 @@ + #This function will help to read the logs from the 'app.log' file and print its contents to the console. It uses a context manager (the 'with' statement) to ensure that the file is properly closed after its suite finishes, even if an error occurs. The 'r' mode is used to open the file for reading. + +def read_logs(): + lines = [] + with open('app.log', 'r') as file: + lines = file.readlines() + return lines + + +def analyze(lines): + log_counts = { + "INFO": 0, + "WARNING": 0, + "ERROR": 0 + } + for line in lines: + if "INFO" in line: + log_counts.update({"INFO": log_counts["INFO"] + 1}) + elif "WARNING" in line: + log_counts.update({"WARNING": log_counts["WARNING"] + 1}) + elif "ERROR" in line: + log_counts.update({"ERROR": log_counts["ERROR"] + 1}) + else: + pass + + return log_counts +lines = read_logs() +counts = analyze(lines) + + +print("log counts are: ", counts) + + +import json + +with open('log_counts.json', 'w') as json_file: + json.dump(counts, json_file, indent=4) + +print("log counts saved to log_counts.json") \ No newline at end of file diff --git a/day-08/mypractice/log_counts.json b/day-08/mypractice/log_counts.json new file mode 100644 index 00000000..c3b72e95 --- /dev/null +++ b/day-08/mypractice/log_counts.json @@ -0,0 +1,5 @@ +{ + "INFO": 10, + "WARNING": 2, + "ERROR": 3 +} \ No newline at end of file From 7f950a77d061962dfb51eb2c298d1e54df4cf01f Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Mon, 6 Apr 2026 02:08:09 +0530 Subject: [PATCH 10/19] this script is updated version for previos script with class and structure where scripts will take inputs from the user which file to check for logs --- day-08/mypractice/app2.log | 62 ++++++++++++++++++ day-08/mypractice/app2_counts.json | 5 ++ day-08/mypractice/app_counts.json | 5 ++ .../log_anylyzerwithclass_structure.py | 65 +++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 day-08/mypractice/app2.log create mode 100644 day-08/mypractice/app2_counts.json create mode 100644 day-08/mypractice/app_counts.json create mode 100644 day-08/mypractice/log_anylyzerwithclass_structure.py diff --git a/day-08/mypractice/app2.log b/day-08/mypractice/app2.log new file mode 100644 index 00000000..a9cb0423 --- /dev/null +++ b/day-08/mypractice/app2.log @@ -0,0 +1,62 @@ +2025-01-10 09:00:01 INFO Application started successfully +2025-01-10 09:00:05 INFO Connecting to database +2025-01-10 09:00:07 INFO Database connection established + +2025-01-10 09:05:12 WARNING High memory usage detected +2025-01-10 09:05:15 INFO Memory usage back to normal + +2025-01-10 09:10:22 ERROR Failed to fetch user data +2025-01-10 09:10:25 ERROR Database timeout occurred + +2025-01-10 09:15:30 INFO Retrying database connection +2025-01-10 09:15:32 INFO Database connection successful + +2025-01-10 09:20:45 WARNING Disk usage above 75% +2025-01-10 09:20:50 INFO Disk cleanup initiated + +2025-01-10 09:25:10 ERROR Unable to write logs to disk +2025-01-10 09:25:15 INFO Log rotation completed + +2025-01-10 09:30:00 INFO Application shutdown initiated +2025-01-10 09:30:05 INFO Application stopped +2025-01-10 09:00:01 INFO Application started successfully +2025-01-10 09:00:05 INFO Connecting to database +2025-01-10 09:00:07 INFO Database connection established + +2025-01-10 09:05:12 WARNING High memory usage detected +2025-01-10 09:05:15 INFO Memory usage back to normal + +2025-01-10 09:10:22 ERROR Failed to fetch user data +2025-01-10 09:10:25 ERROR Database timeout occurred + +2025-01-10 09:15:30 INFO Retrying database connection +2025-01-10 09:15:32 INFO Database connection successful + +2025-01-10 09:20:45 WARNING Disk usage above 75% +2025-01-10 09:20:50 INFO Disk cleanup initiated + +2025-01-10 09:25:10 ERROR Unable to write logs to disk +2025-01-10 09:25:15 INFO Log rotation completed + +2025-01-10 09:30:00 INFO Application shutdown initiated +2025-01-10 09:30:05 INFO Application stopped + +2025-01-10 09:25:10 ERROR Unable to write logs to disk +2025-01-10 09:25:15 INFO Log rotation completed + +2025-01-10 09:30:00 INFO Application shutdown initiated +2025-01-10 09:30:05 INFO Application stopped + +2025-01-10 09:25:10 ERROR Unable to write logs to disk +2025-01-10 09:25:15 INFO Log rotation completed + +2025-01-10 09:30:00 INFO Application shutdown initiated +2025-01-10 09:30:05 INFO Application stopped + +2025-01-10 09:00:07 INFO Database connection established + +2025-01-10 09:05:12 WARNING High memory usage detected +2025-01-10 09:05:15 INFO Memory usage back to normal + +2025-01-10 09:10:22 ERROR Failed to fetch user data +2025-01-10 09:10:25 ERROR Database timeout occurred diff --git a/day-08/mypractice/app2_counts.json b/day-08/mypractice/app2_counts.json new file mode 100644 index 00000000..d6780966 --- /dev/null +++ b/day-08/mypractice/app2_counts.json @@ -0,0 +1,5 @@ +{ + "INFO": 28, + "WARNING": 5, + "ERROR": 10 +} \ No newline at end of file diff --git a/day-08/mypractice/app_counts.json b/day-08/mypractice/app_counts.json new file mode 100644 index 00000000..c3b72e95 --- /dev/null +++ b/day-08/mypractice/app_counts.json @@ -0,0 +1,5 @@ +{ + "INFO": 10, + "WARNING": 2, + "ERROR": 3 +} \ No newline at end of file diff --git a/day-08/mypractice/log_anylyzerwithclass_structure.py b/day-08/mypractice/log_anylyzerwithclass_structure.py new file mode 100644 index 00000000..ac38dac8 --- /dev/null +++ b/day-08/mypractice/log_anylyzerwithclass_structure.py @@ -0,0 +1,65 @@ +import json +import os + +class LogAnalyzer: + + def __init__(self, filename): + self.filename = filename + self.project_dir = os.path.dirname(os.path.abspath(__file__)) # ✅ project folder + self.filepath = os.path.join(self.project_dir, filename) + self.lines = [] + self.counts = {} + + def read_logs(self): + try: + with open(self.filepath, 'r') as file: + self.lines = file.readlines() + print(f"Successfully read: {self.filepath}") + except FileNotFoundError: + print(f"Error: '{self.filename}' not found in project folder ({self.project_dir})") + print(f"Available files: {os.listdir(self.project_dir)}") # ✅ shows what files exist + self.lines = [] + + def analyze(self): + if not self.lines: + print("No lines to analyze.") + return + + self.counts = { + "INFO": 0, + "WARNING": 0, + "ERROR": 0 + } + for line in self.lines: + if "INFO" in line: + self.counts["INFO"] += 1 + elif "WARNING" in line: + self.counts["WARNING"] += 1 + elif "ERROR" in line: + self.counts["ERROR"] += 1 + + print("Log counts are:", self.counts) + + def save_to_json(self): + if not self.counts: + print("No counts to save.") + return + + output_filename = self.filename.replace('.log', '_counts.json') + output_path = os.path.join(self.project_dir, output_filename) # ✅ saves in project folder + + with open(output_path, 'w') as json_file: + json.dump(self.counts, json_file, indent=4) + print(f"Log counts saved to: {output_path}") + + def run(self): + self.read_logs() + self.analyze() + self.save_to_json() + + +# ✅ Take user input +if __name__ == "__main__": + filename = input("Enter the log filename (e.g. app.log): ") + analyzer = LogAnalyzer(filename) + analyzer.run() \ No newline at end of file From 3b3ec7f62bab6685b55a08a9b66916b30eb9652b Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Mon, 6 Apr 2026 02:11:08 +0530 Subject: [PATCH 11/19] made some font changes --- day-08/mypractice/log_anylyzerwithclass_structure.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/day-08/mypractice/log_anylyzerwithclass_structure.py b/day-08/mypractice/log_anylyzerwithclass_structure.py index ac38dac8..1feb6a6f 100644 --- a/day-08/mypractice/log_anylyzerwithclass_structure.py +++ b/day-08/mypractice/log_anylyzerwithclass_structure.py @@ -5,7 +5,7 @@ class LogAnalyzer: def __init__(self, filename): self.filename = filename - self.project_dir = os.path.dirname(os.path.abspath(__file__)) # ✅ project folder + self.project_dir = os.path.dirname(os.path.abspath(__file__)) # project folder self.filepath = os.path.join(self.project_dir, filename) self.lines = [] self.counts = {} @@ -17,7 +17,7 @@ def read_logs(self): print(f"Successfully read: {self.filepath}") except FileNotFoundError: print(f"Error: '{self.filename}' not found in project folder ({self.project_dir})") - print(f"Available files: {os.listdir(self.project_dir)}") # ✅ shows what files exist + print(f"Available files: {os.listdir(self.project_dir)}") # shows what files exist self.lines = [] def analyze(self): @@ -46,7 +46,7 @@ def save_to_json(self): return output_filename = self.filename.replace('.log', '_counts.json') - output_path = os.path.join(self.project_dir, output_filename) # ✅ saves in project folder + output_path = os.path.join(self.project_dir, output_filename) # saves in project folder with open(output_path, 'w') as json_file: json.dump(self.counts, json_file, indent=4) @@ -58,7 +58,7 @@ def run(self): self.save_to_json() -# ✅ Take user input +# Take user input if __name__ == "__main__": filename = input("Enter the log filename (e.g. app.log): ") analyzer = LogAnalyzer(filename) From c18a7727ad3302aade37e6da46b0dac3cf02b617 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Mon, 6 Apr 2026 19:22:02 +0530 Subject: [PATCH 12/19] created simple python scripts to show list of buckets on s3 --- day-08/mypractice/aws_s3_utilities.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 day-08/mypractice/aws_s3_utilities.py diff --git a/day-08/mypractice/aws_s3_utilities.py b/day-08/mypractice/aws_s3_utilities.py new file mode 100644 index 00000000..a5aa1bf9 --- /dev/null +++ b/day-08/mypractice/aws_s3_utilities.py @@ -0,0 +1,24 @@ +import boto3 + +# tried this way also but it is taking more time to load To be frank I have wrote this code in first then get to know it is more effective +#s3 = boto3.client("s3") + +#response = s3.list_buckets() + + +#for item in response["Buckets"]: + # for key, value in item.items(): + # if key == "Name": + # print(value) + +s3 = boto3.client("s3") + + +response = s3.list_buckets() + +#print(response["Buckets"]) + +for bucket in response["Buckets"]: + print(bucket["Name"]) + + From 532e29ef1db9f7ccd79157e642b5b5be90fbb774 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Wed, 8 Apr 2026 18:22:58 +0530 Subject: [PATCH 13/19] modified the day-02 code of stock_market_api.py with try and except method --- day-03/solution.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 day-03/solution.py diff --git a/day-03/solution.py b/day-03/solution.py new file mode 100644 index 00000000..4f8a635c --- /dev/null +++ b/day-03/solution.py @@ -0,0 +1,75 @@ +import requests + +API_KEY = "DAZR72VR6C6AVTHW" +API_URL = "https://www.alphavantage.co/" + +def get_stock_market_data(symbol, is_time_series): + try: + query = f"query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={API_KEY}" + response = requests.get(url=API_URL + query, timeout=10) + response.raise_for_status() + + except requests.exceptions.ConnectionError: + print("❌ No internet connection. Please check your network.") + return + except requests.exceptions.Timeout: + print("❌ Request timed out. The server took too long to respond.") + return + except requests.exceptions.HTTPError as e: + print(f"❌ HTTP error occurred: {e}") + return + + try: + data = response.json() + + except requests.exceptions.JSONDecodeError: + print("❌ Failed to parse response. The API may have returned invalid data.") + return + + try: + # ✅ Check FIRST before doing anything else + if "Error Message" in data: + print(f"❌ Invalid stock symbol '{symbol}'. Please enter a valid symbol like IBM, GOOGL, AMZN.") + return + + if "Note" in data: + print(f"⚠️ API Limit Reached: {data['Note']}") + return + + if "Meta Data" not in data: + print("❌ Unexpected response from API. No data found.") + return + + # ✅ Only reaches here if symbol is valid + print(f"\n✅ Fetching data for: {symbol}") + + for item, value in data.items(): + if is_time_series == "yes": + print(f"\n{item}:") + print(value) + else: + if item == "Meta Data": + print(f"\n{item}:") + print(value) + + except KeyError as e: + print(f"❌ Unexpected data format. Missing key: {e}") + except Exception as e: + print(f"❌ An unexpected error occurred: {e}") + + +# --- Main Program --- +try: + symbol = input("Enter the stock symbol (IBM, GOOGL, AMZN): ").strip().upper() + if not symbol: + raise ValueError("Stock symbol cannot be empty.") + + is_time_series = input("Do you want to see the time series data? (yes/no): ").strip().lower() + if is_time_series not in ("yes", "no"): + raise ValueError("Please enter only 'yes' or 'no'.") + +except ValueError as e: + print(f"❌ Invalid input: {e}") + +else: + get_stock_market_data(symbol, is_time_series) \ No newline at end of file From d494660db7ef258d8a08da11e549bbbd590822a0 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Sat, 11 Apr 2026 02:39:59 +0530 Subject: [PATCH 14/19] day 4 ends with learning new thing where we can read the existed file and extract the output from logs and pass the output by automating creation of new file output.json --- day-04/log_analyzer.py | 17 +++++++++++++++++ day-04/output.json | 1 + 2 files changed, 18 insertions(+) create mode 100644 day-04/log_analyzer.py create mode 100644 day-04/output.json diff --git a/day-04/log_analyzer.py b/day-04/log_analyzer.py new file mode 100644 index 00000000..b15ada36 --- /dev/null +++ b/day-04/log_analyzer.py @@ -0,0 +1,17 @@ + +import json + +with open("app.log", "r") as log_file: + content = log_file.read() + + counts = { + "INFO": content.count("INFO"), + "WARNING": content.count("WARNING"), + "ERROR": content.count("ERROR"), + } + + print(counts) + + + with open("output.json", "w") as file: + json.dump(counts, file) diff --git a/day-04/output.json b/day-04/output.json new file mode 100644 index 00000000..4bcc4030 --- /dev/null +++ b/day-04/output.json @@ -0,0 +1 @@ +{"INFO": 10, "WARNING": 2, "ERROR": 3} \ No newline at end of file From ece129681006546eed66e1493b235a484a7b6aa2 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Sat, 18 Apr 2026 05:23:16 +0530 Subject: [PATCH 15/19] added the code with OOPS aprroach to increase the usability --- day-05/mysolution.py | 43 +++++++++++++++++++++++++++++++++++++++++++ day-05/output.json | 1 + 2 files changed, 44 insertions(+) create mode 100644 day-05/mysolution.py create mode 100644 day-05/output.json diff --git a/day-05/mysolution.py b/day-05/mysolution.py new file mode 100644 index 00000000..a6a68db4 --- /dev/null +++ b/day-05/mysolution.py @@ -0,0 +1,43 @@ +import json + + +class LogAnalyzer: + + # 2. The Setup Function + def __init__(self, log_path, output_path): + + self.log_path = log_path + self.output_path = output_path + self.counts = {} # An empty dictionary to hold our results later + + + def analyze(self): + + with open(self.log_path, "r") as log_file: + content = log_file.read() + + + self.counts = { + "INFO": content.count("INFO"), + "WARNING": content.count("WARNING"), + "ERROR": content.count("ERROR"), + } + + def show_results(self): + + print(self.counts) + + # 5. Action 3: Saving + def save_to_file(self): + + with open(self.output_path, "w") as file: + json.dump(self.counts, file) + + + +my_analyzer = LogAnalyzer("app.log", "output.json") + + +my_analyzer.analyze() +my_analyzer.show_results() +my_analyzer.save_to_file() \ No newline at end of file diff --git a/day-05/output.json b/day-05/output.json new file mode 100644 index 00000000..4bcc4030 --- /dev/null +++ b/day-05/output.json @@ -0,0 +1 @@ +{"INFO": 10, "WARNING": 2, "ERROR": 3} \ No newline at end of file From 3f65d76b5907db35a4b914b7964b28b3c74fcb27 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Sat, 18 Apr 2026 05:25:13 +0530 Subject: [PATCH 16/19] made some changes --- day-05/mysolution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/day-05/mysolution.py b/day-05/mysolution.py index a6a68db4..e8ea0fdb 100644 --- a/day-05/mysolution.py +++ b/day-05/mysolution.py @@ -3,7 +3,7 @@ class LogAnalyzer: - # 2. The Setup Function + def __init__(self, log_path, output_path): self.log_path = log_path @@ -27,7 +27,7 @@ def show_results(self): print(self.counts) - # 5. Action 3: Saving + def save_to_file(self): with open(self.output_path, "w") as file: From ecda4dc0c72fd37d21040f8b1f6e1cb091c96f54 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Mon, 20 Apr 2026 18:05:49 +0530 Subject: [PATCH 17/19] created new script into a **CLI (Command Line Interface) tool where user can pass the arguments --- day-06/app.log | 21 +++++++++++++ day-06/solution.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ day-06/summary.json | 3 ++ 3 files changed, 96 insertions(+) create mode 100644 day-06/app.log create mode 100644 day-06/solution.py create mode 100644 day-06/summary.json diff --git a/day-06/app.log b/day-06/app.log new file mode 100644 index 00000000..056314af --- /dev/null +++ b/day-06/app.log @@ -0,0 +1,21 @@ +2025-01-10 09:00:01 INFO Application started successfully +2025-01-10 09:00:05 INFO Connecting to database +2025-01-10 09:00:07 INFO Database connection established + +2025-01-10 09:05:12 WARNING High memory usage detected +2025-01-10 09:05:15 INFO Memory usage back to normal + +2025-01-10 09:10:22 ERROR Failed to fetch user data +2025-01-10 09:10:25 ERROR Database timeout occurred + +2025-01-10 09:15:30 INFO Retrying database connection +2025-01-10 09:15:32 INFO Database connection successful + +2025-01-10 09:20:45 WARNING Disk usage above 75% +2025-01-10 09:20:50 INFO Disk cleanup initiated + +2025-01-10 09:25:10 ERROR Unable to write logs to disk +2025-01-10 09:25:15 INFO Log rotation completed + +2025-01-10 09:30:00 INFO Application shutdown initiated +2025-01-10 09:30:05 INFO Application stopped diff --git a/day-06/solution.py b/day-06/solution.py new file mode 100644 index 00000000..b14c1b87 --- /dev/null +++ b/day-06/solution.py @@ -0,0 +1,72 @@ +import json +import argparse + + +class LogAnalyzer: + + + def __init__(self, log_path, output_path=None, level=None): + self.log_path = log_path + self.output_path = output_path + self.level = level + self.counts = {} + + def analyze(self): + """Reads the log file, handles missing files, and counts occurrences.""" + try: + with open(self.log_path, "r") as log_file: + content = log_file.read() + + + if self.level: + self.counts = {self.level: content.count(self.level)} + else: + + self.counts = { + "INFO": content.count("INFO"), + "WARNING": content.count("WARNING"), + "ERROR": content.count("ERROR"), + } + return True + + except FileNotFoundError: + + print(f"❌ Error: The file '{self.log_path}' was not found. Please check the path.") + return False + + def show_results(self): + """Prints the counts to the terminal.""" + print("\n📊 Log Analysis Summary:") + for key, value in self.counts.items(): + print(f" - {key}: {value}") + + def save_to_file(self): + """Saves the dictionary to a JSON file if an output path was provided.""" + if self.output_path: + with open(self.output_path, "w") as file: + json.dump(self.counts, file, indent=4) + print(f"\n✅ Results successfully saved to: {self.output_path}") + + +if __name__ == "__main__": + + + parser = argparse.ArgumentParser(description="A DevOps CLI tool to analyze server logs.") + + + parser.add_argument("--file", required=True, help="Path to the input log file (e.g., app.log)") + parser.add_argument("--out", required=False, help="Path to save the JSON output (e.g., summary.json)") + parser.add_argument("--level", required=False, choices=["INFO", "WARNING", "ERROR"], help="Filter by a specific log level") + + + args = parser.parse_args() + + my_analyzer = LogAnalyzer(log_path=args.file, output_path=args.out, level=args.level) + + success = my_analyzer.analyze() + + if success: + my_analyzer.show_results() + + if args.out: + my_analyzer.save_to_file() \ No newline at end of file diff --git a/day-06/summary.json b/day-06/summary.json new file mode 100644 index 00000000..018a055f --- /dev/null +++ b/day-06/summary.json @@ -0,0 +1,3 @@ +{ + "INFO": 10 +} \ No newline at end of file From bf0f3e37525030ddf10135896072d1d42a7a888b Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Fri, 24 Apr 2026 14:34:30 +0530 Subject: [PATCH 18/19] added solution.md explaining thinking and what problem it is solving --- day-02/practice/stock_market_api.py | 2 +- day-07/solution.md | 60 +++++++++++++++++++ .../log_anylyzerwithclass_structure.py | 2 +- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 day-07/solution.md diff --git a/day-02/practice/stock_market_api.py b/day-02/practice/stock_market_api.py index ac2ed527..3266a381 100644 --- a/day-02/practice/stock_market_api.py +++ b/day-02/practice/stock_market_api.py @@ -14,7 +14,7 @@ def get_stock_market_data(symbol,is_timeseries): for key, value in response.json().items(): if is_timeseries: - print(key,value) + print(key,value) else: if key == "Time Series (Daily)": continue diff --git a/day-07/solution.md b/day-07/solution.md new file mode 100644 index 00000000..320db0de --- /dev/null +++ b/day-07/solution.md @@ -0,0 +1,60 @@ +I have picked the code from day -06 where we have modify the code from day -05 + +1)Understanding what problem that script is solving + +In my previous script everything was fine but we were assigned our specific file that we have toc heck the logs from that one log file only. What if we have new log files and we have to check the logs for that then we have to manually edit the code for analyzing different log file + + +2)What is the problem? + +we were not able to automate the code for any log file because it was name specific code for app.log + +3)What input does it need? + +Here we are using the concept of argument where we are passing the argument making the script more functional + +4)What output should it give? + +It will analyze the file which we pass in argument + +________________________________________________________________________________________________________________________________________________________________________________________ + + +🎯 1. What problem am I solving? + +Here I am automating the process of reading log files instead of manually counting how many are INFO,WARNING,and ERROR messages . My scripts can do same thing in milliseconds even with passing arguments as file name + + +📥 2. What input does my script need? + +It needs command-line arguments (flags) passed directly through the terminal via argparse. + +Required Input: The path to the log file you want to read (e.g., --file app.log). + +Optional Input 1: A specific log level to filter by (e.g., --level ERROR). + +Optional Input 2: The name of a file to save the results into (e.g., --out summary.json). + +📤 3. What output should my script give? + +script provides two types of output depending on what the user asks for: + +Terminal Output (Always): A clean, easy-to-read summary printed directly to the console showing the count of each log level. + +File Output (Conditional): If the user provided the --out flag, it generates a physical .json file on the hard drive containing the dictionary of counts. + +Validation Output: If the user types a file name that doesn't exist, it outputs a friendly error message instead of crashing the program. + +⚙️ 4. What are the main steps? + +When you press "Enter" in the terminal, your code executes these exact steps in order: + +Catch the Flags (argparse): reads the terminal command, validates that the inputs are allowed, and pass them into the args object. + +Build the Machine (Initialization): The script creates the my_analyzer object from your LogAnalyzer class and feeds it the file paths from argparse. + +Read and Count (analyze): The machine safely opens the text file, scans the content, counts the requested log levels, and stores the numbers in its internal self.counts memory. + +Display (show_results): The machine prints its internal memory to the screen. + +Export (save_to_file): If an --out destination was provided, the machine formats its internal memory into JSON and saves it to the disk. diff --git a/day-08/mypractice/log_anylyzerwithclass_structure.py b/day-08/mypractice/log_anylyzerwithclass_structure.py index 1feb6a6f..f95ae7c5 100644 --- a/day-08/mypractice/log_anylyzerwithclass_structure.py +++ b/day-08/mypractice/log_anylyzerwithclass_structure.py @@ -13,7 +13,7 @@ def __init__(self, filename): def read_logs(self): try: with open(self.filepath, 'r') as file: - self.lines = file.readlines() + self.lines = file.readlines()git st print(f"Successfully read: {self.filepath}") except FileNotFoundError: print(f"Error: '{self.filename}' not found in project folder ({self.project_dir})") From 8790c9cc79d9036562e319108bcf83169593b917 Mon Sep 17 00:00:00 2001 From: 128rahulk <128rahulk@gmail.com> Date: Fri, 24 Apr 2026 14:39:25 +0530 Subject: [PATCH 19/19] starting from scratch for day -08 --- day-08/mypractice/app.log | 22 ------- day-08/mypractice/app2.log | 62 ------------------ day-08/mypractice/app2_counts.json | 5 -- day-08/mypractice/app_counts.json | 5 -- day-08/mypractice/aws_s3_utilities.py | 24 ------- day-08/mypractice/log_analyzer.py | 39 ----------- .../log_anylyzerwithclass_structure.py | 65 ------------------- day-08/mypractice/log_counts.json | 5 -- 8 files changed, 227 deletions(-) delete mode 100644 day-08/mypractice/app.log delete mode 100644 day-08/mypractice/app2.log delete mode 100644 day-08/mypractice/app2_counts.json delete mode 100644 day-08/mypractice/app_counts.json delete mode 100644 day-08/mypractice/aws_s3_utilities.py delete mode 100644 day-08/mypractice/log_analyzer.py delete mode 100644 day-08/mypractice/log_anylyzerwithclass_structure.py delete mode 100644 day-08/mypractice/log_counts.json diff --git a/day-08/mypractice/app.log b/day-08/mypractice/app.log deleted file mode 100644 index e6e8c400..00000000 --- a/day-08/mypractice/app.log +++ /dev/null @@ -1,22 +0,0 @@ -2025-01-10 09:00:01 INFO Application started successfully -2025-01-10 09:00:05 INFO Connecting to database -2025-01-10 09:00:07 INFO Database connection established - -2025-01-10 09:05:12 WARNING High memory usage detected -2025-01-10 09:05:15 INFO Memory usage back to normal - -2025-01-10 09:10:22 ERROR Failed to fetch user data -2025-01-10 09:10:25 ERROR Database timeout occurred - -2025-01-10 09:15:30 INFO Retrying database connection -2025-01-10 09:15:32 INFO Database connection successful - -2025-01-10 09:20:45 WARNING Disk usage above 75% -2025-01-10 09:20:50 INFO Disk cleanup initiated - -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed - -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped - diff --git a/day-08/mypractice/app2.log b/day-08/mypractice/app2.log deleted file mode 100644 index a9cb0423..00000000 --- a/day-08/mypractice/app2.log +++ /dev/null @@ -1,62 +0,0 @@ -2025-01-10 09:00:01 INFO Application started successfully -2025-01-10 09:00:05 INFO Connecting to database -2025-01-10 09:00:07 INFO Database connection established - -2025-01-10 09:05:12 WARNING High memory usage detected -2025-01-10 09:05:15 INFO Memory usage back to normal - -2025-01-10 09:10:22 ERROR Failed to fetch user data -2025-01-10 09:10:25 ERROR Database timeout occurred - -2025-01-10 09:15:30 INFO Retrying database connection -2025-01-10 09:15:32 INFO Database connection successful - -2025-01-10 09:20:45 WARNING Disk usage above 75% -2025-01-10 09:20:50 INFO Disk cleanup initiated - -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed - -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped -2025-01-10 09:00:01 INFO Application started successfully -2025-01-10 09:00:05 INFO Connecting to database -2025-01-10 09:00:07 INFO Database connection established - -2025-01-10 09:05:12 WARNING High memory usage detected -2025-01-10 09:05:15 INFO Memory usage back to normal - -2025-01-10 09:10:22 ERROR Failed to fetch user data -2025-01-10 09:10:25 ERROR Database timeout occurred - -2025-01-10 09:15:30 INFO Retrying database connection -2025-01-10 09:15:32 INFO Database connection successful - -2025-01-10 09:20:45 WARNING Disk usage above 75% -2025-01-10 09:20:50 INFO Disk cleanup initiated - -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed - -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped - -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed - -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped - -2025-01-10 09:25:10 ERROR Unable to write logs to disk -2025-01-10 09:25:15 INFO Log rotation completed - -2025-01-10 09:30:00 INFO Application shutdown initiated -2025-01-10 09:30:05 INFO Application stopped - -2025-01-10 09:00:07 INFO Database connection established - -2025-01-10 09:05:12 WARNING High memory usage detected -2025-01-10 09:05:15 INFO Memory usage back to normal - -2025-01-10 09:10:22 ERROR Failed to fetch user data -2025-01-10 09:10:25 ERROR Database timeout occurred diff --git a/day-08/mypractice/app2_counts.json b/day-08/mypractice/app2_counts.json deleted file mode 100644 index d6780966..00000000 --- a/day-08/mypractice/app2_counts.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "INFO": 28, - "WARNING": 5, - "ERROR": 10 -} \ No newline at end of file diff --git a/day-08/mypractice/app_counts.json b/day-08/mypractice/app_counts.json deleted file mode 100644 index c3b72e95..00000000 --- a/day-08/mypractice/app_counts.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "INFO": 10, - "WARNING": 2, - "ERROR": 3 -} \ No newline at end of file diff --git a/day-08/mypractice/aws_s3_utilities.py b/day-08/mypractice/aws_s3_utilities.py deleted file mode 100644 index a5aa1bf9..00000000 --- a/day-08/mypractice/aws_s3_utilities.py +++ /dev/null @@ -1,24 +0,0 @@ -import boto3 - -# tried this way also but it is taking more time to load To be frank I have wrote this code in first then get to know it is more effective -#s3 = boto3.client("s3") - -#response = s3.list_buckets() - - -#for item in response["Buckets"]: - # for key, value in item.items(): - # if key == "Name": - # print(value) - -s3 = boto3.client("s3") - - -response = s3.list_buckets() - -#print(response["Buckets"]) - -for bucket in response["Buckets"]: - print(bucket["Name"]) - - diff --git a/day-08/mypractice/log_analyzer.py b/day-08/mypractice/log_analyzer.py deleted file mode 100644 index e3e435b7..00000000 --- a/day-08/mypractice/log_analyzer.py +++ /dev/null @@ -1,39 +0,0 @@ - #This function will help to read the logs from the 'app.log' file and print its contents to the console. It uses a context manager (the 'with' statement) to ensure that the file is properly closed after its suite finishes, even if an error occurs. The 'r' mode is used to open the file for reading. - -def read_logs(): - lines = [] - with open('app.log', 'r') as file: - lines = file.readlines() - return lines - - -def analyze(lines): - log_counts = { - "INFO": 0, - "WARNING": 0, - "ERROR": 0 - } - for line in lines: - if "INFO" in line: - log_counts.update({"INFO": log_counts["INFO"] + 1}) - elif "WARNING" in line: - log_counts.update({"WARNING": log_counts["WARNING"] + 1}) - elif "ERROR" in line: - log_counts.update({"ERROR": log_counts["ERROR"] + 1}) - else: - pass - - return log_counts -lines = read_logs() -counts = analyze(lines) - - -print("log counts are: ", counts) - - -import json - -with open('log_counts.json', 'w') as json_file: - json.dump(counts, json_file, indent=4) - -print("log counts saved to log_counts.json") \ No newline at end of file diff --git a/day-08/mypractice/log_anylyzerwithclass_structure.py b/day-08/mypractice/log_anylyzerwithclass_structure.py deleted file mode 100644 index f95ae7c5..00000000 --- a/day-08/mypractice/log_anylyzerwithclass_structure.py +++ /dev/null @@ -1,65 +0,0 @@ -import json -import os - -class LogAnalyzer: - - def __init__(self, filename): - self.filename = filename - self.project_dir = os.path.dirname(os.path.abspath(__file__)) # project folder - self.filepath = os.path.join(self.project_dir, filename) - self.lines = [] - self.counts = {} - - def read_logs(self): - try: - with open(self.filepath, 'r') as file: - self.lines = file.readlines()git st - print(f"Successfully read: {self.filepath}") - except FileNotFoundError: - print(f"Error: '{self.filename}' not found in project folder ({self.project_dir})") - print(f"Available files: {os.listdir(self.project_dir)}") # shows what files exist - self.lines = [] - - def analyze(self): - if not self.lines: - print("No lines to analyze.") - return - - self.counts = { - "INFO": 0, - "WARNING": 0, - "ERROR": 0 - } - for line in self.lines: - if "INFO" in line: - self.counts["INFO"] += 1 - elif "WARNING" in line: - self.counts["WARNING"] += 1 - elif "ERROR" in line: - self.counts["ERROR"] += 1 - - print("Log counts are:", self.counts) - - def save_to_json(self): - if not self.counts: - print("No counts to save.") - return - - output_filename = self.filename.replace('.log', '_counts.json') - output_path = os.path.join(self.project_dir, output_filename) # saves in project folder - - with open(output_path, 'w') as json_file: - json.dump(self.counts, json_file, indent=4) - print(f"Log counts saved to: {output_path}") - - def run(self): - self.read_logs() - self.analyze() - self.save_to_json() - - -# Take user input -if __name__ == "__main__": - filename = input("Enter the log filename (e.g. app.log): ") - analyzer = LogAnalyzer(filename) - analyzer.run() \ No newline at end of file diff --git a/day-08/mypractice/log_counts.json b/day-08/mypractice/log_counts.json deleted file mode 100644 index c3b72e95..00000000 --- a/day-08/mypractice/log_counts.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "INFO": 10, - "WARNING": 2, - "ERROR": 3 -} \ No newline at end of file