From 7ca45b3861e6f88fa29410346558f28157b857b6 Mon Sep 17 00:00:00 2001 From: RamanSati Date: Sat, 22 Nov 2025 19:38:32 +0000 Subject: [PATCH 1/4] python changes --- Day-02/examples/02-int.py | 1 + Day-02/examples/1_test.py | 8 ++++++++ Day-04/modules_test.py | 3 +++ Day-04/test.py | 12 ++++++++++++ Day-05/command_line_args.py | 20 ++++++++++++++++++++ 5 files changed, 44 insertions(+) create mode 100644 Day-02/examples/1_test.py create mode 100644 Day-04/modules_test.py create mode 100644 Day-04/test.py create mode 100644 Day-05/command_line_args.py diff --git a/Day-02/examples/02-int.py b/Day-02/examples/02-int.py index bd5aa178..3d311f91 100644 --- a/Day-02/examples/02-int.py +++ b/Day-02/examples/02-int.py @@ -13,3 +13,4 @@ # Absolute Value result3 = abs(-7) print("Absolute Value:", result3) + diff --git a/Day-02/examples/1_test.py b/Day-02/examples/1_test.py new file mode 100644 index 00000000..457934d4 --- /dev/null +++ b/Day-02/examples/1_test.py @@ -0,0 +1,8 @@ +arn="sdjald:kjsdfla/dsjfkhs:12345" +print(arn.split("/")[1]) +name ="raman" +print(name[2:5]) + +print(round(4.6134564)) # Rounds to the nearest integer +print(round(4.487964)) # Rounds to the nearest integer +print(pow(2, 3)) # 2 raised to the power of 3 \ No newline at end of file diff --git a/Day-04/modules_test.py b/Day-04/modules_test.py new file mode 100644 index 00000000..56d5624f --- /dev/null +++ b/Day-04/modules_test.py @@ -0,0 +1,3 @@ +import test as test +test.test_addition() +test.test_subtraction() \ No newline at end of file diff --git a/Day-04/test.py b/Day-04/test.py new file mode 100644 index 00000000..2448e65a --- /dev/null +++ b/Day-04/test.py @@ -0,0 +1,12 @@ +def test_addition(a, b): + return a + b + +def test_subtraction(a, b): + print("Testing subtraction...", a - b ) + +def test_multiplication(a, b): + print("Testing multiplication...", a * b ) + +print(test_addition(10, 5 )) +test_subtraction(50, 20 ) +test_multiplication(4, 5 ) \ No newline at end of file diff --git a/Day-05/command_line_args.py b/Day-05/command_line_args.py new file mode 100644 index 00000000..8c207b0b --- /dev/null +++ b/Day-05/command_line_args.py @@ -0,0 +1,20 @@ +import sys + +def add(num1, num2): + return num1 + num2 +def subtract(num1, num2): + return num1 - num2 +def multiply(num1, num2): + return num1 * num2 + +num1 = int(sys.argv[1]) +num2 = int(sys.argv[2]) +operation = sys.argv[3] +if operation == "add": + print(f"The addition of {num1} and {num2} is {add(num1, num2)}") +elif operation == "subtract": + print(f"The subtraction of {num1} and {num2} is {subtract(num1, num2)}") +elif operation == "multiply": + print(f"The multiplication of {num1} and {num2} is {multiply(num1, num2)}") +else: + print("Invalid operation. Please use add, subtract, or multiply.") From efcb25b25ef11a004b062ed2dc9b3dce454a48e4 Mon Sep 17 00:00:00 2001 From: RamanSati Date: Mon, 24 Nov 2025 12:16:04 +0000 Subject: [PATCH 2/4] new feature: add test1.py files for Days 08 to 11 12 --- Day-08/test1.py | 30 ++++++++++++++++++++++++++++++ Day-09/test1.py | 12 ++++++++++++ Day-10/test1.py | 16 ++++++++++++++++ Day-11/test1.py | 26 ++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 Day-08/test1.py create mode 100644 Day-09/test1.py create mode 100644 Day-10/test1.py create mode 100644 Day-11/test1.py diff --git a/Day-08/test1.py b/Day-08/test1.py new file mode 100644 index 00000000..3920f90b --- /dev/null +++ b/Day-08/test1.py @@ -0,0 +1,30 @@ +# list + +# list1 = ["raman", "sati", "kumar"] +# list2 = [1, 2, 3, 4, 5] +# combined_list = list1 + list2 +# print("Combined List:", combined_list) + + + +# s3_buckets = ["bucket1", "bucket2", "bucket3"] +# for bucket in s3_buckets: +# print(f"Creating S3 bucket: {bucket}") + + +# tuples - > list are mutable whereas tuples are immutable + +# tuple1 = ("apple", "banana", "cherry") +# # tuple1[1] = "orange" # This will raise a TypeError +# print(tuple1) + +list_example = [10, 20, 30, 40, 50] +# Accessing elements +print("Original List:", list_example) +first_element = list_example[0] +print("First Element:", first_element) + +list_example[2] = 35 + +print(first_element+ list_example[2]) +print("Modified List:", list_example) diff --git a/Day-09/test1.py b/Day-09/test1.py new file mode 100644 index 00000000..b1ec69f0 --- /dev/null +++ b/Day-09/test1.py @@ -0,0 +1,12 @@ +# for i in range(5): +# print(i+1, "iteration completed") +# print("Hello, World!") + +for i in range(1, 6): + print(f"{i} iteration completed") + if i == 3: + # break + print("This will not be printed when i is 3") + continue + + print("Hello, World!") \ No newline at end of file diff --git a/Day-10/test1.py b/Day-10/test1.py new file mode 100644 index 00000000..f1f15cd5 --- /dev/null +++ b/Day-10/test1.py @@ -0,0 +1,16 @@ +# list all the files in list of folders that user provide as input print maximimum size of it and handle exception if folder is not found + +import os +folders = input("Enter folder names separated by space: ").split() +for folder in folders: + try: + files=os.listdir(folder) + except FileNotFoundError: + print(f"Folder '{folder}' not found, please provide correct folder name.") + except PermissionError: + print(f"Permission denied to access folder '{folder}'.") + continue + print("listing given folder:", folder) + for file in files: + print(file) + diff --git a/Day-11/test1.py b/Day-11/test1.py new file mode 100644 index 00000000..9fc0650c --- /dev/null +++ b/Day-11/test1.py @@ -0,0 +1,26 @@ +# student_info = { +# "name": "Raman Sati", +# "student_id": "123456789", +# "course": "Python for DevOps", +# "date": "2024-06-15" +# } + +# print(student_info["name"]) + +# student_info = [ +# {"name": "Raman Sati", "student_id": "123456789", "course": "Python for DevOps", "date": "2024-06-15"}, +# {"name": "John Doe", "student_id": "987654321", "course": "Python for DevOps", "date": "2024-06-16"}, +# {"name": "Jane Smith", "student_id": "456789123", "course": "Python for DevOps", "date": "2024-06-17"} +# ] + +# for student in student_info: +# print(student["name"]) + +ec2_instances = [ + {"id": "i-1234567890abcdef0", "type": "t2.micro", "state": "running"}, + {"id": "i-0abcdef1234567890", "type": "t2.small", "state": "stopped"}, + {"id": "i-0fedcba9876543210", "type": "t2.medium", "state": "running"} +] + +print("EC2 Instances: of type " + ec2_instances[1]["type"]) +print("EC2 Instances: of state " + ec2_instances[1]["state"]) From 5ded7186c9fa3a6dc8a3db1dd30413915d25883f Mon Sep 17 00:00:00 2001 From: RamanSati Date: Mon, 24 Nov 2025 20:13:56 +0000 Subject: [PATCH 3/4] github pull request count --- Day-11/test2.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Day-11/test2.py diff --git a/Day-11/test2.py b/Day-11/test2.py new file mode 100644 index 00000000..843a35ca --- /dev/null +++ b/Day-11/test2.py @@ -0,0 +1,62 @@ +# # github pull request information on a repo + +# import requests + +# response = requests.get("https://api.github.com/repos/kubernetes/kubernetes/pulls") + +# # URL to fetch pull requests from the GitHub API + +# # print(response.json()) + +# # for pr in response.json(): +# # print(pr['user']['login']) + +# # to print the first user and their login name + +# details = response.json() + +# print(details[0]['user']['id']) + +# for element in range(len(details)): +# print(details[element]['user']['login']) +# print(details[element]['user']['id']) +# print(details[element]['user']['html_url']) +# print("-----") +# # Make a GET request to fetch pull requests data from the GitHub API + +# Program to demonstrate integration with GitHub to fetch the +# details of Users who created Pull requests(Active) on Kubernetes Github repo. + + +import requests + +# URL to fetch pull requests from the GitHub API +url = f'https://api.github.com/repos/kubernetes/kubernetes/pulls' + +# Make a GET request to fetch pull requests data from the GitHub API + +response = requests.get(url) # Add headers=headers inside get() for authentication + +# Only if the response is successful + +if response.status_code == 200: + # Convert the JSON response to a dictionary + pull_requests = response.json() + + # Create an empty dictionary to store PR creators and their counts + pr_creators = {} + + # Iterate through each pull request and extract the creator's name + for pull in pull_requests: + creator = pull['user']['login'] + if creator in pr_creators: + pr_creators[creator] += 1 + else: + pr_creators[creator] = 1 + # Display the dictionary of PR creators and their counts + print("PR Creators and Counts:") + for creator, count in pr_creators.items(): + print(f"{creator}: {count} PR(s)") +else: + print(f"Failed to fetch data. Status code: {response.status_code}") + From 239760573743acea9ba8a652c727f965af998a13 Mon Sep 17 00:00:00 2001 From: RamanSati Date: Tue, 9 Dec 2025 16:25:44 +0000 Subject: [PATCH 4/4] python todo app --- Day-12/test1.py | 18 ++++++++ simple-python-app/app.py | 56 +++++++++++++++++++++++-- simple-python-app/db.sqlite | Bin 0 -> 8192 bytes simple-python-app/requirements.txt | 3 +- simple-python-app/templates/index.html | 51 ++++++++++++++++++++++ 5 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 Day-12/test1.py create mode 100644 simple-python-app/db.sqlite create mode 100644 simple-python-app/templates/index.html diff --git a/Day-12/test1.py b/Day-12/test1.py new file mode 100644 index 00000000..32f8f355 --- /dev/null +++ b/Day-12/test1.py @@ -0,0 +1,18 @@ +# update server conf file so when someone runs this program it updates the server conf file with max connections to 600 + +def update_server_config(file_path, key, value): + + with open(file_path, "r") as file: + lines = file.readlines() + + with open(file_path, "w") as file: + for line in lines: + if key in line: + file.write(f"{key}={value}\n") + else: + file.write(line) + + +update_server_config("server.conf", "MAX_CONNECTIONS", "600") + + \ No newline at end of file diff --git a/simple-python-app/app.py b/simple-python-app/app.py index 0c9d9e60..369bf7ff 100644 --- a/simple-python-app/app.py +++ b/simple-python-app/app.py @@ -1,10 +1,58 @@ -from flask import Flask +from flask import Flask, render_template, request, redirect, url_for +from flask_sqlalchemy import SQLAlchemy +import os app = Flask(__name__) +# Database Configuration +basedir = os.path.abspath(os.path.dirname(__file__)) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'db.sqlite') +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + +db = SQLAlchemy(app) + +# Database Model +class Todo(db.Model): + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(100)) + complete = db.Column(db.Boolean) + + def __repr__(self): + return f'' + +# App Routes @app.route('/') -def hello_world(): - return 'Hello, World!' +def index(): + # Show all todos + todo_list = Todo.query.all() + return render_template('index.html', todo_list=todo_list) + +@app.route('/add', methods=['POST']) +def add(): + # Add new todo + title = request.form.get('title') + new_todo = Todo(title=title, complete=False) + db.session.add(new_todo) + db.session.commit() + return redirect(url_for('index')) + +@app.route('/update/') +def update(todo_id): + # Toggle complete status + todo = Todo.query.filter_by(id=todo_id).first() + todo.complete = not todo.complete + db.session.commit() + return redirect(url_for('index')) + +@app.route('/delete/') +def delete(todo_id): + # Delete todo + todo = Todo.query.filter_by(id=todo_id).first() + db.session.delete(todo) + db.session.commit() + return redirect(url_for('index')) if __name__ == '__main__': - app.run(debug=True, host='0.0.0.0', port=8000) \ No newline at end of file + with app.app_context(): + db.create_all() + app.run(debug=True, host='0.0.0.0', port=8000) \ No newline at end of file diff --git a/simple-python-app/db.sqlite b/simple-python-app/db.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..1c23381ac653fbff5fddf838e6aef5f394019704 GIT binary patch literal 8192 zcmeI#L2JS=6bJAZ5sC%rF0$)8wjiST1r|$~V%BP`f(H+7?VwQUHgXa?_(AbelV;CL twdc4llQ8jrbNA_|=oZ}`^8s*c2tWV=5P$##AOHafKmY;|fWZG3_yx<+EMWiu literal 0 HcmV?d00001 diff --git a/simple-python-app/requirements.txt b/simple-python-app/requirements.txt index fdceace4..5da2550d 100644 --- a/simple-python-app/requirements.txt +++ b/simple-python-app/requirements.txt @@ -1,2 +1,3 @@ -Flask==2.1.0 +Flask +Flask-SQLAlchemy Werkzeug==2.2.2 \ No newline at end of file diff --git a/simple-python-app/templates/index.html b/simple-python-app/templates/index.html new file mode 100644 index 00000000..db0b273b --- /dev/null +++ b/simple-python-app/templates/index.html @@ -0,0 +1,51 @@ + + + + + + Python To-Do App + + + +
+

My To-Do List

+ +
+ + +
+ + +
+ +