Compare commits

..

15 commits

Author SHA1 Message Date
dependabot-preview[bot] af9d826938 [Security] Bump symfony/cache from 4.2.1 to 4.3.5
Bumps [symfony/cache](https://github.com/symfony/cache) from 4.2.1 to 4.3.5. **This update includes security fixes.**
- [Release notes](https://github.com/symfony/cache/releases)
- [Changelog](https://github.com/symfony/cache/blob/master/CHANGELOG.md)
- [Commits](https://github.com/symfony/cache/compare/v4.2.1...v4.3.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-24 01:26:37 +01:00
dependabot-preview[bot] 854da4448b [Security] Bump symfony/http-foundation from 4.2.1 to 4.3.5
Bumps [symfony/http-foundation](https://github.com/symfony/http-foundation) from 4.2.1 to 4.3.5. **This update includes a security fix.**
- [Release notes](https://github.com/symfony/http-foundation/releases)
- [Changelog](https://github.com/symfony/http-foundation/blob/master/CHANGELOG.md)
- [Commits](https://github.com/symfony/http-foundation/compare/v4.2.1...v4.3.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-24 01:26:25 +01:00
dependabot-preview[bot] 8eda8a59c9 Bump symfony/dotenv from 4.2.1 to 4.3.5
Bumps [symfony/dotenv](https://github.com/symfony/dotenv) from 4.2.1 to 4.3.5.
- [Release notes](https://github.com/symfony/dotenv/releases)
- [Changelog](https://github.com/symfony/dotenv/blob/master/CHANGELOG.md)
- [Commits](https://github.com/symfony/dotenv/compare/v4.2.1...v4.3.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-24 01:26:00 +01:00
Oliver Davies 3cd0184e61 composer update 2019-10-24 01:21:19 +01:00
Oliver Davies 5e0dfdfbd2 Stop running assets:install 2019-01-16 12:39:34 +00:00
Oliver Davies 191840d8cf Update PHP version 2019-01-16 12:39:05 +00:00
Oliver Davies b4636b3e08 Add descriptions to commands 2019-01-16 00:19:00 +00:00
Oliver Davies 2b0fbcc6d7 Remove unused imports 2019-01-16 00:18:52 +00:00
Oliver Davies b50d0de494 Merge branch 'add-doctrine' 2019-01-16 00:11:54 +00:00
Oliver Davies 5624f86e38 Fetch untweeted tweets, store retweet time 2019-01-16 00:11:21 +00:00
Oliver Davies 2c5e1cf756 Add getUntweetedTweets method 2019-01-16 00:04:13 +00:00
Oliver Davies b85a82e6d6 Update imports 2019-01-16 00:03:44 +00:00
Oliver Davies 06d35d0515 Don't send since_id if there's no newest post 2019-01-15 23:50:11 +00:00
Oliver Davies e3cca4f40c wip 2019-01-15 23:45:45 +00:00
Oliver Davies c199a9fd78 Revert "Tidy imports"
This reverts commit 2079aaef0e.
2019-01-15 23:37:55 +00:00
8 changed files with 635 additions and 424 deletions

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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()
);
} }
} }

View file

@ -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();
} }
} }

View file

@ -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

View file

@ -2,7 +2,7 @@
namespace App\Service; namespace App\Service;
use App\Model\Tweet; use App\Entity\Tweet;
class Retweeter class Retweeter
{ {

View file

@ -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

View file

@ -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"
}, },