File docker/application/Dockerfile changed (mode: 100644) (index 547c4df..dbb445a) |
... |
... |
MAINTAINER Ivaylo Iliev <ranapat@yahoo.com> |
6 |
6 |
# Install base packages |
# Install base packages |
7 |
7 |
RUN \ |
RUN \ |
8 |
8 |
apt-get update > /dev/null 2>&1 && \ |
apt-get update > /dev/null 2>&1 && \ |
9 |
|
apt-get install -y curl wget apt-transport-https lsb-release ca-certificates zip unzip > /dev/null 2>&1 |
|
|
9 |
|
apt-get install -y curl wget apt-transport-https lsb-release ca-certificates zip unzip git > /dev/null 2>&1 |
10 |
10 |
|
|
11 |
11 |
# Install php7.1 |
# Install php7.1 |
12 |
12 |
RUN \ |
RUN \ |
13 |
13 |
wget -nv -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg > /dev/null 2>&1 && \ |
wget -nv -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg > /dev/null 2>&1 && \ |
14 |
14 |
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list && \ |
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list && \ |
15 |
15 |
apt-get update > /dev/null 2>&1 && \ |
apt-get update > /dev/null 2>&1 && \ |
16 |
|
apt-get install -y php7.1-fpm php7.1 php7.1-xml php7.1-intl php7.1-mysql php7.1-bz2 php7.1-zip > /dev/null 2>&1 && \ |
|
|
16 |
|
apt-get install -y php7.1-fpm php7.1 php7.1-xml php7.1-intl php7.1-mysql php7.1-bz2 php7.1-zip php7.1-curl > /dev/null 2>&1 && \ |
17 |
17 |
echo "cgi.fix_pathinfo=0" >> /etc/php/7.1/fpm/php.ini |
echo "cgi.fix_pathinfo=0" >> /etc/php/7.1/fpm/php.ini |
18 |
18 |
|
|
19 |
19 |
# Install Nginx. |
# Install Nginx. |
File src/nasa/app/AppKernel.php changed (mode: 100644) (index ca20bee..e153ca8) |
... |
... |
class AppKernel extends Kernel |
16 |
16 |
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), |
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), |
17 |
17 |
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), |
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), |
18 |
18 |
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), |
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), |
|
19 |
|
new Sensio\Bundle\BuzzBundle\SensioBuzzBundle(), |
19 |
20 |
new AppBundle\AppBundle(), |
new AppBundle\AppBundle(), |
20 |
21 |
new NeoBundle\NeoBundle(), |
new NeoBundle\NeoBundle(), |
21 |
22 |
]; |
]; |
File src/nasa/composer.json changed (mode: 100644) (index 7f44038..7515c6a) |
26 |
26 |
"doctrine/doctrine-migrations-bundle": "^1.0", |
"doctrine/doctrine-migrations-bundle": "^1.0", |
27 |
27 |
"doctrine/orm": "^2.5", |
"doctrine/orm": "^2.5", |
28 |
28 |
"incenteev/composer-parameter-handler": "^2.0", |
"incenteev/composer-parameter-handler": "^2.0", |
|
29 |
|
"sensio/buzz-bundle": "dev-master", |
29 |
30 |
"sensio/distribution-bundle": "^5.0.19", |
"sensio/distribution-bundle": "^5.0.19", |
30 |
31 |
"sensio/framework-extra-bundle": "^3.0.2", |
"sensio/framework-extra-bundle": "^3.0.2", |
31 |
32 |
"symfony/monolog-bundle": "^3.1.0", |
"symfony/monolog-bundle": "^3.1.0", |
File src/nasa/composer.lock changed (mode: 100644) (index b4317d9..6c8c880) |
4 |
4 |
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
5 |
5 |
"This file is @generated automatically" |
"This file is @generated automatically" |
6 |
6 |
], |
], |
7 |
|
"content-hash": "90a153819e98ee1921583b571582c64b", |
|
|
7 |
|
"content-hash": "37b86ba9506556d12cfc9065d420e8f7", |
8 |
8 |
"packages": [ |
"packages": [ |
9 |
9 |
{ |
{ |
10 |
10 |
"name": "composer/ca-bundle", |
"name": "composer/ca-bundle", |
|
1130 |
1130 |
], |
], |
1131 |
1131 |
"time": "2014-01-12T16:20:24+00:00" |
"time": "2014-01-12T16:20:24+00:00" |
1132 |
1132 |
}, |
}, |
|
1133 |
|
{ |
|
1134 |
|
"name": "kriswallsmith/buzz", |
|
1135 |
|
"version": "v0.15.1", |
|
1136 |
|
"source": { |
|
1137 |
|
"type": "git", |
|
1138 |
|
"url": "https://github.com/kriswallsmith/Buzz.git", |
|
1139 |
|
"reference": "d59932b335c2f2f3ec9eee66a37db6bd50d39e13" |
|
1140 |
|
}, |
|
1141 |
|
"dist": { |
|
1142 |
|
"type": "zip", |
|
1143 |
|
"url": "https://api.github.com/repos/kriswallsmith/Buzz/zipball/d59932b335c2f2f3ec9eee66a37db6bd50d39e13", |
|
1144 |
|
"reference": "d59932b335c2f2f3ec9eee66a37db6bd50d39e13", |
|
1145 |
|
"shasum": "" |
|
1146 |
|
}, |
|
1147 |
|
"require": { |
|
1148 |
|
"php": "^5.3.3 || ^7.0" |
|
1149 |
|
}, |
|
1150 |
|
"require-dev": { |
|
1151 |
|
"symfony/phpunit-bridge": "^3.3" |
|
1152 |
|
}, |
|
1153 |
|
"suggest": { |
|
1154 |
|
"ext-curl": "*" |
|
1155 |
|
}, |
|
1156 |
|
"type": "library", |
|
1157 |
|
"autoload": { |
|
1158 |
|
"psr-4": { |
|
1159 |
|
"Buzz\\": "lib/Buzz" |
|
1160 |
|
} |
|
1161 |
|
}, |
|
1162 |
|
"notification-url": "https://packagist.org/downloads/", |
|
1163 |
|
"license": [ |
|
1164 |
|
"MIT" |
|
1165 |
|
], |
|
1166 |
|
"authors": [ |
|
1167 |
|
{ |
|
1168 |
|
"name": "Kris Wallsmith", |
|
1169 |
|
"email": "kris.wallsmith@gmail.com", |
|
1170 |
|
"homepage": "http://kriswallsmith.net/" |
|
1171 |
|
} |
|
1172 |
|
], |
|
1173 |
|
"description": "Lightweight HTTP client", |
|
1174 |
|
"homepage": "https://github.com/kriswallsmith/Buzz", |
|
1175 |
|
"keywords": [ |
|
1176 |
|
"curl", |
|
1177 |
|
"http client" |
|
1178 |
|
], |
|
1179 |
|
"time": "2017-08-19T09:43:47+00:00" |
|
1180 |
|
}, |
1133 |
1181 |
{ |
{ |
1134 |
1182 |
"name": "monolog/monolog", |
"name": "monolog/monolog", |
1135 |
1183 |
"version": "1.23.0", |
"version": "1.23.0", |
|
1612 |
1660 |
], |
], |
1613 |
1661 |
"time": "2017-01-02T13:31:39+00:00" |
"time": "2017-01-02T13:31:39+00:00" |
1614 |
1662 |
}, |
}, |
|
1663 |
|
{ |
|
1664 |
|
"name": "sensio/buzz-bundle", |
|
1665 |
|
"version": "dev-master", |
|
1666 |
|
"target-dir": "Sensio/Bundle/BuzzBundle", |
|
1667 |
|
"source": { |
|
1668 |
|
"type": "git", |
|
1669 |
|
"url": "https://github.com/sensiolabs/SensioBuzzBundle.git", |
|
1670 |
|
"reference": "ad7c722f755471b80f5c9c7dd703b2975f8a518b" |
|
1671 |
|
}, |
|
1672 |
|
"dist": { |
|
1673 |
|
"type": "zip", |
|
1674 |
|
"url": "https://api.github.com/repos/sensiolabs/SensioBuzzBundle/zipball/ad7c722f755471b80f5c9c7dd703b2975f8a518b", |
|
1675 |
|
"reference": "ad7c722f755471b80f5c9c7dd703b2975f8a518b", |
|
1676 |
|
"shasum": "" |
|
1677 |
|
}, |
|
1678 |
|
"require": { |
|
1679 |
|
"kriswallsmith/buzz": "> 0.6", |
|
1680 |
|
"php": ">=5.3.2" |
|
1681 |
|
}, |
|
1682 |
|
"type": "symfony-bundle", |
|
1683 |
|
"extra": { |
|
1684 |
|
"branch-alias": { |
|
1685 |
|
"dev-master": "1.1-dev" |
|
1686 |
|
} |
|
1687 |
|
}, |
|
1688 |
|
"autoload": { |
|
1689 |
|
"psr-0": { |
|
1690 |
|
"Sensio\\Bundle\\BuzzBundle": "" |
|
1691 |
|
} |
|
1692 |
|
}, |
|
1693 |
|
"notification-url": "https://packagist.org/downloads/", |
|
1694 |
|
"license": [ |
|
1695 |
|
"MIT" |
|
1696 |
|
], |
|
1697 |
|
"authors": [ |
|
1698 |
|
{ |
|
1699 |
|
"name": "Marc Weistroff", |
|
1700 |
|
"email": "marc.weistroff@sensio.com" |
|
1701 |
|
} |
|
1702 |
|
], |
|
1703 |
|
"description": "Bundle around the Buzz HTTP client", |
|
1704 |
|
"homepage": "https://github.com/sensio/SensioBuzzBundle", |
|
1705 |
|
"keywords": [ |
|
1706 |
|
"buzz", |
|
1707 |
|
"http client" |
|
1708 |
|
], |
|
1709 |
|
"time": "2016-03-15T10:06:41+00:00" |
|
1710 |
|
}, |
1615 |
1711 |
{ |
{ |
1616 |
1712 |
"name": "sensio/distribution-bundle", |
"name": "sensio/distribution-bundle", |
1617 |
1713 |
"version": "v5.0.21", |
"version": "v5.0.21", |
|
2736 |
2832 |
], |
], |
2737 |
2833 |
"aliases": [], |
"aliases": [], |
2738 |
2834 |
"minimum-stability": "stable", |
"minimum-stability": "stable", |
2739 |
|
"stability-flags": [], |
|
|
2835 |
|
"stability-flags": { |
|
2836 |
|
"sensio/buzz-bundle": 20 |
|
2837 |
|
}, |
2740 |
2838 |
"prefer-stable": false, |
"prefer-stable": false, |
2741 |
2839 |
"prefer-lowest": false, |
"prefer-lowest": false, |
2742 |
2840 |
"platform": { |
"platform": { |
File src/nasa/src/NeoBundle/Command/ImportLastThreeDaysCommand.php changed (mode: 100644) (index fa0b18b..c1bd9aa) |
... |
... |
use Symfony\Component\Console\Input\InputInterface; |
7 |
7 |
use Symfony\Component\Console\Output\OutputInterface; |
use Symfony\Component\Console\Output\OutputInterface; |
8 |
8 |
use Symfony\Component\Console\Input\InputArgument; |
use Symfony\Component\Console\Input\InputArgument; |
9 |
9 |
|
|
10 |
|
use NeoBundle\Entity\Neo; |
|
|
10 |
|
use NeoBundle\Service\Importer; |
|
11 |
|
use NeoBundle\Exception\NeoImportStructureInvalidException; |
11 |
12 |
|
|
12 |
13 |
class ImportLastThreeDaysCommand extends ContainerAwareCommand |
class ImportLastThreeDaysCommand extends ContainerAwareCommand |
13 |
14 |
{ |
{ |
|
... |
... |
class ImportLastThreeDaysCommand extends ContainerAwareCommand |
22 |
23 |
protected function execute(InputInterface $input, OutputInterface $output) |
protected function execute(InputInterface $input, OutputInterface $output) |
23 |
24 |
{ |
{ |
24 |
25 |
$output->writeln("<info>Import last 3 days from nasa api...</info>"); |
$output->writeln("<info>Import last 3 days from nasa api...</info>"); |
|
26 |
|
$output->writeln(""); |
25 |
27 |
|
|
|
28 |
|
/** @var NeoBundle\Service\Importer $neoImporter */ |
|
29 |
|
$neoImporter = $this->getContainer()->get('neo.import'); |
26 |
30 |
|
|
27 |
|
$em = $this->getContainer()->get('doctrine')->getManager(); |
|
28 |
|
|
|
29 |
|
$product = new Neo(); |
|
30 |
|
$product->setName('Keyboard'); |
|
31 |
|
$product->setReference(1); |
|
32 |
|
$product->setApproachAt(new \DateTime()); |
|
33 |
|
$product->setSpeed(doubleval(2.04)); |
|
34 |
|
$product->setIsHazardous(true); |
|
35 |
|
|
|
36 |
|
$em->persist($product); |
|
37 |
|
|
|
38 |
|
$em->flush(); |
|
|
31 |
|
try { |
|
32 |
|
$neoImporter->import(); |
39 |
33 |
|
|
|
34 |
|
$output->writeln("<info>Import complete!</info>"); |
|
35 |
|
} catch (NeoImportStructureInvalidException $e) { |
|
36 |
|
$output->writeln("<error>Import failed: structure invalid!</error>"); |
|
37 |
|
} catch (\Buzz\Exception\RequestException $e) { |
|
38 |
|
$output->writeln("<error>Import failed: invalid url!</error>"); |
|
39 |
|
} |
40 |
40 |
} |
} |
41 |
41 |
} |
} |
File src/nasa/src/NeoBundle/Entity/Neo.php changed (mode: 100644) (index 011bb29..fd94ec6) |
... |
... |
class Neo |
79 |
79 |
* |
* |
80 |
80 |
* @return Neo |
* @return Neo |
81 |
81 |
*/ |
*/ |
82 |
|
public function setCreatedAt($createdAt) |
|
|
82 |
|
public function setCreatedAt(\DateTime $createdAt) |
83 |
83 |
{ |
{ |
84 |
84 |
$this->createdAt = $createdAt; |
$this->createdAt = $createdAt; |
85 |
85 |
|
|
|
... |
... |
class Neo |
103 |
103 |
* |
* |
104 |
104 |
* @return Neo |
* @return Neo |
105 |
105 |
*/ |
*/ |
106 |
|
public function setApproachAt($approachAt) |
|
|
106 |
|
public function setApproachAt(\DateTime $approachAt) |
107 |
107 |
{ |
{ |
108 |
108 |
$this->approachAt = $approachAt; |
$this->approachAt = $approachAt; |
109 |
109 |
|
|
110 |
110 |
return $this; |
return $this; |
111 |
111 |
} |
} |
112 |
112 |
|
|
|
113 |
|
/** |
|
114 |
|
* Set approachAt as string |
|
115 |
|
* |
|
116 |
|
* @param string $approachAt |
|
117 |
|
|
|
118 |
|
* @return Neo |
|
119 |
|
*/ |
|
120 |
|
public function setApproachAtAsString(string $approachAtAsString) |
|
121 |
|
{ |
|
122 |
|
$this->setApproachAt(\DateTime::createFromFormat('Y-m-d', $approachAtAsString)); |
|
123 |
|
|
|
124 |
|
return $this; |
|
125 |
|
} |
|
126 |
|
|
113 |
127 |
/** |
/** |
114 |
128 |
* Get approachAt |
* Get approachAt |
115 |
129 |
* |
* |
File src/nasa/src/NeoBundle/Repository/NeoRepository.php changed (mode: 100644) (index 0638ccd..1347f20) |
... |
... |
use NeoBundle\Entity\Neo; |
10 |
10 |
/** |
/** |
11 |
11 |
* Neo Repository |
* Neo Repository |
12 |
12 |
*/ |
*/ |
13 |
|
class UserRepository extends EntityRepository |
|
|
13 |
|
class NeoRepository extends EntityRepository |
14 |
14 |
{ |
{ |
15 |
15 |
/** |
/** |
16 |
16 |
* @return mixed |
* @return mixed |
|
... |
... |
class UserRepository extends EntityRepository |
26 |
26 |
|
|
27 |
27 |
return $queryBuilder->getQuery()->getResults(); |
return $queryBuilder->getQuery()->getResults(); |
28 |
28 |
} |
} |
|
29 |
|
|
|
30 |
|
public function referenceExists($reference) |
|
31 |
|
{ |
|
32 |
|
return $this->createQueryBuilder('n') |
|
33 |
|
->select('count(n.id)') |
|
34 |
|
->where('n.reference=:reference') |
|
35 |
|
->setParameter('reference', $reference) |
|
36 |
|
->getQuery() |
|
37 |
|
->getSingleScalarResult() == 0; |
|
38 |
|
} |
29 |
39 |
} |
} |
File src/nasa/src/NeoBundle/Service/Import.php added (mode: 100644) (index 0000000..8e62372) |
|
1 |
|
<?php |
|
2 |
|
|
|
3 |
|
namespace NeoBundle\Service; |
|
4 |
|
|
|
5 |
|
use Doctrine\ORM\EntityManager; |
|
6 |
|
|
|
7 |
|
use NeoBundle\Entity\Neo; |
|
8 |
|
use NeoBundle\Repository\NeoRepository; |
|
9 |
|
use NeoBundle\Exception\NeoImportStructureInvalidException; |
|
10 |
|
|
|
11 |
|
class Import |
|
12 |
|
{ |
|
13 |
|
/** |
|
14 |
|
* @var EntityManager |
|
15 |
|
*/ |
|
16 |
|
private $em; |
|
17 |
|
|
|
18 |
|
/** |
|
19 |
|
* @var \Buzz\Browser |
|
20 |
|
*/ |
|
21 |
|
private $buzz; |
|
22 |
|
|
|
23 |
|
/** |
|
24 |
|
* @var NeoRepository; |
|
25 |
|
*/ |
|
26 |
|
private $neoRepository; |
|
27 |
|
|
|
28 |
|
/** |
|
29 |
|
* @var string |
|
30 |
|
*/ |
|
31 |
|
private $key; |
|
32 |
|
|
|
33 |
|
/** |
|
34 |
|
* @var string |
|
35 |
|
*/ |
|
36 |
|
private $url; |
|
37 |
|
|
|
38 |
|
/** |
|
39 |
|
* @var int |
|
40 |
|
*/ |
|
41 |
|
private $days; |
|
42 |
|
|
|
43 |
|
public function __construct( |
|
44 |
|
EntityManager $em, |
|
45 |
|
\Buzz\Browser $buzz, |
|
46 |
|
NeoRepository $neoRepository, |
|
47 |
|
string $key, string $url, int $days) |
|
48 |
|
{ |
|
49 |
|
$this->em = $em; |
|
50 |
|
$this->buzz = $buzz; |
|
51 |
|
$this->neoRepository = $neoRepository; |
|
52 |
|
$this->key = $key; |
|
53 |
|
$this->url = $url; |
|
54 |
|
$this->days = $days; |
|
55 |
|
} |
|
56 |
|
|
|
57 |
|
public function import() |
|
58 |
|
{ |
|
59 |
|
$result = json_decode($this->buzz->get($this->getUrl())->getContent(), true); |
|
60 |
|
|
|
61 |
|
if ($this->analyze($result)) { |
|
62 |
|
$this->process($result['near_earth_objects']); |
|
63 |
|
} else { |
|
64 |
|
throw new NeoImportStructureInvalidException(); |
|
65 |
|
} |
|
66 |
|
} |
|
67 |
|
|
|
68 |
|
private function process($data) |
|
69 |
|
{ |
|
70 |
|
foreach ($data as $key=>$value) { |
|
71 |
|
foreach ($value as $item) { |
|
72 |
|
$neo = new Neo(); |
|
73 |
|
|
|
74 |
|
$neo->setName($item['name']); |
|
75 |
|
$neo->setReference($item['neo_reference_id']); |
|
76 |
|
$neo->setSpeed( |
|
77 |
|
count($item['close_approach_data']) > 0 ? |
|
78 |
|
$item['close_approach_data'][0]['relative_velocity']['kilometers_per_hour'] : 0 |
|
79 |
|
); |
|
80 |
|
$neo->setApproachAtAsString( |
|
81 |
|
count($item['close_approach_data']) > 0 ? |
|
82 |
|
$item['close_approach_data'][0]['close_approach_date'] : null |
|
83 |
|
); |
|
84 |
|
$neo->setIsHazardous($item['is_potentially_hazardous_asteroid']); |
|
85 |
|
|
|
86 |
|
$this->persist($neo); |
|
87 |
|
} |
|
88 |
|
} |
|
89 |
|
} |
|
90 |
|
|
|
91 |
|
private function persist(Neo $neo) |
|
92 |
|
{ |
|
93 |
|
if ($this->neoRepository->referenceExists($neo->getReference())) { |
|
94 |
|
$this->em->persist($neo); |
|
95 |
|
|
|
96 |
|
$this->em->flush(); |
|
97 |
|
} |
|
98 |
|
} |
|
99 |
|
|
|
100 |
|
private function analyze($data) |
|
101 |
|
{ |
|
102 |
|
if ( |
|
103 |
|
is_array($data) |
|
104 |
|
&& isset($data['near_earth_objects']) |
|
105 |
|
) { |
|
106 |
|
return true; |
|
107 |
|
} else { |
|
108 |
|
return false; |
|
109 |
|
} |
|
110 |
|
} |
|
111 |
|
|
|
112 |
|
private function getUrl() |
|
113 |
|
{ |
|
114 |
|
$end = new \DateTime(); |
|
115 |
|
$start = new \DateTime(); |
|
116 |
|
$start->sub(new \DateInterval('P' . ($this->days - 1) . 'D')); |
|
117 |
|
|
|
118 |
|
return str_replace( |
|
119 |
|
'##key##', |
|
120 |
|
$this->key, |
|
121 |
|
str_replace( |
|
122 |
|
'##start##', |
|
123 |
|
$start->format('Y-m-d'), |
|
124 |
|
str_replace( |
|
125 |
|
'##end##', |
|
126 |
|
$end->format('Y-m-d'), |
|
127 |
|
$this->url |
|
128 |
|
) |
|
129 |
|
) |
|
130 |
|
); |
|
131 |
|
} |
|
132 |
|
} |