generated from dannz510/dannzheart.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_handler.py
86 lines (64 loc) · 3.49 KB
/
file_handler.py
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
import subprocess
import wmi
import os
import sys
import webbrowser
if os.path.exists('Files and Document') == False:
os.mkdir('Files and Document')
path = 'Files and Document/'
def isContain(text, list):
for word in list:
if word in text:
return True
return False
def createFile(text):
appLocation = "C:\\Users\\Roshan\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"#"C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
if isContain(text, ["ppt","power point","powerpoint"]):
file_name = "sample_file.ppt"
appLocation = "C:\\Program Files (x86)\\Microsoft Office\\Office15\\POWERPNT.exe"
elif isContain(text, ['excel','spreadsheet']):
file_name = "sample_file.xsl"
appLocation = "C:\\Program Files (x86)\\Microsoft Office\\Office15\\EXCEL.EXE"
elif isContain(text, ['word','document']):
file_name = "sample_file.docx"
appLocation = "C:\\Program Files (x86)\\Microsoft Office\\Office15\\WINWORD.EXE"
elif isContain(text, ["text","simple","normal"]): file_name = "sample_file.txt"
elif "python" in text: file_name = "sample_file.py"
elif "css" in text: file_name = "sample_file.css"
elif "javascript" in text: file_name = "sample_file.js"
elif "html" in text: file_name = "sample_file.html"
elif "c plus plus" in text or "c + +" in text: file_name = "sample_file.cpp"
elif "java" in text: file_name = "sample_file.java"
elif "json" in text: file_name = "sample_file.json"
else: return "Unable to create this type of file"
file = open(path + file_name, 'w')
file.close()
subprocess.Popen([appLocation, path + file_name])
return "File is created.\nNow you can edit this file"
def CreateHTMLProject(project_name='Sample'):
if os.path.isdir(path + project_name):
webbrowser.open(os.getcwd() + '/' + path + project_name + "\\index.html")
return 'There is a same project which is already created, look at this...'
else:
os.mkdir(path + project_name)
os.mkdir(path+project_name+ '/images')
os.mkdir(path+project_name+ '/videos')
htmlContent = '<html>\n\t<head>\n\t\t<title> ' + project_name + ' </title>\n\t\t<link rel="stylesheet" type="text/css" href="style.css">\n\t</head>\n<body>\n\t<p id="label"></p>\n\t<button id="btn" onclick="showText()"> Click Me </button>\n\t<script src="script.js"></script>\n</body>\n</html>'
htmlFile = open(path+project_name+ '/index.html', 'w')
htmlFile.write(htmlContent)
htmlFile.close()
cssContent = '* {\n\tmargin:0;\n\tpadding:0;\n}\nbody {\n\theight:100vh;\n\tdisplay:flex;\n\tjustify-content:center;\n\talign-items:center;\n}\n#btn {\n\twidth:200px;\n\tpadding: 20px 10px;\n\tborder-radius:5px;\n\tbackground-color:red;\n\tcolor:#fff;\n\toutline:none;border:none;\n}\np {\n\tfont-size:30px;\n}'
cssFile = open(path+project_name+ '/style.css', 'w')
cssFile.write(cssContent)
cssFile.close
jsContent = 'function showText() {\n\tdocument.getElementById("label").innerHTML="Successfully Created '+ project_name +' Project";\n\tdocument.getElementById("btn").style="background-color:green;"\n}'
jsFile = open(path+project_name+ '/script.js', 'w')
jsFile.write(jsContent)
jsFile.close()
appLocation = "C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
# subprocess.Popen([appLocation, path + project_name])
subprocess.Popen([appLocation, path + project_name + "/index.html"])
subprocess.Popen([appLocation, path + project_name + "/style.css"])
subprocess.Popen([appLocation, path + project_name + "/script.js"])
webbrowser.open(os.getcwd() + '/' + path + project_name + "\\index.html")
return f'Successfully Created {project_name} Project'