Browse Source

adding

master
Björn 3 years ago
parent
commit
e7f21824f0
37 changed files with 3493 additions and 680 deletions
  1. +0
    -0
      .editorconfig
  2. +1
    -0
      .env.example
  3. +0
    -0
      .gitattributes
  4. +2
    -0
      .gitignore
  5. +36
    -1
      README.md
  6. +0
    -0
      app/Commands/.gitkeep
  7. +67
    -0
      app/Commands/CrawlerRunCommand.php
  8. +37
    -0
      app/Commands/SettingsMenuCommand.php
  9. +13
    -0
      app/Handlers/Action/ActionInterface.php
  10. +11
    -0
      app/Handlers/Action/MediaMove.php
  11. +28
    -0
      app/Handlers/Response/ResponseHandler.php
  12. +14
    -0
      app/Handlers/Response/ResponseHandlerInterface.php
  13. +46
    -0
      app/Handlers/Response/Rss.php
  14. +0
    -0
      app/Models/Action.php
  15. +0
    -0
      app/Models/Log.php
  16. +13
    -0
      app/Models/Source.php
  17. +0
    -0
      app/Providers/AppServiceProvider.php
  18. +0
    -0
      bootstrap/app.php
  19. +0
    -0
      box.json
  20. +12
    -8
      composer.json
  21. +2826
    -589
      composer.lock
  22. +1
    -1
      config/app.php
  23. +0
    -0
      config/commands.php
  24. +147
    -0
      config/database.php
  25. +100
    -0
      config/logging.php
  26. +0
    -37
      crawler/README.md
  27. +0
    -44
      crawler/app/Commands/InspiringCommand.php
  28. +37
    -0
      database/migrations/2021_05_09_063140_create_sources_table.php
  29. +45
    -0
      database/migrations/2021_05_09_073140_create_actions_table.php
  30. +41
    -0
      database/migrations/2021_05_09_073140_create_logs_table.php
  31. +16
    -0
      database/seeds/DatabaseSeeder.php
  32. +0
    -0
      phpunit.xml.dist
  33. +0
    -0
      super-hog
  34. +0
    -0
      tests/CreatesApplication.php
  35. +0
    -0
      tests/Feature/InspiringCommandTest.php
  36. +0
    -0
      tests/TestCase.php
  37. +0
    -0
      tests/Unit/ExampleTest.php

crawler/.editorconfig → .editorconfig View File


+ 1
- 0
.env.example View File

@ -0,0 +1 @@
CONSUMER_KEY=

crawler/.gitattributes → .gitattributes View File


crawler/.gitignore → .gitignore View File

@ -3,3 +3,5 @@
/.vscode /.vscode
/.vagrant /.vagrant
.phpunit.result.cache .phpunit.result.cache
.env
/database/database.sqlite

+ 36
- 1
README.md View File

