diff --git a/app/main.py b/app/main.py index f20e43c..a13425f 100644 --- a/app/main.py +++ b/app/main.py @@ -5,7 +5,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys -import time,os +import time,os,random import r_kuji @@ -13,6 +13,7 @@ import r_kuji profile_dir = "/tmp/profile" username = os.environ["RAKUTENID"] password = os.environ["RAKUTENPW"] +user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57" rch_time = int(os.environ["RCH_WATCH_TIME"]) rch_num = int(os.environ["RCH_WATCH_NUM"]) target_url = "https://channel.rakuten.co.jp/" @@ -30,6 +31,7 @@ def gen_driver(): options = webdriver.ChromeOptions() options.add_argument("--window-size=1920,1080") options.add_argument("--user-data-dir=" + profile_dir ) + options.add_argument('--user-agent=' + user_agent ) driver = webdriver.Remote( command_executor="http://selenium:4444/wd/hub", @@ -101,8 +103,9 @@ def watching_rch(): element = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body'))) for i in range(0, rch_num): - # 30秒待機 - time.sleep(30) + # 30秒~150秒待機 + random_seconds = random.randint(30, 150) + time.sleep(random_seconds) print( "Rチャンネル:" + str( i + 1) + "番目のチャンネルの視聴を始めます。視聴時間は" + str(rch_time) + "秒に設定されています。") @@ -140,7 +143,9 @@ def main(): watching_rch() if __name__ == '__main__': - time.sleep(60) # selniumコンテナの起動を待つ待機 + # 60-900秒待機 (毎日同時刻にアクセスすることを回避) + random_seconds = random.randint(60, 900) + time.sleep(random_seconds) # selniumコンテナの起動を待つ待機 main() try: r_kuji.rkuji()