Ajoute la configuration supplementaire pour la creation
-> Meme avec ceci, cela ne fonctionne toujours pas. -> Soit il manque tous les parametres, soit c'est le parametre en GET.
This commit is contained in:
parent
f6f4bab169
commit
fa069edee8
@ -1,3 +1,12 @@
|
|||||||
[CREDENTIALS]
|
[CREDENTIALS]
|
||||||
login=xxxxx
|
login=xxxxx
|
||||||
password=xxxxx
|
password=xxxxx
|
||||||
|
|
||||||
|
[ACCOUNT]
|
||||||
|
region=xx
|
||||||
|
department=xx
|
||||||
|
city=xxxxx
|
||||||
|
postal_code=xxxxx
|
||||||
|
address=xxxxxxxxxx
|
||||||
|
name=xxxx
|
||||||
|
phone=xxxxxxxxxx
|
@ -9,28 +9,24 @@ class Account
|
|||||||
const HOME_URL = 'https://www.leboncoin.fr/';
|
const HOME_URL = 'https://www.leboncoin.fr/';
|
||||||
const LOGIN_URL = 'https://www.leboncoin.fr/beta/ajax/popins/connexion.html';
|
const LOGIN_URL = 'https://www.leboncoin.fr/beta/ajax/popins/connexion.html';
|
||||||
const ACCOUNT_URL = 'https://compteperso.leboncoin.fr/account/index.html';
|
const ACCOUNT_URL = 'https://compteperso.leboncoin.fr/account/index.html';
|
||||||
const ADD_URL = 'https://www2.leboncoin.fr/ai/form/0';
|
const ADD_URL = 'https://www.leboncoin.fr/ai/form/0';
|
||||||
|
|
||||||
/** @var Client */
|
/** @var Client */
|
||||||
protected $client;
|
protected $client;
|
||||||
/** @var string */
|
/** @var Config */
|
||||||
protected $login;
|
protected $config;
|
||||||
/** @var string */
|
|
||||||
protected $password;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $is_connected = false;
|
protected $is_connected = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account constructor.
|
* Account constructor.
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
* @param string $login
|
* @param Config $config
|
||||||
* @param string $password
|
|
||||||
*/
|
*/
|
||||||
public function __construct(Client $client, $login, $password)
|
public function __construct(Client $client, Config $config)
|
||||||
{
|
{
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->login = $login;
|
$this->config = $config;
|
||||||
$this->password = $password;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,7 +64,7 @@ class Account
|
|||||||
if (!$this->isConnected()) {
|
if (!$this->isConnected()) {
|
||||||
$crawler = $this->client->request('GET', self::LOGIN_URL);
|
$crawler = $this->client->request('GET', self::LOGIN_URL);
|
||||||
$form = $crawler->selectButton('Se connecter')->form();
|
$form = $crawler->selectButton('Se connecter')->form();
|
||||||
$crawler = $this->client->submit($form, ['st_username' => $this->login, 'st_passwd' => $this->password]);
|
$crawler = $this->client->submit($form, ['st_username' => $this->config->login, 'st_passwd' => $this->config->password]);
|
||||||
$this->is_connected = $crawler->filter('.account_userinfo')->count() > 0;
|
$this->is_connected = $crawler->filter('.account_userinfo')->count() > 0;
|
||||||
}
|
}
|
||||||
return $this->is_connected;
|
return $this->is_connected;
|
||||||
@ -99,11 +95,27 @@ class Account
|
|||||||
|
|
||||||
public function addDeal(Deal $deal)
|
public function addDeal(Deal $deal)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
$t = date('YmdHis');
|
||||||
|
$log_folder = sprintf('%s/logs/%s', APP_DIR, $t);
|
||||||
|
mkdir($log_folder);
|
||||||
$crawler = $this->client->request('GET', self::ADD_URL);
|
$crawler = $this->client->request('GET', self::ADD_URL);
|
||||||
|
file_put_contents(sprintf('%s/add.html', $log_folder), $crawler->html());
|
||||||
$form = $crawler->selectButton('Valider')->form();
|
$form = $crawler->selectButton('Valider')->form();
|
||||||
$image0 = fopen(sprintf('%s/%s/image0.jpg', DEALS_DIR, $deal->getId()), 'rb');
|
$image0 = fopen(sprintf('%s/%s/image0.jpg', DEALS_DIR, $deal->getId()), 'r');
|
||||||
// TODO manage location
|
|
||||||
$fields = [
|
$fields = [
|
||||||
|
'check_type_diff' => 0,
|
||||||
|
'company_ad' => 0,
|
||||||
|
// TODO what are those ?
|
||||||
|
'location_p' => sprintf('%s %s', $this->config->city, $this->config->postal_code),
|
||||||
|
'zipcode' => $this->config->postal_code,
|
||||||
|
'city' => $this->config->city,
|
||||||
|
'region' => $this->config->region,
|
||||||
|
'dpt_code' => $this->config->department,
|
||||||
|
'address' => $this->config->address,
|
||||||
|
'name' => $this->config->name,
|
||||||
|
'email' => $this->config->login,
|
||||||
|
'phone' => $this->config->phone,
|
||||||
'category' => $deal->getCategory(),
|
'category' => $deal->getCategory(),
|
||||||
'type' => $deal->getType(),
|
'type' => $deal->getType(),
|
||||||
'subject' => $deal->getSubject(),
|
'subject' => $deal->getSubject(),
|
||||||
@ -113,6 +125,24 @@ class Account
|
|||||||
'no_salesmen' => 1,
|
'no_salesmen' => 1,
|
||||||
'phone_hidden' => 0,
|
'phone_hidden' => 0,
|
||||||
];
|
];
|
||||||
$crawler = $this->client->request('POST', $form->getUri(), ['Content-Type => multipart/form-data'], [], [], $fields);
|
array_walk($fields, function (&$item, $key) {
|
||||||
|
$item = [
|
||||||
|
'name' => $key,
|
||||||
|
'contents' => $item,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
var_dump($form->getUri());
|
||||||
|
// $crawler = $this->client->request('POST', $form->getUri(), ['Content-Type => multipart/form-data'], [], [], $fields);
|
||||||
|
// This one doesn't wor either -> redirect to Home
|
||||||
|
$crawler = $this->client->request('POST', $form->getUri(), ['multipart' => $fields]);
|
||||||
|
var_dump($crawler->html());
|
||||||
|
var_dump($crawler);
|
||||||
|
file_put_contents(sprintf('%s/add-1.html', $log_folder), $crawler->html());
|
||||||
|
$form = $crawler->selectButton('Valider mon annonce')->form();
|
||||||
|
// TODO accept_rule checked and valid form
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
echo $e->getTraceAsString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
44
library/Config.php
Normal file
44
library/Config.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Shikiryu\LBCReposter;
|
||||||
|
|
||||||
|
class Config
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $data = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config constructor.
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
public function __construct(array $data = [])
|
||||||
|
{
|
||||||
|
$this->parseData($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __get($name)
|
||||||
|
{
|
||||||
|
return $this->data[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
private function parseData(array $data)
|
||||||
|
{
|
||||||
|
foreach ($data as $name => $item) {
|
||||||
|
if (is_array($item)) {
|
||||||
|
$this->parseData($item);
|
||||||
|
} else {
|
||||||
|
$this->data[$name] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -347,4 +347,20 @@ class Deal
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $json path to json
|
||||||
|
*
|
||||||
|
* @return Deal
|
||||||
|
*/
|
||||||
|
public static function fromJSON($json)
|
||||||
|
{
|
||||||
|
$json = \json_decode(file_get_contents($json), true);
|
||||||
|
$deal = new self();
|
||||||
|
foreach ($json as $property => $value) {
|
||||||
|
$method = sprintf('set%s', ucfirst($property));
|
||||||
|
$deal->$method($value);
|
||||||
|
}
|
||||||
|
return $deal;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user