Skip to content

Commit

Permalink
Automated
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshiMinh committed Jun 5, 2024
1 parent b184365 commit b643ba2
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 40 deletions.
59 changes: 39 additions & 20 deletions fetchShowing.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
// Define the movie card HTML as a template
const movieCardTemplate = `
<div class="col-lg-3 col-sm-6">
<div class="card border-0" style="width: 15; margin: auto;">
<img src="MoviesShowing/Abigail.jpg" class="card-img-top" />
<div class="card-body">
<p class="card-text">Abigail</p>
<div>
<button class="btn btn-primary">Đặt vé</button>
</div>
</div>
</div>
</div>
`;
// Read the movie data from the Movies.txt file
fetch('Movies.txt')
.then(response => response.text())
.then(data => {
const movieData = [];
const lines = data.split('\n');

// Get the container element
const container = document.getElementById('showing-movies-container');
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('MoviesShowing\\')) {
const parts = line.split('\\');
const name = parts[1].replace(/.jpg/g, '');
const image = `MoviesShowing/${parts[1]}`;
movieData.push({ name, image });
}
}

// Insert the movie card template 10 times
for (let i = 0; i < 10; i++) {
container.innerHTML += movieCardTemplate;
}
// Define the movie card HTML as a template function
const movieCardTemplate = (movie) => `
<div class="col-lg-3 col-sm-6">
<div class="card border-0" style="width: 15; margin: auto;">
<img src="${movie.image}" class="card-img-top" />
<div class="card-body">
<p class="card-text">${movie.name}</p>
<div>
<button class="btn btn-primary">Đặt vé</button>
</div>
</div>
</div>
</div>
`;

// Get the container element
const container = document.getElementById('showing-movies-container');

// Generate the HTML for each movie and append it to the container
movieData.forEach(movie => {
container.innerHTML += movieCardTemplate(movie);
});
})
.catch(error => console.error('Error:', error));
59 changes: 39 additions & 20 deletions fetchUpcoming.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
// Define the upcoming movie card HTML as a template
const upcomingMovieCardTemplate = `
<div class="col-lg-3 col-sm-6">
<div class="card border-0" style="width: 15; margin: auto;">
<img src="MoviesUpcoming/Anh Hùng Bàn Phím.jpg" class="card-img-top" />
<div class="card-body">
<p class="card-text">Anh Hùng Bàn Phím</p>
<div>
<button class="btn btn-primary">Đặt vé</button>
// Read the movie data from the Movies.txt file
fetch('Movies.txt')
.then(response => response.text())
.then(data => {
const upcomingMovieData = [];
const lines = data.split('\n');

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
if (line.startsWith('MoviesUpcoming\\')) {
const parts = line.split('\\');
const name = parts[1].replace(/.jpg/g, '');
const image = `MoviesUpcoming/${parts[1]}`;
upcomingMovieData.push({ name, image });
}
}

// Define the upcoming movie card HTML as a template function
const upcomingMovieCardTemplate = (movie) => `
<div class="col-lg-3 col-sm-6">
<div class="card border-0" style="width: 15; margin: auto;">
<img src="${movie.image}" class="card-img-top" />
<div class="card-body">
<p class="card-text">${movie.name}</p>
<div>
<button class="btn btn-primary">Đặt vé</button>
</div>
</div>
</div>
</div>
</div>
</div>
`;
`;

// Get the container element
const upcomingContainer = document.getElementById('pills-sub');
// Get the container element
const upcomingContainer = document.getElementById('pills-sub');

// Get the row2 element inside the container
const row2 = upcomingContainer.querySelector('.row2');
// Get the row2 element inside the container
const row2 = upcomingContainer.querySelector('.row2');

// Insert the upcoming movie card template 10 times
for (let i = 0; i < 10; i++) {
row2.innerHTML += upcomingMovieCardTemplate;
}
// Generate the HTML for each upcoming movie and append it to the row2 element
upcomingMovieData.forEach(movie => {
row2.innerHTML += upcomingMovieCardTemplate(movie);
});
})
.catch(error => console.error('Error:', error));
31 changes: 31 additions & 0 deletions fetchmovies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Run in Node.js
const fs = require('fs');
const path = require('path');

const directoryPaths = ['MoviesShowing', 'MoviesUpcoming'];
const outputFile = 'movies.txt';

