-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabOne.py
More file actions
42 lines (34 loc) · 1.3 KB
/
LabOne.py
File metadata and controls
42 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests
import os
import shutil
from datetime import datetime
if os.path.exists('Seth_Anmawen'):
try:
shutil.rmtree('Seth_Anmawen')
print(f"Directory '{'Seth_Anmawen'}' has been removed successfully.")
except Exception as e:
print(f"Error: {e}")
download_folder = 'Seth_Anmawen'
if not os.path.exists(download_folder):
os.makedirs(download_folder)
print(f"Directory: {download_folder} created.")
local_file_path = os.path.join(download_folder, "Seth_Anmawen.txt")
url = "https://raw.githubusercontent.com/sdg000/pydevops_intro_lab/main/change_me.txt"
response = requests.get(url)
if response.status_code == 200:
print(f"File successfully downloaded.")
with open(local_file_path, "wb") as file:
file.write(response.content)
print('File saved successfully.')
else:
print(f"Failed to download file. Status code: {response.status_code}")
user_input = input("Describe what you have learned so far in a sentence: ")
now = datetime.now()
current_time = now.strftime("%Y-%m-%d %H:%M:%S")
with open(local_file_path, "w") as file:
file.write(user_input + "\n")
file.write(f"Last modified on: {current_time}")
print("File successfully modified.")
with open(local_file_path, "r") as file:
print("\nYou Entered: ", end=' ')
print(file.read())