Skip to content

Commit

Permalink
Feat: 배포용 chromedriver, firebase secret json 환경변수로 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
yxhwxn committed Aug 11, 2024
1 parent 08a02f6 commit c12acb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ public void crawlYoutubeComments(String url, Long eventId, String userId, boolea
}
}

// 크롤링 코드 실행 (생략)
System.setProperty("webdriver.chrome.driver", "src/main/resources/drivers/chromedriver");
// 크롤링 코드 실행
String chromeDriverPath = System.getenv("CHROME_DRIVER_PATH");
if (chromeDriverPath != null && !chromeDriverPath.isEmpty()) {
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
} else {
throw new RuntimeException("CHROME_DRIVER_PATH 환경 변수가 설정되지 않았습니다.");
}

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
Expand All @@ -95,7 +100,7 @@ public void crawlYoutubeComments(String url, Long eventId, String userId, boolea
try {
Thread.sleep(5000); // 초기 로딩 대기

long endTime = System.currentTimeMillis() + 240000; // 스크롤 시간 조정 (필요에 따라 조정)
long endTime = System.currentTimeMillis() + 300000; // 스크롤 시간 조정 (필요에 따라 조정)
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;

while (System.currentTimeMillis() < endTime) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/cmc/suppin/fcm/config/FirebaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import javax.annotation.PostConstruct;
import java.io.FileInputStream;
import java.io.InputStream;

@Configuration
public class FirebaseConfig {

@Value("${FIREBASE_CONFIG_PATH}")
private String firebaseConfigPath;

@PostConstruct
public void init() {
try {
InputStream serviceAccount = new ClassPathResource("suppin-a5657-firebase-adminsdk.json").getInputStream();
InputStream serviceAccount = new FileInputStream(firebaseConfigPath);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.build();
Expand Down

0 comments on commit c12acb0

Please sign in to comment.