// Function to fetch JPG file names in a directory
function fetchJPGFileNames(directory) {
return fs.readdirSync(directory)
.filter(file => path.extname(file).toLowerCase() === '.jpg');
}

// Function to write file names to a text file
function writeToFile(fileNames) {
fs.writeFileSync(outputFile, fileNames.join('\n'));
}

// Main function to fetch file names from directories and write to file
function fetchAndWriteFileNames() {
let allFileNames = [];
directoryPaths.forEach(directory => {
const fileNames = fetchJPGFileNames(directory);
allFileNames = allFileNames.concat(fileNames.map(fileName => path.join(directory, fileName)));
});

writeToFile(allFileNames);
console.log(`File names written to ${outputFile}`);
}

fetchAndWriteFileNames();
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<link rel="stylesheet" href="./owlcarousel/assets/owl.theme.default.css" />
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="./owlcarousel/owl.carousel.min.js"></script>
<script src="fetchmovies.js"></script>
</head>

<body style="transition: 0.5s;">
Expand Down
42 changes: 42 additions & 0 deletions minh.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Search</title>
</head>
<body>
<h1>YouTube Search Result</h1>
<div id="result"></div>

<script>
const apiKey = 'AIzaSyBZEQlM2UNO9ni0l62DwuvQ9JVfo55Am-0'; // Replace with your YouTube Data API key
const searchQuery = 'justice league Trailer';
const maxResults = 1;
const apiUrl = `https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q=${encodeURIComponent(searchQuery)}&maxResults=${maxResults}&key=${apiKey}`;

fetch(apiUrl)
.then(response => response.json())
.then(data => {
const videos = data.items;
if (videos.length > 0) {
const firstVideo = videos[0];
const videoId = firstVideo.id.videoId;
const videoTitle = firstVideo.snippet.title;
const videoUrl = `https://www.youtube.com/watch?v=${videoId}`;

document.getElementById('result').innerHTML = `
<h2>${videoTitle}</h2>
<a href="${videoUrl}" target="_blank">${videoUrl}</a>
`;
} else {
document.getElementById('result').innerText = 'No videos found.';
}
})
.catch(error => {
console.error('Error fetching data from YouTube API:', error);
document.getElementById('result').innerText = 'Error fetching data from YouTube API.';
});
</script>
</body>
</html>
27 changes: 27 additions & 0 deletions movies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
MoviesShowing\Abigail.jpg
MoviesShowing\DUNE Phần Hai.jpg
MoviesShowing\Exhuma Quật Mộ Trùng Ma.jpg
MoviesShowing\Godzilla X Kong Đế Chế Mới.jpg
MoviesShowing\Kung Fu Panda 4.jpg
MoviesShowing\Mai.jpg
MoviesShowing\Mobile Suit Gundam SEED FREEDOM.jpg
MoviesShowing\Monkey Man.jpg
MoviesShowing\Muôn Vị Nhân Gian.jpg
MoviesShowing\Người Chết Trở Về.jpg
MoviesShowing\Quỷ Thuật.jpg
MoviesShowing\Sáng Đèn.jpg
MoviesShowing\Thanh Xuân 18x2 Lữ Trình Hướng Về Em.jpg
MoviesShowing\Điềm Báo Của Quỷ.jpg
MoviesShowing\Đền Mạng.jpg
MoviesUpcoming\Anh Hùng Bàn Phím.jpg
MoviesUpcoming\B4S – Trước Giờ “Yêu”.jpg
MoviesUpcoming\Biệt Đội Săn Ma Kỷ Nguyên Băng Giá.jpg
MoviesUpcoming\Cái Giá Của Hạnh Phúc.jpg
MoviesUpcoming\Hòa Quang Đẫm Máu.jpg
MoviesUpcoming\Mùa Hè Của Luca.jpg
MoviesUpcoming\Ngày Tàn Của Đế Quốc.jpg
MoviesUpcoming\Người Bạn Trong Tưởng Tượng.jpg
MoviesUpcoming\Quỷ Cái.jpg
MoviesUpcoming\SUGA Agust D TOUR ‘D-DAY’ THE MOVIE.jpg
MoviesUpcoming\Trò Chơi Chết Chóc.jpg
MoviesUpcoming\Đóa Hoa Mong Manh.jpg

0 comments on commit b643ba2

Please sign in to comment.