@ -1,2 +1,37 @@
# Super Hog
<p align="center">
<img title="Laravel Zero" height="100" src="https://raw.githubusercontent.com/laravel-zero/docs/master/images/logo/laravel-zero-readme.png" />
</p>
<p align="center">
<a href="https://github.com/laravel-zero/framework/actions"><img src="https://img.shields.io/github/workflow/status/laravel-zero/framework/Continuous%20Integration.svg" alt="Build Status"></img></a>
<a href="https://scrutinizer-ci.com/g/laravel-zero/framework"><img src="https://img.shields.io/scrutinizer/g/laravel-zero/framework.svg" alt="Quality Score"></img></a>
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/license.svg" alt="License"></a>
</p>
<h4> <center>This is a <bold>community project</bold> and not an official Laravel one </center></h4>
Laravel Zero was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a micro-framework that provides an elegant starting point for your console application. It is an **unofficial** and customized version of Laravel optimized for building command-line applications.
- Built on top of the [Laravel](https://laravel.com) components.
- Optional installation of Laravel [Eloquent](https://laravel-zero.com/docs/database/), Laravel [Logging](https://laravel-zero.com/docs/logging/) and many others.
- Supports interactive [menus](https://laravel-zero.com/docs/build-interactive-menus/) and [desktop notifications](https://laravel-zero.com/docs/send-desktop-notifications/) on Linux, Windows & MacOS.
- Ships with a [Scheduler](https://laravel-zero.com/docs/task-scheduling/) and a [Standalone Compiler](https://laravel-zero.com/docs/build-a-standalone-application/).
- Integration with [Collision](https://github.com/nunomaduro/collision) - Beautiful error reporting
------
## Documentation
For full documentation, visit [laravel-zero.com](https://laravel-zero.com/).
## Support the development
**Do you like this project? Support it by donating**
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)
- Patreon: [Donate](https://www.patreon.com/nunomaduro)
## License
Laravel Zero is an open-source software licensed under the [MIT license](https://github.com/laravel-zero/laravel-zero/blob/stable/LICENSE.md).

crawler/app/Commands/.gitkeep → app/Commands/.gitkeep View File


+ 67
- 0
app/Commands/CrawlerRunCommand.php View File

@ -0,0 +1,67 @@
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use Illuminate\Support\Facades\Http;
use SimpleXMLElement;
class CrawlerRunCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'crawler:run';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$sources = [
'https://steadyhq.com/rss/krautreporter?auth=f7da00aa-fd3f-4411-a16f-138a1ce88dcc',
'https://steadyhq.com/rss/insertmoin?auth=d37bffc9-9a84-4eed-95f6-3b6cb77c2406'
];
$handler = new RssHandler();
$response = $handler->get($url);
// if it is a 200
if ($response->ok()) {
$handler->run($response, $actions);
// if there is an error on the source
} else if ($response->serverError()) {
}
}
private function get($url, $handler)
{
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*
*/
public function schedule(Schedule $schedule): void
{
$schedule->command(static::class)->everyMinute();
}
}

+ 37
- 0
app/Commands/SettingsMenuCommand.php View File

@ -0,0 +1,37 @@
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
class SettingsMenuCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'settings:menu';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$option = $this->menu('Settings', [
'Freshly baked muffins',
'Freshly baked croissants',
'Turnovers, crumb cake, cinnamon buns, scones',
])->open();
}
}

+ 13
- 0
app/Handlers/Action/ActionInterface.php View File

@ -0,0 +1,13 @@
<?php
use App\Action;
/**
*
*
*/
interface ActionInterface
{
public function config();
public function run();
}

+ 11
- 0
app/Handlers/Action/MediaMove.php View File

@ -0,0 +1,11 @@
<?php
/**
*
*
*
*/
class FileMoveActionHandler extends ActionHandler {
}

+ 28
- 0
app/Handlers/Response/ResponseHandler.php View File

@ -0,0 +1,28 @@
<?php
namespace App\ResponseHandler;
/**
*
*
*
*/
class RssResponseHandler extends ResponseHandler implements ResponseHandlerInterface
{
protected $response;
protected $source;
protected $actions;
protected $beforeActions;
protected $afterActions;
/**
*
* @param [type] $actions
*
*/
public function __construct($source)
{
$this->source = $source;
}
}

+ 14
- 0
app/Handlers/Response/ResponseHandlerInterface.php View File

@ -0,0 +1,14 @@
<?php
namespace App\ResponseHandler;
/**
*
*
*
*/
interface RssResponseInterface
{
public function get();
public function handle();
}

+ 46
- 0
app/Handlers/Response/Rss.php View File

@ -0,0 +1,46 @@
<?php
namespace App\ResponseHandler;
/**
* Handle Response of a Rss Feed,
* response will parsed to SimpleXMLElement
* each item in a channel will be run through actions
*
*
*/
class Rss extends ResponseHandler
{
/**
* getting data from
*
*
* @return object
*
*/
public function get()
{
$this->response = Http::withHeaders([
"Content-Type" => "text/xml;charset=utf-8"
])->get($this->source->url);
return $this->response;
}
/**
* handle response
*
*
*
*/
public function handle()
{
$xml = new SimpleXMLElement($this->response->body());
foreach($xml->channel->item as $item) {
foreach($this->actions as $action) {
$action->handle($item);
}
}
}
}

+ 0
- 0
app/Models/Action.php View File


+ 0
- 0
app/Models/Log.php View File


+ 13
- 0
app/Models/Source.php View File

@ -0,0 +1,13 @@
<?php
/**
*
*
*
*
*/
class Source
{
}

crawler/app/Providers/AppServiceProvider.php → app/Providers/AppServiceProvider.php View File


crawler/bootstrap/app.php → bootstrap/app.php View File


crawler/box.json → box.json View File


crawler/composer.json → composer.json View File

@ -17,9 +17,15 @@
], ],
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"laravel-zero/framework": "^7.0"
"guzzlehttp/guzzle": "^6.3.1",
"illuminate/database": "^7.0",
"illuminate/http": "^7.0",
"illuminate/log": "^7.0",
"laravel-zero/framework": "^7.0",
"nunomaduro/laravel-console-menu": "^3.0"
}, },
"require-dev": { "require-dev": {
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.3.1", "mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.5" "phpunit/phpunit": "^8.5"
}, },
@ -36,14 +42,12 @@
"config": { "config": {
"preferred-install": "dist", "preferred-install": "dist",
"sort-packages": true, "sort-packages": true,
"optimize-autoloader": true
},
"scripts": {
"post-create-project-cmd": [
"@php application app:rename"
]
"optimize-autoloader": true,
"platform": {
"php": "7.4.18"
}
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"prefer-stable": true, "prefer-stable": true,
"bin": ["application"]
"bin": ["super-hog"]
} }

