Skip to content

Commit

Permalink
v0.4.7: Added Gardaland
Browse files Browse the repository at this point in the history
  • Loading branch information
timyboy12345 committed Nov 8, 2023
1 parent 38b03f8 commit 067adec
Show file tree
Hide file tree
Showing 11 changed files with 608 additions and 40 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ In the table below you will find the parks that are currently supported and the
| 🇬🇧 Alton Towers | 🎡 | True | True | True | True | False |
| 🇬🇧 Paultons Park | 🎡 | True | True | True | True | False |
| 🇬🇧 Chessington world of Adventures | 🎡 | True | True | True | True | False |
| 🇮🇹 Gardaland | 🎡 | True | True | True | False | False |
| 🇳🇱 Efteling | 🎡 | True | True | True | True | False |
| 🇳🇱 Toverland | 🎡 | True | True | True | False | True |
| 🇳🇱 Walibi Holland | 🎡 | True | True | True | True | True |
Expand Down Expand Up @@ -104,7 +105,7 @@ In the table below you will find the parks that are currently supported and the
## Parks on the planning

UK: Pleasure Beach, LegoLand Windsor, Drayton Manor
IT: Gardaland, Cincetitta World
IT: Cincetitta World, **Mirabilandia**
ES: Puy de Fou Espana
DE: Europapark, Rulantica, Heidi Park
OO: Familypark
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "themeparks-node-api",
"version": "0.4.6",
"version": "0.4.7",
"description": "An API which can retrieve theme park wait times.",
"author": "Tim Arendsen",
"private": false,
Expand Down
64 changes: 34 additions & 30 deletions src/_services/aio/aio-themepark.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ThemeParkSupports } from '../../_interfaces/park-supports.interface';
import { Poi } from '../../_interfaces/poi.interface';
import * as fs from 'fs';
import { HttpService } from '@nestjs/axios';
import * as Sentry from '@sentry/node';

const unzipper = require('unzipper');

Expand Down Expand Up @@ -43,7 +44,7 @@ export class AioThemeparkService extends ThroughPoisThemeParkService {
supportsRideWaitTimesHistory: false,
supportsPois: true,
supportsTranslations: false,
supportsHalloween: false,
supportsHalloween: false,
};
}

Expand Down Expand Up @@ -121,24 +122,24 @@ supportsHalloween: false,
};

