Recherche des tweets de réponse avec l'API Tweeter
This commit is contained in:
56
app/Console/Commands/ImportUsersCommand.php
Normal file
56
app/Console/Commands/ImportUsersCommand.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Account;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class ImportUsersCommand extends Command
|
||||
{
|
||||
protected $signature = 'import:users {file}';
|
||||
protected $description = 'Import users from a text file';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$filePath = $this->argument('file');
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
$this->error("Le fichier spécifié n'existe pas.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
$file = fopen($filePath, 'r');
|
||||
|
||||
while (($line = fgets($file)) !== false) {
|
||||
$data = explode(':', trim($line));
|
||||
|
||||
if (count($data) < 5) {
|
||||
$this->error("Format incorrect dans le fichier.");
|
||||
continue;
|
||||
}
|
||||
|
||||
[$username, $password, $email, $emailPassword, $token] = $data;
|
||||
|
||||
Account::create([
|
||||
'name' => $username,
|
||||
'password' => $password,
|
||||
'rambler_email' => $email,
|
||||
'rambler_password' => $emailPassword,
|
||||
'auth_token' => $token,
|
||||
]);
|
||||
|
||||
$this->info("Utilisateur {$username} importé avec succès.");
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
|
||||
$this->info("Importation terminée.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user