Skip to content

Commit

Permalink
Add new Parser for the SessionizeApi
Browse files Browse the repository at this point in the history
  • Loading branch information
heiglandreas committed Feb 14, 2023
1 parent 15ab89b commit f539501
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
root = true

[*]
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[{*.js, *.json}]
indent_size = 2
7 changes: 4 additions & 3 deletions bin/callingallpapers
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ set_time_limit(0);
date_default_timezone_set('Etc/UTC');

// include the composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

// import the Symfony Console Application
use Symfony\Component\Console\Application;
// import the Symfony Console Application
use Symfony\Component\Console\Application;

$app = new Application();
$app->add(new \Callingallpapers\Command\ParseEvents());
$app->add(new \Callingallpapers\Command\ParseEventsConfsTech());
$app->add(new \Callingallpapers\Subcommands\Sessionize\Command());
$app->add(new \Callingallpapers\Subcommands\SessionizeApi\Command());
$app->add(new \Callingallpapers\Command\NotifyClosingCfps());

$app->run();
5 changes: 4 additions & 1 deletion config/callingallpapers.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ mastodon.name = "cfp"
mastodon.instance = "social.callingallpapers.com"
mastodon.clientId = ""
mastodon.clientSecret = ""
mastodon.token = ""
mastodon.token = ""
;
; Sessionize
sessionize.apiKey = ""
3 changes: 3 additions & 0 deletions src/CfpFilter/FollowUriRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function __construct(array $fields, Client $client)
public function filter(Cfp $cfp) : Cfp
{
foreach ($this->fields as $field) {
if ($cfp->$field === null) {
continue;
}
try {
$cfp->$field = $this->followRedirects($cfp->$field);
} catch (\Exception $e) {
Expand Down
10 changes: 5 additions & 5 deletions src/Command/AbstractParseEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ protected function configure()
->setDefinition(array(
new InputOption('start', 's', InputOption::VALUE_OPTIONAL, 'What should be the first date to be taken into account?', ''),
))
->setHelp(sprintf(<<<EOT
Get details about CfPs from https://sesionize.com
->setHelp(sprintf(<<<'EOT'
Get details about CfPs from %2$s
Usage:
<info>callingallpapers parseCfPs:sessionize 2015-02-23<env></info>
<info>callingallpapers parseCfPs:%1$s 2015-02-23<env></info>
If you ommit the date the current date will be used instead
<info>callingallpapers parseCfPs:sessionize<env></info>
<info>callingallpapers parseCfPs:%1$s<env></info>
EOT
, $this->getServiceUrl()));
, $this->getParserId(), $this->getParserName()));
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
24 changes: 24 additions & 0 deletions src/Service/ConfigService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Copyright Andreas Heigl <andreas@heigl.org>
*
* Licensed under the MIT-license. For details see the included file LICENSE.md
*/
declare(strict_types=1);

namespace Callingallpapers\Service;

use function parse_ini_file;

class ConfigService
{
private $configFile = __DIR__ . '/../../config/callingallpapers.ini';

public function __construct() {}

public function getConfiguration(): array
{
return parse_ini_file($this->configFile)??[];
}
}
4 changes: 0 additions & 4 deletions src/Service/MastodonNotifierClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

use Colorfield\Mastodon\MastodonAPI;
use Colorfield\Mastodon\MastodonOAuth;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
use OAuth;

class MastodonNotifierClientFactory
{
Expand Down
1 change: 0 additions & 1 deletion src/Subcommands/Sessionize/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use Callingallpapers\Service\ServiceContainer;
use Callingallpapers\Subcommands\Sessionize\Parser\EntryParser;
use Callingallpapers\Subcommands\Sessionize\Parser\Sessionize;
use GuzzleHttp\Client;

class Command extends AbstractParseEvents
{
Expand Down
46 changes: 46 additions & 0 deletions src/Subcommands/SessionizeApi/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* Copyright Andreas Heigl <andreas@heigl.org>
*
* Licensed under the MIT-license. For details see the included file LICENSE.md
*/
declare(strict_types=1);

namespace Callingallpapers\Subcommands\SessionizeApi;

use Callingallpapers\Command\AbstractParseEvents;
use Callingallpapers\Entity\Cfp;
use Callingallpapers\Parser\ParserInterface;
use Callingallpapers\Service\ConfigService;
use Callingallpapers\Service\ServiceContainer;
use Callingallpapers\Subcommands\SessionizeApi\Parser\EntryParser;
use Callingallpapers\Subcommands\SessionizeApi\Parser\Sessionize;
use function strtolower;

class Command extends AbstractParseEvents
{
const NAME = 'SessionizeAPI';

protected function getParser(ServiceContainer $serviceContainer) : ParserInterface
{
$parser = new EntryParser(new Cfp(), $serviceContainer);

return new Sessionize($parser, $serviceContainer->getClient(), new ConfigService());
}

protected function getParserName() : string
{
return self::NAME;
}

protected function getParserId() : string
{
return strtolower($this->getParserName());
}

protected function getServiceUrl() : string
{
return 'https://sessionize.com';
}
}
116 changes: 116 additions & 0 deletions src/Subcommands/SessionizeApi/Parser/EntryParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

declare(strict_types = 1);

/**
* Copyright Andrea Heigl <andreas@heigl.org>
*
* Licenses under the MIT-license. For details see the included file LICENSE.md
*/
namespace Callingallpapers\Subcommands\SessionizeApi\Parser;

use Callingallpapers\Entity\Cfp;
use Callingallpapers\Service\ServiceContainer;
use Callingallpapers\Service\TimezoneService;
use DateTimeImmutable;
use DateTimeZone;
use DOMDocument;
use DOMXPath;
use Exception;
use GuzzleHttp\Client;
use InvalidArgumentException;
use Throwable;

class EntryParser
{
private $cfp;

private $timezoneService;

private $geolocationService;

public function __construct(Cfp $cfp, ServiceContainer $container)
{
$this->cfp = $cfp;
$this->timezoneService = $container->getTimezoneService();
$this->geolocationService = $container->getGeolocationService();
}

/**
* @param array{
* eventId: int,
* name: string,
* organizer: string,
* website: string,
* cfpLink: string,
* isTest: boolean,
* isOnline: boolean,
* isUserGroup: boolean,
* expensesCovered: array{
* conferenceFee: boolean,
* accommodation: boolean,
* travel: boolean
* },
* eventDates: array{
* start: datestring,
* end: datestring
* },
* cfpDates: array{
* startUtc: datetimestringZ,
* endUtc: datetimestringZ,
* start: datetimestring,
* end: datetimestring
* },
* timezone: array{
* iana: string,
* windows: string
* },
* location: array{
* full: string,
* city: string,
* state: string,
* country: string,
* coordinates: latlonstring
* },
* links: array{
* twitter: string,
* linkedIn: null,
* facebook: string,
* instagram: string,
* }
* } $event
* @return Cfp
* @throws Exception
*/
public function parse(array $event): Cfp
{
$cfp = new Cfp();

try {
$cfp->location = $event['location']['full']??'';
if ($event['location']['coordinates']??null !== null) {
$location = explode(',', $event['location']['coordinates']);
$cfp->latitude = $location[0];
$cfp->longitude = $location[1];
}
$cfp->timezone = $event['timezone']['iana'];

$timezone = new DateTimeZone($cfp->timezone);

$cfp->dateEnd = new DateTimeImmutable($event['cfpDates']['end'], $timezone);
$cfp->dateStart = new DateTimeImmutable($event['cfpDates']['start'], $timezone);

$cfp->uri = $event['cfpLink'];
$cfp->conferenceName = $event['name'];

$cfp->conferenceUri = $event['website'];

$cfp->eventEndDate = new DateTimeImmutable($event['eventDates']['end'], $timezone);
$cfp->eventStartDate = new DateTimeImmutable($event['eventDates']['start'], $timezone);

return $cfp;
} catch (Exception $e) {
throw $e;
}
}
}
Loading

0 comments on commit f539501

Please sign in to comment.