composer.lock
File diff suppressed because it is too large
View File


crawler/config/app.php → config/app.php View File

@ -13,7 +13,7 @@ return [
| |
*/ */
'name' => 'Application',
'name' => 'Super-hog',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

crawler/config/commands.php → config/commands.php View File


+ 147
- 0
config/database.php View File

@ -0,0 +1,147 @@
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'sqlite'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer body of commands than a typical key-value system
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
],
'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
],
'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '1'),
],
],
];

+ 100
- 0
config/logging.php View File

@ -0,0 +1,100 @@
<?php
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['stderr'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],
],
];

+ 0
- 37
crawler/README.md View File

@ -1,37 +0,0 @@
<p align="center">
<img title="Laravel Zero" height="100" src="https://raw.githubusercontent.com/laravel-zero/docs/master/images/logo/laravel-zero-readme.png" />
</p>
<p align="center">
<a href="https://github.com/laravel-zero/framework/actions"><img src="https://img.shields.io/github/workflow/status/laravel-zero/framework/Continuous%20Integration.svg" alt="Build Status"></img></a>
<a href="https://scrutinizer-ci.com/g/laravel-zero/framework"><img src="https://img.shields.io/scrutinizer/g/laravel-zero/framework.svg" alt="Quality Score"></img></a>
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel-zero/framework"><img src="https://poser.pugx.org/laravel-zero/framework/license.svg" alt="License"></a>
</p>
<h4> <center>This is a <bold>community project</bold> and not an official Laravel one </center></h4>
Laravel Zero was created by, and is maintained by [Nuno Maduro](https://github.com/nunomaduro), and is a micro-framework that provides an elegant starting point for your console application. It is an **unofficial** and customized version of Laravel optimized for building command-line applications.
- Built on top of the [Laravel](https://laravel.com) components.
- Optional installation of Laravel [Eloquent](https://laravel-zero.com/docs/database/), Laravel [Logging](https://laravel-zero.com/docs/logging/) and many others.
- Supports interactive [menus](https://laravel-zero.com/docs/build-interactive-menus/) and [desktop notifications](https://laravel-zero.com/docs/send-desktop-notifications/) on Linux, Windows & MacOS.
- Ships with a [Scheduler](https://laravel-zero.com/docs/task-scheduling/) and a [Standalone Compiler](https://laravel-zero.com/docs/build-a-standalone-application/).
- Integration with [Collision](https://github.com/nunomaduro/collision) - Beautiful error reporting
------
## Documentation
For full documentation, visit [laravel-zero.com](https://laravel-zero.com/).
## Support the development
**Do you like this project? Support it by donating**
- PayPal: [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)
- Patreon: [Donate](https://www.patreon.com/nunomaduro)
## License
Laravel Zero is an open-source software licensed under the [MIT license](https://github.com/laravel-zero/laravel-zero/blob/stable/LICENSE.md).

+ 0
- 44
crawler/app/Commands/InspiringCommand.php View File

@ -1,44 +0,0 @@
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
class InspiringCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'inspiring {name=Artisan}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Simplicity is the ultimate sophistication.');
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function schedule(Schedule $schedule)
{
// $schedule->command(static::class)->everyMinute();
}
}

+ 37
- 0
database/migrations/2021_05_09_063140_create_sources_table.php View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSourcesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sources', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('url');
$table->string('response_handler_class');
$table->dateTime('last_run_at');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('sources');
}
}

+ 45
- 0
database/migrations/2021_05_09_073140_create_actions_table.php View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateActionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('actions', function (Blueprint $table) {
$table->id();
$table->string('action_handler_class');
$table->enum('type', [
'before', 'after'
])->nullable();
$table->integer('priority');
// sources
$table->uuid('source_id')
->nullable();
$table->foreign('source_id')
->references('id')
->on('sources');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('actions');
}
}

+ 41
- 0
database/migrations/2021_05_09_073140_create_logs_table.php View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('logs', function (Blueprint $table) {
$table->uuid();
$tabke->json('message');
$table->enum('state', [
'critical', 'solved', 'error'
]);
// sources
$table->uuid('source_id')->nullable();
$table->foreign('source_id')->references('id')->on('sources');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('logs');
}
}

+ 16
- 0
database/seeds/DatabaseSeeder.php View File

@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
}
}

crawler/phpunit.xml.dist → phpunit.xml.dist View File


crawler/application → super-hog View File


crawler/tests/CreatesApplication.php → tests/CreatesApplication.php View File


crawler/tests/Feature/InspiringCommandTest.php → tests/Feature/InspiringCommandTest.php View File


crawler/tests/TestCase.php → tests/TestCase.php View File


crawler/tests/Unit/ExampleTest.php → tests/Unit/ExampleTest.php View File


Loading…
Cancel
Save