return new Promise((resolve, reject) => {
this.httpService
.get(
this._attractionsIoApiUrl + '/data',
config,
)
.toPromise()
.then(() => {
// When the call is successful, a redirect status code was not given
// This means something went wrong
console.error('SUCCESS BUT ACTUALLY AN ERROR');
reject();
})
.catch((reason: AxiosError) => {
if (reason.response.status === 303) {
const headers = reason.response.headers;
resolve(headers.location);
return;
}
this.httpService
.get(
this._attractionsIoApiUrl + '/data',
config,
)
.toPromise()
.then(() => {
// When the call is successful, a redirect status code was not given
// This means something went wrong
console.error('SUCCESS BUT ACTUALLY AN ERROR');
reject();
})
.catch((reason: AxiosError) => {
if (reason.response.status === 303) {
const headers = reason.response.headers;
resolve(headers.location);
return;
}

console.error('FAILED');
console.error(`${reason.response.status} / ${reason.response.statusText}`);
Expand All @@ -163,11 +164,11 @@ supportsHalloween: false,
.toPromise()
.then(value => {
if (!fs.existsSync(`${__dirname}/../../../storage`)) {
fs.mkdirSync(`${__dirname}/../../../storage`)
fs.mkdirSync(`${__dirname}/../../../storage`);
}

if (!fs.existsSync(`${__dirname}/../../../storage/aio`)) {
fs.mkdirSync(`${__dirname}/../../../storage/aio`)
fs.mkdirSync(`${__dirname}/../../../storage/aio`);
}

fs.writeFile(downloadLocation, value.data, function(err) {
Expand Down Expand Up @@ -200,24 +201,27 @@ supportsHalloween: false,
}

public getDefaultLanguage(): string {
return 'en-GB'
return 'en-GB';
}

async getPois(): Promise<Poi[]> {
const url = await this.getDataUrl()
.then((value) => {
return value;
})
.catch(reason => {
console.error(reason);
});

const inputPath = `${__dirname}/../../../storage/aio/${this.getInstallationDirectory()}.zip`;
const outputPath = `${__dirname}/../../../storage/aio/${this.getInstallationDirectory()}-output/`;

// TODO: Add a system that invalidates old information (fs.stat or fs.statSync?)
const settingsExists = fs.existsSync(`${outputPath}/records.json`);

if (!settingsExists) {
const url = await this.getDataUrl()
.then((value) => {
return value;
})
.catch(reason => {
console.error(reason);
Sentry.captureException(reason);
throw reason;
});

await this.downloadZip(url, inputPath)
.then(() => {
console.log(`Zip file downloaded to ${inputPath}`);
Expand Down
3 changes: 3 additions & 0 deletions src/_services/parks/parks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
import { HersheyparkService } from '../../parks/hersheypark/hersheypark.service';
import { SeaworldService } from '../../parks/seaworld/seaworld.service';
import { UniversalService } from '../../parks/universal/universal.service';
import { GardalandService } from '../../parks/gardaland/gardaland.service';

@Injectable()
export class ParksService {
Expand Down Expand Up @@ -113,6 +114,7 @@ export class ParksService {
private readonly _hersheypark: HersheyparkService,
private readonly _seaworldCompanyService: SeaworldService,
private readonly _universalService: UniversalService,
private readonly _gardaland: GardalandService,
) {
this._parks = [];
this._parks.push(_eftelingService);
Expand Down Expand Up @@ -158,6 +160,7 @@ export class ParksService {
this._parks.push(_parqueWarnerMadridBeach);
this._parks.push(_futuroscope);
this._parks.push(_hersheypark);
this._parks.push(_gardaland)

this._companies = [];
this._companies.push(_sixflagsService);
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/parks/parks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export class ParksController {
}

/**
* convert country code to corresponding flag emoji
* Convert country code to corresponding flag emoji
* @param {string} cc - country code string
* @returns {string} flag emoji
*/
private countryCodeEmoji(cc) {
private countryCodeEmoji(cc): string {
// country code regex
const CC_REGEX = /^[a-z]{2}$/i;

Expand All @@ -100,6 +100,11 @@ export class ParksController {
return String.fromCodePoint(...codePoints);
}

/**
* Capitalize the first letter of a word
* @param string The string to capitalize
* @private
*/
private capitalize(string: string) {
return string.slice(0, 1).toUpperCase() + string.slice(1);
};
Expand Down
19 changes: 19 additions & 0 deletions src/parks/gardaland/gardaland.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Module } from '@nestjs/common';
import { GardalandService } from './gardaland.service';
import { HttpModule } from '@nestjs/axios';
import { ConfigModule } from '@nestjs/config';
import { AioTransferServiceService } from '../../_services/aio/transfer-service/aio-transfer-service.service';

@Module({
imports: [
HttpModule,
ConfigModule.forRoot({
envFilePath: '.env',
cache: false,
ignoreEnvFile: false,
}),
],
providers: [GardalandService, AioTransferServiceService],
exports: [GardalandService],
})
export class GardalandModule {}
31 changes: 31 additions & 0 deletions src/parks/gardaland/gardaland.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Test, TestingModule } from '@nestjs/testing';
import { GardalandService } from './gardaland.service';
import { AioTransferServiceService } from '../../_services/aio/transfer-service/aio-transfer-service.service';
import { HttpModule } from '@nestjs/axios';
import { ConfigModule } from '@nestjs/config';

describe('GardalandService', () => {
let service: GardalandService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [GardalandService, AioTransferServiceService],
imports: [HttpModule, ConfigModule.forRoot()],
}).compile();

service = module.get<GardalandService>(GardalandService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});

it('should return info', () => {
expect(service.getInfo().id).toBeDefined();
});

it('should return a list of POIs', async () => {
const data = await service.getPois();
expect(data).toBeInstanceOf(Array);
}, 1000 * 60);
});
Loading

0 comments on commit 067adec

Please sign in to comment.