2024. 7. 2. 22:35ㆍprogramming
파이썬으로 작업 하기

정형화 된 html 소스를 파일로 만들기 기본 프로그램 소스
make_web_editer.py
import os
def create_folder_with_subfolders(parent_folder, subfolders):
# Create the parent folder
os.makedirs(parent_folder, exist_ok=True)
# Create each subfolder inside the parent folder
for subfolder in subfolders:
subfolder_path = os.path.join(parent_folder, subfolder)
os.makedirs(subfolder_path, exist_ok=True)
print(f'Subfolder "{subfolder}" created in "{parent_folder}".')
def create_with_file(folder_name, html_file_name, html_content):
# Path for the HTML file
html_file_path = os.path.join(folder_name, html_file_name)
# Create the HTML file with the specified content
with open(html_file_path, 'w') as file:
file.write(html_content)
print(f'Folder "{folder_name}" and file "{html_file_name}" created.')
# Example usage
folder = 'main'
folder2 = 'main\\css'
subfolders = ['js', 'css']
html_file = 'index.html'
content = '''<html lang="en"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel="stylesheet" href="./css/style.css">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"/>
<script src="http://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
</head>
<body>
<script>
$(function(){
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'horizontal',
loop: true,
autoplay: true,
delay:1000,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// And if we need scrollbar
scrollbar: {
el: '.swiper-scrollbar',
},
});
});
</script>
<header>
<div class="container">
<h1>Welcome to Our Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About Us</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</div>
</header>
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide" style="background-image:url(https://via.placeholder.com/1920x500/FFEEFF);"></div>
<div class="swiper-slide" style="background-image:url(https://via.placeholder.com/1920x500/FFEEEE);"></div>
<div class="swiper-slide" style="background-image:url(https://via.placeholder.com/1920x500/EEFFEE);"></div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
<main>
<section id="home" class="section">
<div class="container">
<h2>Home</h2>
<p>Welcome to our homepage. We are glad to have you here. Explore our site to learn more about us and what we offer.</p>
</div>
</section>
<section id="about" class="section">
<div class="container">
<h2>About Us</h2>
<p>Our company is dedicated to providing the best service possible. We have a rich history and a bright future ahead.</p>
</div>
</section>
<section id="services" class="section">
<div class="container">
<h2>Services</h2>
<p>We offer a variety of services to meet your needs. Browse our services to find out how we can help you.</p>
</div>
</section>
<section id="contact" class="section">
<div class="container">
<h2>Contact Us</h2>
<p>Feel free to reach out to us with any questions or inquiries. We are here to help.</p>
</div>
</section>
</main>
<footer>
<div class="container">
<p>© 2024 Our Website. All rights reserved.</p>
</div>
</footer></body></html>'''
html_file2 = 'style.css'
content2 = '''
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
line-height: 1.6;
}
.container {
width: 80%;
margin: auto;
overflow: hidden;
}
header {
background: #333;
color: #fff;
padding-top: 30px;
min-height: 70px;
border-bottom: #77d7c3 3px solid;
}
header a {
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header ul {
padding: 0;
list-style: none;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
float: right;
margin-top: 10px;
}
header #branding {
float: left;
}
header #branding h1 {
margin: 0;
}
.section {
padding: 20px 0;
border-bottom: #e8491d 1px solid;
}
footer {
padding: 20px 0;
background: #333;
color: #fff;
text-align: center;
}
.swiper {
width: 100%;
height:500px;
}
.swiper-slide {
width: 100%;
height:500px;
}
'''
# Example usage
create_folder_with_subfolders(folder, subfolders)
create_with_file(folder, html_file, content)
create_with_file(folder2, html_file2, content2)
소스 끝.
그냥 기본적으로 폴더 만들고 안에 html 과 css 파일 만드는 소스
자세한 설명은 생략
'programming' 카테고리의 다른 글
| 1.웹 에디터 프로그램 만들기 (0) | 2024.06.30 |
|---|