Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmy committed Nov 4, 2023
0 parents commit 4b565ec
Show file tree
Hide file tree
Showing 27 changed files with 785 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
APP_UID=1000
APP_GID=1000

MOONBOARD_USERNAME=
MOONBOARD_PASSWORD=
16 changes: 16 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.env.example export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/CHANGELOG.md export-ignore
/docker/ export-ignore
/docker-compose.yml export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/tests/ export-ignore
/vendor-bin/ export-ignore
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: ngmy
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: https://flattr.com/@ngmy
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint

on: [push, pull_request]

jobs:
lint:

runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
php: ['8.2']

name: PHP ${{ matrix.php }}

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up PHP ${{ matrix.php }}
run: sudo update-alternatives --set php /usr/bin/php${{ matrix.php }}

- name: Update Composer to latest version
run: sudo composer self-update

- name: Validate composer.json
run: composer validate

- name: Install Composer dependencies
run: |
composer install --no-interaction
- name: Run lint
run: composer lint
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test

on: [push, pull_request]

jobs:
test:

runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
php: ['8.2']

name: PHP ${{ matrix.php }}

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up PHP ${{ matrix.php }}
run: sudo update-alternatives --set php /usr/bin/php${{ matrix.php }}

- name: Update Composer to latest version
run: sudo composer self-update

- name: Validate composer.json
run: composer validate

- name: Install Composer dependencies
run: |
composer install --no-interaction
- name: Run tests
run: |
composer test-coverage
- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: vendor-bin/php-coveralls/vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dotenv
/.env

# Composer
/composer.lock
/vendor/
/vendor-bin/**/composer.lock
/vendor-bin/**/vendor/

# Build
/build/

# PHPUnit
/.phpunit.cache/
/phpunit.xml

# PHPStan
/phpstan.neon

# PHP CS Fixer
/.php-cs-fixer.php
/.php-cs-fixer.cache
19 changes: 19 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;

$config = new PhpCsFixer\Config();

return $config->setRules([
'@PHP80Migration:risky' => true,
'@PHP81Migration' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@PHPUnit100Migration:risky' => true,
])
->setFinder($finder)
;
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release Notes

## 0.1.0 - 2023-11-04

- Initial release.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Yuta Nagamiya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# MoonBoard Web Scraper

A web scraper for MoonBoard website.

## Installation

Clone this repository and install Composer packages:

```bash
git clone https://github.com/ngmy/moonboard-web-scraper.git

cd moonboard-web-scraper

composer install --no-dev
```

Also, set your MoonBoard username and password to the `MOONBOARD_USERNAME` and `MOONBOARD_PASSWORD` environment
variables.

## Usage

### Scrape benchmarks

```bash
bin/moonboard-web-scraper scrape-benchmarks
```

## Changelog

Please see the [changelog](CHANGELOG.md).

## License

MoonBoard Web Scraper is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
33 changes: 33 additions & 0 deletions bin/moonboard-web-scraper
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';

use App\Commands\ScrapeBenchmarksCommand;
use App\Models\HoldSetups;
use App\Services\Authenticator;
use App\UseCases\ScrapeBenchmarksAction;
use Symfony\Component\Console\Application;
use Symfony\Component\Panther\Client;

$client = Client::createChromeClient(
arguments: [
'--disable-dev-shm-usage',
'--headless',
'--no-sandbox',
'--window-size=1500,1500'
],
baseUri: 'https://www.moonboard.com',
);
$application = new Application();
$application->add(new ScrapeBenchmarksCommand(
new ScrapeBenchmarksAction(
client: $client,
authenticator: new Authenticator(
username: getenv('MOONBOARD_USERNAME'),
password: getenv('MOONBOARD_PASSWORD'),
),
holdSetups: HoldSetups::all(),
),
));
$application->run();
74 changes: 74 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "ngmy/moonboard-web-scraper",
"description": "A web scraper for MoonBoard website.",
"license": "MIT",
"type": "project",
"keywords": [
"moonboard",
"scraper"
],
"authors": [
{
"name": "Yuta Nagamiya",
"email": "y.nagamiya@gmail.com"
}
],
"homepage": "https://github.com/ngmy/moonboard-web-scraper",
"require": {
"php": "^8.2",
"ext-zip": "*",
"symfony/console": "^6.3",
"symfony/panther": "^2.1"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"ergebnis/composer-normalize": "^2.39",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true,
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true
},
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"forward-command": true,
"target-directory": "vendor-bin"
}
},
"scripts": {
"fmt": [
"@php vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --allow-risky=yes"
],
"lint": [
"Composer\\Config::disableProcessTimeout",
"@php vendor/bin/phpstan clear-result-cache || exit $?",
"@php vendor/bin/phpstan analyse"
],
"test": [
"@php vendor-bin/phpunit/vendor/bin/phpunit --no-coverage"
],
"test-coverage": [
"@putenv XDEBUG_MODE=coverage",
"@php vendor-bin/phpunit/vendor/bin/phpunit"
]
}
}
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.7"

services:
app:
build:
context: ./docker/php
args:
UID: ${APP_UID}
GID: ${APP_GID}
tty: true
environment:
MOONBOARD_USERNAME: ${MOONBOARD_USERNAME}
MOONBOARD_PASSWORD: ${MOONBOARD_PASSWORD}
volumes:
- .:/var/www
working_dir: /var/www
27 changes: 27 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM php:8.2

ARG USERNAME=app
ARG GROUPNAME=app
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID $GROUPNAME \
&& useradd -m -u $UID -g $GID $USERNAME

# Add to download Composer packages from dist.
RUN apt-get update && apt-get install -y unzip

# Add to install symfony/panther.
RUN apt-get update \
&& apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip

# Add to measure code coverage.
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

RUN apt-get update \
&& apt-get install -y chromium-driver

COPY --from=composer /usr/bin/composer /usr/bin/composer
14 changes: 14 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
level: max
paths:
- .
- .php-cs-fixer.dist.php
excludePaths:
- vendor
- vendor-bin
bootstrapFiles:
- vendor-bin/php-cs-fixer/vendor/autoload.php
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false

# vim: set ft=yaml:
Loading

0 comments on commit 4b565ec

Please sign in to comment.