nakas commited on
Commit
9fa1e15
·
verified ·
1 Parent(s): c218a7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -4,6 +4,27 @@ import pandas as pd
4
  import time
5
  import json
6
  from datetime import datetime
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  def scrape_weather_data(site_id="YCTIM", hours=720):
9
  """
@@ -18,8 +39,11 @@ def scrape_weather_data(site_id="YCTIM", hours=720):
18
 
19
  try:
20
  with sync_playwright() as p:
21
- # Launch browser in headless mode
22
- browser = p.chromium.launch(headless=True)
 
 
 
23
  context = browser.new_context(
24
  user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
25
  )
 
4
  import time
5
  import json
6
  from datetime import datetime
7
+ import subprocess
8
+ import sys
9
+ import os
10
+
11
+ # Install Playwright browsers if they don't exist
12
+ def install_playwright_browsers():
13
+ try:
14
+ if not os.path.exists('/home/user/.cache/ms-playwright'):
15
+ print("Installing Playwright browsers...")
16
+ subprocess.run(
17
+ [sys.executable, "-m", "playwright", "install", "chromium"],
18
+ check=True,
19
+ capture_output=True,
20
+ text=True
21
+ )
22
+ print("Playwright browsers installed successfully")
23
+ except Exception as e:
24
+ print(f"Error installing browsers: {e}")
25
+
26
+ # Install browsers when the module loads
27
+ install_playwright_browsers()
28
 
29
  def scrape_weather_data(site_id="YCTIM", hours=720):
30
  """
 
39
 
40
  try:
41
  with sync_playwright() as p:
42
+ # Launch browser in headless mode with reduced arguments for compatibility
43
+ browser = p.chromium.launch(
44
+ headless=True,
45
+ args=['--no-sandbox', '--disable-dev-shm-usage']
46
+ )
47
  context = browser.new_context(
48
  user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
49
  )