mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
mempool weather added
This commit is contained in:
49
app/Console/Commands/MempoolSpace/CacheRecommendedFees.php
Normal file
49
app/Console/Commands/MempoolSpace/CacheRecommendedFees.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\MempoolSpace;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CacheRecommendedFees extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'mempool:recommended-fees';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$apiKey = config('services.open-ai.apiKey');
|
||||
$client = OpenAI::client($apiKey);
|
||||
|
||||
$result = Http::get('https://mempool.space/api/v1/fees/recommended');
|
||||
$result = $result->json();
|
||||
|
||||
$result = $client->completions()
|
||||
->create([
|
||||
'model' => 'text-davinci-003',
|
||||
'prompt' => sprintf('Erstelle einen Wetterbericht für den Bitcoin Mempool mit folgenden Gebühren: fastestFee: %s sat/vB, halfHourFee: %s sat/vB, hourFee: %s sat/vB, economyFee: %s sat/vB, minimumFee: %s sat/vB. Fasse mit maximal 400 Zeichen zusammen und schreibe im Stile eines Wetterberichtes aus dem Fernsehen um.',
|
||||
$result['fastestFee'],
|
||||
$result['halfHourFee'],
|
||||
$result['hourFee'],
|
||||
$result['economyFee'],
|
||||
$result['minimumFee']
|
||||
),
|
||||
'max_tokens' => 400,
|
||||
'temperature' => 1
|
||||
]);
|
||||
|
||||
cache()->put('mempool-weather', $result['choices'][0]['text'], now()->addMinutes(62));
|
||||
}
|
||||
}
|
||||
50
app/Console/Commands/Test.php
Normal file
50
app/Console/Commands/Test.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use OpenAI;
|
||||
|
||||
class Test extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'test';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$apiKey = config('services.open-ai.apiKey');
|
||||
$client = OpenAI::client($apiKey);
|
||||
|
||||
$result = Http::get('https://mempool.space/api/v1/fees/recommended');
|
||||
$result = $result->json();
|
||||
|
||||
$result = $client->completions()
|
||||
->create([
|
||||
'model' => 'text-davinci-003',
|
||||
'prompt' => sprintf('Erstelle einen Wetterbericht für den Bitcoin Mempool mit folgenden Gebühren: fastestFee: %s sat/vB, halfHourFee: %s sat/vB, hourFee: %s sat/vB, economyFee: %s sat/vB, minimumFee: %s sat/vB. Fasse mit maximal 400 Zeichen zusammen und schreibe im Stile eines Wetterberichtes aus dem Fernsehen um.',
|
||||
$result['fastestFee'],
|
||||
$result['halfHourFee'],
|
||||
$result['hourFee'],
|
||||
$result['economyFee'],
|
||||
$result['minimumFee']
|
||||
),
|
||||
'max_tokens' => 400,
|
||||
'temperature' => 1
|
||||
]);
|
||||
|
||||
cache()->put('mempool-weather', $result['choices'][0]['text'], now()->addMinutes(60));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Console;
|
||||
|
||||
use App\Console\Commands\Database\CleanupLoginKeys;
|
||||
use App\Console\Commands\Feed\ReadAndSyncPodcastFeeds;
|
||||
use App\Console\Commands\MempoolSpace\CacheRecommendedFees;
|
||||
use App\Console\Commands\Nostr\PublishUnpublishedItems;
|
||||
use App\Console\Commands\OpenBooks\SyncOpenBooks;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
@@ -22,6 +23,7 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
$schedule->command(CacheRecommendedFees::class)->hourly();
|
||||
$schedule->call(new PruneStaleAttachments)
|
||||
->daily();
|
||||
$schedule->command(SyncOpenBooks::class)
|
||||
|
||||
40
app/Http/Livewire/Banner/MempoolWeather.php
Normal file
40
app/Http/Livewire/Banner/MempoolWeather.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Banner;
|
||||
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Component;
|
||||
|
||||
class MempoolWeather extends Component
|
||||
{
|
||||
public string $weather = '';
|
||||
|
||||
public $fastestFee;
|
||||
public $halfHourFee;
|
||||
public $hourFee;
|
||||
public $economyFee;
|
||||
public $minimumFee;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if (cache()->has('mempool-weather')) {
|
||||
$this->weather = cache()->get('mempool-weather');
|
||||
} else {
|
||||
Artisan::call('test');
|
||||
$this->weather = cache()->get('mempool-weather');
|
||||
}
|
||||
$result = Http::get('https://mempool.space/api/v1/fees/recommended');
|
||||
$result = $result->json();
|
||||
$this->fastestFee = $result['fastestFee'];
|
||||
$this->halfHourFee = $result['halfHourFee'];
|
||||
$this->hourFee = $result['hourFee'];
|
||||
$this->economyFee = $result['economyFee'];
|
||||
$this->minimumFee = $result['minimumFee'];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.banner.mempool-weather');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user