Skip to content

vanvt91/daily-weather

Repository files navigation

AccuWeather Daily Forecast Scraper

Playwright + TypeScript automation that scrapes daily forecast data from AccuWeather, validates temperature conversion, and exports reports.

What This Project Does

  1. Open https://www.accuweather.com
  2. Navigate to the configured city daily forecast page
  3. Scrape all available day cards (typically up to 15)
  4. For each day, extract Day/Night detail data
  5. Enrich humidity from the hourly forecast page
  6. Validate Fahrenheit/Celsius conversion
  7. Save final report as JSON and HTML

Current Project Structure

daily-weather-report-main/
├── playwright.config.ts
├── package.json
├── tsconfig.json
├── .env.example
├── src/
│   ├── config/
│   │   └── config.ts
│   ├── pages/
│   │   ├── BasePage.ts
│   │   ├── HomePage.ts
│   │   ├── DailyForecastPage.ts
│   │   ├── DayDetailPage.ts
│   │   └── HourlyForecastPage.ts
│   ├── types/
│   │   └── weather.ts
│   └── utils/
│       ├── temperatureConverter.ts
│       ├── reportHelpers.ts
│       ├── fileReporter.ts
│       └── logger.ts
├── tests/
│   └── weather/
│       └── daily-weather.spec.ts
├── reports/
└── scripts/
    ├── run-hourly.sh
    └── com.weather.scraper.plist

Test Design (Current)

The spec runs in serial mode and has 2 tests:

  • Scrape all days and validate weather data
  • Save reports in JSON and HTML formats

Selector Strategy

Page objects use layered selector fallback in priority order:

  1. data-qa selectors
  2. semantic class/structure selectors
  3. text-based selectors (last fallback)

This helps reduce flaky scraping when AccuWeather changes markup.

Configuration

Set values in .env (copy from .env.example):

  • CITY_NAME
  • CITY_LOCATION_ID
  • CITY_COUNTRY
  • CITY_SLUG
  • HEADLESS
  • TIMEZONE
  • REPORT_OUTPUT_DIR
  • SCRAPE_DELAY_MS

Example:

CITY_NAME=Ho Chi Minh City
CITY_LOCATION_ID=353981
CITY_COUNTRY=vn
CITY_SLUG=ho-chi-minh-city
HEADLESS=true
REPORT_OUTPUT_DIR=reports

Run

npm install
npx playwright install
npm run run:weather

Useful commands:

npm run test:headed
npm run test:debug
npm run test:report

Output

Each run writes files to reports/:

  • weather_*.json (full report payload)
  • weather_report_*.html (readable report page)

Notes

  • Uses system Chrome (channel: 'chrome') to improve stability against site anti-bot checks.
  • scripts/com.weather.scraper.plist is for macOS LaunchAgent scheduling.
  • scripts/run-hourly.sh is a shell scheduler helper (macOS/Linux style).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors