-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_Automation_with_Python_Scripts.py
More file actions
106 lines (78 loc) · 2.82 KB
/
Copy pathTask_Automation_with_Python_Scripts.py
File metadata and controls
106 lines (78 loc) · 2.82 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import shutil
import re
# 🔹 Task 1: Move files
def move_files():
source = input("Enter source folder path: ")
destination = input("Enter destination folder path: ")
extension = input("Enter file extension (e.g., .jpg, .txt): ").lower()
if not os.path.exists(source):
print("❌ Source folder not found!")
return
if not os.path.exists(destination):
os.makedirs(destination)
print("📁 Destination folder created.")
count = 0
for file in os.listdir(source):
if file.lower().endswith(extension):
src_path = os.path.join(source, file)
dest_path = os.path.join(destination, file)
shutil.move(src_path, dest_path)
print(f"✅ Moved: {file}")
count += 1
print(f"📊 Total files moved: {count}")
# 🔹 Task 2: Extract emails
def extract_emails():
input_file = input("Enter input text file path: ")
output_file = input("Enter output file path: ")
if not os.path.exists(input_file):
print("❌ File not found!")
return
with open(input_file, "r") as file:
content = file.read()
emails = re.findall(r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]+", content)
with open(output_file, "w") as file:
for email in emails:
file.write(email + "\n")
print(f"📧 {len(emails)} emails extracted and saved!")
# 🔹 Task 3: Scrape website title
def scrape_website():
url = input("Enter website URL: ")
try:
response = requests.get(url)
html = response.text
title = re.search(r"<title>(.*?)</title>", html, re.IGNORECASE)
if title:
title_text = title.group(1)
print(f"🌐 Website Title: {title_text}")
save = input("Do you want to save it? (yes/no): ").lower()
if save == "yes":
with open("website_title.txt", "w") as file:
file.write(title_text)
print("✅ Saved to website_title.txt")
else:
print("❌ Title not found!")
except Exception as e:
print("❌ Error:", e)
# 🔹 Main Menu
def main():
while True:
print("\n🔧 Task Automation Menu")
print("1. Move Files")
print("2. Extract Emails")
print("3. Scrape Website Title")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
move_files()
elif choice == "2":
extract_emails()
elif choice == "3":
scrape_website()
elif choice == "4":
print("👋 Exiting program")
break
else:
print("❌ Invalid choice")
if __name__ == "__main__":
main()