Compare commits
15 commits
add-doctri
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
af9d826938 | ||
![]() |
854da4448b | ||
![]() |
8eda8a59c9 | ||
|
3cd0184e61 | ||
|
5e0dfdfbd2 | ||
|
191840d8cf | ||
|
b4636b3e08 | ||
|
2b0fbcc6d7 | ||
|
b50d0de494 | ||
|
5624f86e38 | ||
|
2c5e1cf756 | ||
|
b85a82e6d6 | ||
|
06d35d0515 | ||
|
e3cca4f40c | ||
|
c199a9fd78 |
|
@ -2,13 +2,13 @@
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"license": "proprietary",
|
"license": "proprietary",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1.3",
|
"php": "~7.1",
|
||||||
"ext-ctype": "*",
|
"ext-ctype": "*",
|
||||||
"ext-iconv": "*",
|
"ext-iconv": "*",
|
||||||
"josephlavin/tap": "^1.0",
|
"josephlavin/tap": "^1.0",
|
||||||
"jublonet/codebird-php": "^3.1",
|
"jublonet/codebird-php": "^3.1",
|
||||||
"symfony/console": "4.2.*",
|
"symfony/console": "4.2.*",
|
||||||
"symfony/dotenv": "4.2.*",
|
"symfony/dotenv": "4.3.*",
|
||||||
"symfony/flex": "^1.1",
|
"symfony/flex": "^1.1",
|
||||||
"symfony/framework-bundle": "4.2.*",
|
"symfony/framework-bundle": "4.2.*",
|
||||||
"symfony/orm-pack": "^1.0",
|
"symfony/orm-pack": "^1.0",
|
||||||
|
@ -41,8 +41,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"auto-scripts": {
|
"auto-scripts": {
|
||||||
"cache:clear": "symfony-cmd",
|
"cache:clear": "symfony-cmd"
|
||||||
"assets:install %PUBLIC_DIR%": "symfony-cmd"
|
|
||||||
},
|
},
|
||||||
"post-install-cmd": [
|
"post-install-cmd": [
|
||||||
"@auto-scripts"
|
"@auto-scripts"
|
||||||
|
|
929
composer.lock
generated
929
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,10 +4,10 @@ namespace App\Command;
|
||||||
|
|
||||||
use App\Entity\Tweet;
|
use App\Entity\Tweet;
|
||||||
use App\Service\TweetFetcher;
|
use App\Service\TweetFetcher;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
class FetchTweetsCommand extends Command
|
class FetchTweetsCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -18,32 +18,34 @@ class FetchTweetsCommand extends Command
|
||||||
*/
|
*/
|
||||||
private $tweetFetcher;
|
private $tweetFetcher;
|
||||||
|
|
||||||
/**
|
public function __construct(TweetFetcher $tweetFetcher)
|
||||||
* @var \Doctrine\ORM\EntityManagerInterface
|
|
||||||
*/
|
|
||||||
private $entityManager;
|
|
||||||
|
|
||||||
public function __construct(TweetFetcher $tweetFetcher, EntityManagerInterface $entityManager)
|
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->tweetFetcher = $tweetFetcher;
|
$this->tweetFetcher = $tweetFetcher;
|
||||||
$this->entityManager = $entityManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setDescription('Add a short description for your command')
|
->setDescription('Fetch and store any tweets to be retweeted')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$this->tweetFetcher->getTweets()->each(function (Tweet $tweet) {
|
$io = new SymfonyStyle($input, $output);
|
||||||
$this->entityManager->persist($tweet);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->entityManager->flush();
|
$io->table(
|
||||||
|
['Tweet', 'Author', 'Created', 'ID'],
|
||||||
|
$this->tweetFetcher->getTweets()->map(function (Tweet $tweet) {
|
||||||
|
return [
|
||||||
|
$tweet->getText(),
|
||||||
|
$tweet->getAuthor(),
|
||||||
|
$tweet->getCreated(),
|
||||||
|
$tweet->getId(),
|
||||||
|
];
|
||||||
|
})->all()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
use App\Model\Tweet;
|
use App\Entity\Tweet;
|
||||||
|
use App\Repository\TweetRepository;
|
||||||
use App\Service\Retweeter;
|
use App\Service\Retweeter;
|
||||||
use App\Service\TweetFetcher;
|
use App\Service\TweetFetcher;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
||||||
|
|
||||||
class RetweetTweetsCommand extends Command
|
class RetweetTweetsCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -20,25 +20,48 @@ class RetweetTweetsCommand extends Command
|
||||||
|
|
||||||
private $retweeter;
|
private $retweeter;
|
||||||
|
|
||||||
public function __construct(TweetFetcher $tweetFetcher, Retweeter $retweeter)
|
/**
|
||||||
{
|
* @var \App\Repository\TweetRepository
|
||||||
|
*/
|
||||||
|
private $tweetRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Doctrine\ORM\EntityManagerInterface
|
||||||
|
*/
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TweetFetcher $tweetFetcher,
|
||||||
|
TweetRepository $tweetRepository,
|
||||||
|
Retweeter $retweeter,
|
||||||
|
EntityManagerInterface $entityManager
|
||||||
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->tweetFetcher = $tweetFetcher;
|
$this->tweetFetcher = $tweetFetcher;
|
||||||
$this->retweeter = $retweeter;
|
$this->retweeter = $retweeter;
|
||||||
|
$this->tweetRepository = $tweetRepository;
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setDescription('Add a short description for your command')
|
->setDescription('Retweet one or more stored tweets')
|
||||||
|
->addOption('number', null, InputOption::VALUE_OPTIONAL, 'Specify how many tweets to retweet.', 1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$this->tweetFetcher->getTweets()->each(function (Tweet $tweet) {
|
$this->tweetRepository->getUntweetedTweets($input->getOption('number'))->each(function (Tweet $tweet) {
|
||||||
$this->retweeter->retweet($tweet);
|
$this->retweeter->retweet($tweet);
|
||||||
|
|
||||||
|
$tweet->setRetweeted(time());
|
||||||
|
|
||||||
|
$this->entityManager->persist($tweet);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Repository;
|
||||||
use App\Entity\Tweet;
|
use App\Entity\Tweet;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||||
|
use Tightenco\Collect\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Tweet|null find($id, $lockMode = null, $lockVersion = null)
|
* @method Tweet|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
@ -29,22 +30,19 @@ class TweetRepository extends ServiceEntityRepository
|
||||||
|
|
||||||
return collect($result)->first();
|
return collect($result)->first();
|
||||||
}
|
}
|
||||||
// /**
|
|
||||||
// * @return Tweet[] Returns an array of Tweet objects
|
|
||||||
// */
|
public function getUntweetedTweets(int $limit): Collection
|
||||||
/*
|
|
||||||
public function findByExampleField($value)
|
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('t')
|
return collect(
|
||||||
->andWhere('t.exampleField = :val')
|
$this->createQueryBuilder('t')
|
||||||
->setParameter('val', $value)
|
->where('t.retweeted is NULL')
|
||||||
->orderBy('t.id', 'ASC')
|
->orderBy('t.created', 'asc')
|
||||||
->setMaxResults(10)
|
->setMaxResults($limit)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult()
|
->getResult()
|
||||||
;
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public function findOneBySomeField($value): ?Tweet
|
public function findOneBySomeField($value): ?Tweet
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Model\Tweet;
|
use App\Entity\Tweet;
|
||||||
|
|
||||||
class Retweeter
|
class Retweeter
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Service;
|
||||||
|
|
||||||
use App\Entity\Tweet;
|
use App\Entity\Tweet;
|
||||||
use App\Repository\TweetRepository;
|
use App\Repository\TweetRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Tightenco\Collect\Support\Collection;
|
use Tightenco\Collect\Support\Collection;
|
||||||
|
|
||||||
class TweetFetcher
|
class TweetFetcher
|
||||||
|
@ -30,30 +31,36 @@ class TweetFetcher
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \App\Repository\TweetRepository
|
* @var \Doctrine\ORM\EntityManagerInterface
|
||||||
|
*/
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \App\Service\TweetRepository
|
||||||
*/
|
*/
|
||||||
private $tweetRepository;
|
private $tweetRepository;
|
||||||
|
|
||||||
public function __construct(Codebird $codebird, TweetRepository $tweetRepository)
|
public function __construct(Codebird $codebird, EntityManagerInterface $entityManager, TweetRepository $tweetRepository)
|
||||||
{
|
{
|
||||||
$this->codebird = $codebird;
|
$this->codebird = $codebird;
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
$this->tweetRepository = $tweetRepository;
|
$this->tweetRepository = $tweetRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTweets(): Collection
|
public function getTweets(): Collection
|
||||||
{
|
{
|
||||||
$latestTweet = $this->tweetRepository->findNewestTweet();
|
$params = ['q' => collect($this->params()->all())->implode(' AND ')];
|
||||||
|
if ($newestTweet = $this->tweetRepository->findNewestTweet()) {
|
||||||
|
$params['since_id'] = $newestTweet->getId();
|
||||||
|
}
|
||||||
|
|
||||||
$response = collect($this->codebird->get()->search_tweets([
|
$response = collect($this->codebird->get()->search_tweets($params));
|
||||||
'q' => collect($this->params()->all())->implode(' AND '),
|
|
||||||
'since_id' => $latestTweet ? $latestTweet->getId() : null,
|
|
||||||
]));
|
|
||||||
|
|
||||||
if ($response->get('httpstatus') != 200) {
|
if ($response->get('httpstatus') != 200) {
|
||||||
dump($response);
|
dump($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return collect($response->get('statuses'))
|
$tweets = collect($response->get('statuses'))
|
||||||
->map(function (\stdClass $status) {
|
->map(function (\stdClass $status) {
|
||||||
return tap(new Tweet(), function (Tweet $tweet) use ($status) {
|
return tap(new Tweet(), function (Tweet $tweet) use ($status) {
|
||||||
$tweet->setId($status->id);
|
$tweet->setId($status->id);
|
||||||
|
@ -64,6 +71,10 @@ class TweetFetcher
|
||||||
$this->entityManager->persist($tweet);
|
$this->entityManager->persist($tweet);
|
||||||
});
|
});
|
||||||
})->reverse();
|
})->reverse();
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return $tweets;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function params(): Collection
|
private function params(): Collection
|
||||||
|
|
|
@ -188,6 +188,9 @@
|
||||||
"ref": "5374e24d508ba8fd6ba9eb15170255fdb778316a"
|
"ref": "5374e24d508ba8fd6ba9eb15170255fdb778316a"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"symfony/stopwatch": {
|
||||||
|
"version": "v4.2.2"
|
||||||
|
},
|
||||||
"symfony/var-dumper": {
|
"symfony/var-dumper": {
|
||||||
"version": "v4.2.2"
|
"version": "v4.2.2"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue