diff --git a/day-01/functions_test.py b/day-01/functions_test.py new file mode 100644 index 00000000..f2879ae3 --- /dev/null +++ b/day-01/functions_test.py @@ -0,0 +1,59 @@ +import psutil +# cpu usage check karne ke liye psutil library ka use karte hai, isko install karne ke liye pip install psutil command ka use karte hai + + +# Function = "Kamm karna" + +# def sum_of_two_numbers(): + +# num1 = int(input("Enter the first number :")) +# num2 = int(input("Enter the second number :")) +# sum = num1+num2 +# print(sum) +# sum_of_two_numbers() + + + +# env = input("Enter the environment : ") +# if env == "Dev": +# print("Not correct env") +# elif env == "Prod": +# def sum_of_two_numbers(): + +# num1 = int(input("Enter the first number :")) +# num2 = int(input("Enter the second number :")) +# sum = num1+num2 +# print(sum) +# sum_of_two_numbers() +# else: +# print("Please enter correct env") + + +# env = input("Enter the environment : ") +# if env == "Dev": +# print("Not correct env") +# elif env == "Prod": +# sum_of_two_numbers() +# else: +# print("Please enter correct env") + + + +# cpu_usage = int(input("Enter the CPU usage : ")) +# def check_cpu_usage(): +# cpu_usage = int(input("Enter the CPU usage : ")) +# if cpu_usage >= 80: +# print("Send them an email") +# else: +# print("CPU usage is normal") +# check_cpu_usage() + +def check_cpu_usage(): + cpu_threshold = int(input("Enter the CPU threshold : ")) + current_cpu_usage = psutil.cpu_percent(interval=1) # interval = 1 means it will check the CPU usage for 1 second + print("Current CPU usage is : ", current_cpu_usage) + if current_cpu_usage > cpu_threshold: + print("Send them an email") + else: + print("CPU usage is normal") +check_cpu_usage() \ No newline at end of file diff --git a/day-02/api_data_fetcher.py b/day-02/api_data_fetcher.py new file mode 100644 index 00000000..eb67966f --- /dev/null +++ b/day-02/api_data_fetcher.py @@ -0,0 +1,22 @@ +import requests +import json + + +api_url = "https://official-joke-api.appspot.com/random_joke" + +def get_jokes(): + response = requests.get(url=api_url) + print(response.json()) + # final = json.loads(response.text) + # print(final) + # new_final = json.dumps(final) + with open ("jokes.json" , "w") as json_file: + json_file.write(response.text) + print("data written to json file successfully") + for key,value in response.json().items(): + setup = response.json()["setup"] + punchline = response.json()["punchline"] + return setup, punchline +setup, punchline = get_jokes() +print(setup) +print(punchline) \ No newline at end of file diff --git a/day-02/jokes.json b/day-02/jokes.json new file mode 100644 index 00000000..cd14195b --- /dev/null +++ b/day-02/jokes.json @@ -0,0 +1 @@ +{"type":"general","setup":"Did you hear the story about the cheese that saved the world?","punchline":"It was legend dairy.","id":65} \ No newline at end of file