Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Day-02/examples/02-int.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
# Absolute Value
result3 = abs(-7)
print("Absolute Value:", result3)

8 changes: 8 additions & 0 deletions Day-02/examples/1_test.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions Day-04/modules_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test as test
test.test_addition()
test.test_subtraction()
12 changes: 12 additions & 0 deletions Day-04/test.py
Original file line number Diff line number Diff line change
@@ -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 )
20 changes: 20 additions & 0 deletions Day-05/command_line_args.py
Original file line number Diff line number Diff line change
@@ -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.")
30 changes: 30 additions & 0 deletions Day-08/test1.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions Day-09/test1.py
Original file line number Diff line number Diff line change
@@ -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!")
16 changes: 16 additions & 0 deletions Day-10/test1.py
Original file line number Diff line number Diff line change
@@ -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)

26 changes: 26 additions & 0 deletions Day-11/test1.py
Original file line number Diff line number Diff line change
@@ -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"])
62 changes: 62 additions & 0 deletions Day-11/test2.py
Original file line number Diff line number Diff line change
@@ -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}")

18 changes: 18 additions & 0 deletions Day-12/test1.py
Original file line number Diff line number Diff line change
@@ -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")


56 changes: 52 additions & 4 deletions simple-python-app/app.py
Original file line number Diff line number Diff line change
@@ -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'<Todo {self.title}>'

# 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/<int:todo_id>')
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/<int:todo_id>')
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)
with app.app_context():
db.create_all()
app.run(debug=True, host='0.0.0.0', port=8000)
Binary file added simple-python-app/db.sqlite
Binary file not shown.
3 changes: 2 additions & 1 deletion simple-python-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Flask==2.1.0
Flask
Flask-SQLAlchemy
Werkzeug==2.2.2
51 changes: 51 additions & 0 deletions simple-python-app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python To-Do App</title>
<style>
body { font-family: sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; background-color: #f4f4f9; }
.container { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
h1 { text-align: center; color: #333; }
form { display: flex; gap: 10px; margin-bottom: 20px; }
input[type="text"] { flex-grow: 1; padding: 10px; border: 1px solid #ddd; border-radius: 4px; }
button { padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer; }
button:hover { background-color: #218838; }
ul { list-style: none; padding: 0; }
li { background: #fff; border-bottom: 1px solid #eee; padding: 10px; display: flex; justify-content: space-between; align-items: center; }
li:last-child { border-bottom: none; }
.task-content { display: flex; align-items: center; gap: 10px; }
.done { text-decoration: line-through; color: #888; }
.actions a { text-decoration: none; margin-left: 10px; font-size: 0.9em; }
.delete-btn { color: #dc3545; }
.check-btn { color: #007bff; }
</style>
</head>
<body>
<div class="container">
<h1>My To-Do List</h1>

<form action="/add" method="POST">
<input type="text" name="title" placeholder="What needs to be done?" required>
<button type="submit">Add Task</button>
</form>

<ul>
{% for todo in todo_list %}
<li>
<div class="task-content">
<span class="{% if todo.complete %}done{% endif %}">{{ todo.title }}</span>
</div>
<div class="actions">
<a href="/update/{{ todo.id }}" class="check-btn">
{% if todo.complete %}Undo{% else %}Complete{% endif %}
</a>
<a href="/delete/{{ todo.id }}" class="delete-btn">Delete</a>
</div>
</li>
{% endfor %}
</ul>
</div>
</body>
</html>