Commit c4510f44 authored by Andreas Muttscheller's avatar Andreas Muttscheller

Add integration test for planned timetable fetcher

parent d5af6f64
......@@ -37,3 +37,4 @@ build
#api conf files
*api.conf
*.token
......@@ -53,6 +53,9 @@ lazy val root = (project in file("."))
"com.amazonaws" % "aws-lambda-java-events" % "2.2.5",
"com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
"com.amazonaws" % "aws-java-sdk-ecs" % "1.11.492" % "it",
"com.amazonaws" % "aws-java-sdk-ec2" % "1.11.492" % "it",
// ElasticSearch
"com.sksamuel.elastic4s" % "elastic4s-core_2.12" % "6.3.8",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "6.3.8",
......
......@@ -9,10 +9,14 @@ import com.amazonaws.services.ecs.AmazonECSClientBuilder
import com.amazonaws.services.ecs.model._
import com.amazonaws.services.elasticsearch.AWSElasticsearchClientBuilder
import com.amazonaws.services.elasticsearch.model.DescribeElasticsearchDomainRequest
import com.amazonaws.services.lambda.AWSLambdaClientBuilder
import com.amazonaws.services.lambda.model.{Environment, GetFunctionConfigurationRequest, UpdateFunctionConfigurationRequest}
import com.sksamuel.elastic4s.aws.Aws4ElasticClient
import com.sksamuel.elastic4s.http.ElasticDsl._
import com.sksamuel.elastic4s.http.ElasticProperties
import sbt.Keys.envVars
import sbt._
import complete.DefaultParsers._
import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext.Implicits.global
......@@ -32,6 +36,7 @@ object AwsUtils extends AutoPlugin {
val startECSMockServer = taskKey[Unit]("Start MockServer on ECS")
val listECSMockServer = taskKey[Unit]("List MockServer on ECS")
val stopECSMockServer = taskKey[Unit]("Stop MockServer on ECS")
val updateLambdaMockServerEnv = inputKey[Unit]("Set the environment variable for mock server on lambdas")
}
import autoImport._
......@@ -193,6 +198,32 @@ object AwsUtils extends AutoPlugin {
}
}
def updateLambdaMockServerIp(service: String, stage: String, mockServerIp: String): Unit = {
val lambdaClient = AWSLambdaClientBuilder.defaultClient
lambdaClient.listFunctions()
.getFunctions
.asScala
.map(_.getFunctionName)
.filter(_.startsWith(s"$service-$stage-"))
.foreach { functionName =>
val functionConf = lambdaClient.getFunctionConfiguration(new GetFunctionConfigurationRequest()
.withFunctionName(functionName)
)
println(s"Updating function $functionName with IP $mockServerIp")
val envVars = functionConf.getEnvironment.getVariables
envVars.put("SLACK_API_URL", s"$mockServerIp/slack")
envVars.put("DB_API_URL", s"$mockServerIp/dbapi")
lambdaClient.updateFunctionConfiguration(new UpdateFunctionConfigurationRequest()
.withFunctionName(functionName)
.withEnvironment(new Environment()
.withVariables(envVars)
)
)
}
}
override lazy val projectSettings = Seq(
awsServiceName in IntegrationTest := "delay-info",
awsStage in IntegrationTest := "sbt-it",
......@@ -219,6 +250,9 @@ object AwsUtils extends AutoPlugin {
},
startECSMockServer in IntegrationTest := {
val service = (envVars in IntegrationTest).value.getOrElse("SERVERLESS_SERVICE", "")
val stage = (envVars in IntegrationTest).value.getOrElse("SERVERLESS_STAGE", "")
val runningTasks = getRunningMockServerTasks()
if (runningTasks.nonEmpty) {
val attachmentsDetails = runningTasks.head.getAttachments.get(0).getDetails.asScala
......@@ -226,7 +260,9 @@ object AwsUtils extends AutoPlugin {
val publicIp = getIpForNetworkInterfaceId(networkInterfaceId.getValue)
println(s"Mockserver ${runningTasks.head.getTaskArn} already running on ip $publicIp")
} else {
startMockServer()
val publicIp = startMockServer()
updateLambdaMockServerIp(service, stage, publicIp)
}
},
......@@ -238,6 +274,17 @@ object AwsUtils extends AutoPlugin {
val runningTasks = getRunningMockServerTasks()
stopMockServers(runningTasks)
},
)
updateLambdaMockServerEnv in IntegrationTest := {
val args: Seq[String] = spaceDelimited("<arg>").parsed
if (args.size != 1) {
println("Specify ip or host of mockserver")
} else {
val service = (envVars in IntegrationTest).value.getOrElse("SERVERLESS_SERVICE", "")
val stage = (envVars in IntegrationTest).value.getOrElse("SERVERLESS_STAGE", "")
updateLambdaMockServerIp(service, stage, args.head)
}
},
)
}
\ No newline at end of file
libraryDependencies ++= Seq(
// AWS
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.11.488",
"com.amazonaws" % "aws-java-sdk-elasticsearch" % "1.11.488",
"com.amazonaws" % "aws-java-sdk-ecs" % "1.11.488",
"com.amazonaws" % "aws-java-sdk-ec2" % "1.11.488",
"com.amazonaws" % "aws-java-sdk-dynamodb" % "1.11.492",
"com.amazonaws" % "aws-java-sdk-elasticsearch" % "1.11.492",
"com.amazonaws" % "aws-java-sdk-ecs" % "1.11.492",
"com.amazonaws" % "aws-java-sdk-ec2" % "1.11.492",
"com.amazonaws" % "aws-java-sdk-lambda" % "1.11.492",
// ElasticSearch
"com.sksamuel.elastic4s" % "elastic4s-core_2.12" % "6.3.8",
......
......@@ -22,6 +22,7 @@ provider:
- es:ESHttpPut
- es:ESHttpDelete
- es:ESHttpGet
- es:DescribeElasticsearchDomain
Resource: '*'
environment:
IS_SERVERLESS: "true"
......
<?xml version="1.0" ?>
<timetable station="Frankfurt(Main)Hbf">
<s id="5445318277801725537-1902150047-1">
<tl c="RB" f="N" n="24777" o="K4RB" t="p"/>
<dp l="12" pp="22" ppth="Frankfurt-Höchst|Frankfurt-Unterliederbach|Liederbach-Süd|Liederbach|Kelkheim-Münster|Kelkheim|Kelkheim-Hornau|Schneidhain|Königstein(Taunus)" pt="1902150047"/>
</s>
<s id="8929972609231063802-1902142347-13">
<tl c="S" f="S" n="35683" o="800528" t="p"/>
<ar l="6" pp="15" ppth="Friedberg(Hess)|Bruchenbrücken|Nieder Wöllstadt|Okarben|Groß Karben|Dortelweil|Bad Vilbel|Bad Vilbel Süd|Frankfurt-Berkersheim|Frankfurt-Frankfurter Berg|Frankfurt-Eschersheim|Frankfurt(Main)West" pt="1902150028"/>
</s>
<s id="-2061827729431017903-1902150030-1">
<tl c="RE" f="N" n="4639" o="800772" t="p"/>
<dp l="54" pp="5" ppth="Frankfurt(Main)Süd|Frankfurt(Main)Ost|Frankfurt-Mainkur|Maintal West|Maintal Ost|Hanau-Wilhelmsbad|Hanau West|Hanau Hbf|Großauheim(Kr Hanau)|Großkrotzenburg|Kahl(Main)|Dettingen(Main)|Rückersbacher Schlucht|Kleinostheim|Aschaffenburg Hbf" pt="1902150030"/>
</s>
<s id="689999962957508889-1902150050-1">
<tl c="S" f="S" n="35787" o="800528" t="p"/>
<dp l="7" pp="3" ppth="Frankfurt-Niederrad|Frankfurt am Main - Stadion|Zeppelinheim|Walldorf(Hess)|Mörfelden|Groß Gerau-Dornberg|Groß Gerau-Dornheim|Riedstadt-Wolfskehlen|Riedstadt-Goddelau" pt="1902150050"/>
</s>
<s id="-5351785907908476378-1902142243-25">
<tl c="RB" f="N" n="15035" o="800535" t="p"/>
<ar l="41" pp="7" ppth="Marburg(Lahn)|Marburg Süd|Niederweimar|Niederwalgern|Fronhausen(Lahn)|Friedelhausen|Lollar|Gießen Oswaldsgarten|Gießen|Großen Linden|Lang Göns|Kirch Göns|Butzbach|Ostheim(b Butzbach)|Bad Nauheim|Friedberg(Hess)|Assenheim(Oberhess)|Nidderau|Ostheim(Kr Hanau)|Bruchköbel|Hanau Nord|Hanau Hbf|Offenbach(Main)Hbf|Frankfurt(Main)Süd" pt="1902150038" wings="-1771922681694671110-1902142233"/>
</s>
<s id="-1771922681694671110-1902142233-26">
<tl c="RB" f="N" n="15135" o="800535" t="p"/>
<ar l="40" pp="7" ppth="Herborn(Dillkr)|Sinn|Edingen(Wetzlar)|Katzenfurt|Ehringshausen(Kr Wetzlar)|Werdorf|Aßlar|Wetzlar|Dutenhofen(Wetzlar)|Gießen|Großen Linden|Lang Göns|Kirch Göns|Butzbach|Ostheim(b Butzbach)|Bad Nauheim|Friedberg(Hess)|Assenheim(Oberhess)|Nidderau|Ostheim(Kr Hanau)|Bruchköbel|Hanau Nord|Hanau Hbf|Offenbach(Main)Hbf|Frankfurt(Main)Süd" pt="1902150038"/>
</s>
<s id="5326279913886417438-1902150028-1">
<tl c="RB" f="N" n="25678" o="K4RB" t="p"/>
<dp l="21" pp="17" ppth="Frankfurt-Höchst|Hofheim(Taunus)|Niedernhausen(Taunus)|Idstein(Taunus)|Wörsdorf|Bad Camberg|Niederselters|Oberbrechen|Niederbrechen|Lindenholzhausen|Eschhofen|Limburg(Lahn)" pt="1902150028"/>
</s>
<s id="544811828918702738-1902141730-17">
<tl c="IC" f="F" n="2321" o="80" t="p"/>
<ar pp="2" ppth="Hamburg-Altona|Hamburg Dammtor|Hamburg Hbf|Hamburg-Harburg|Bremen Hbf|Osnabrück Hbf|Münster(Westf)Hbf|Dortmund Hbf|Essen Hbf|Duisburg Hbf|Düsseldorf Hbf|Köln Hbf|Bonn Hbf|Koblenz Hbf|Mainz Hbf|Frankfurt(M) Flughafen Fernbf" pt="1902150034"/>
</s>
<s id="9117006994590991223-1902142236-32">
<tl c="RE" f="N" n="4636" o="800772" t="p"/>
<ar l="54" pp="5" ppth="Würzburg Hbf|Würzburg-Zell|Veitshöchheim|Thüngersheim|Retzbach-Zellingen|Himmelstadt|Karlstadt(Main)|Wernfeld|Gemünden(Main)|Langenprozelten|Lohr Bahnhof|Partenstein|Wiesthal|Heigenbrücken|Laufach|Hösbach|Aschaffenburg Hbf|Kleinostheim|Rückersbacher Schlucht|Dettingen(Main)|Kahl(Main)|Großkrotzenburg|Großauheim(Kr Hanau)|Hanau Hbf|Hanau West|Hanau-Wilhelmsbad|Maintal Ost|Maintal West|Frankfurt-Mainkur|Frankfurt(Main)Ost|Frankfurt(Main)Süd" pt="1902150048"/>
</s>
<s id="5391302266099657590-1902142320-20">
<tl c="RB" f="N" n="15338" o="800574" t="p"/>
<ar l="68" pp="11" ppth="Heidelberg Hbf|Heidelberg-Pfaffengrund/Wieblingen|Neu-Edingen/Friedrichsfeld|Ladenburg|Heddesheim/Hirschberg|Weinheim-Lützelsachsen|Weinheim(Bergstr)Hbf|Hemsbach|Laudenbach(Bergstr)|Heppenheim(Bergstr)|Bensheim|Bensheim-Auerbach|Zwingenberg(Bergstr)|Hähnlein-Alsbach|Bickenbach(Bergstr)|Darmstadt-Eberstadt|Darmstadt Süd|Darmstadt Hbf|Langen(Hess)" pt="1902150048"/>
</s>
<s id="-2320340282101811304-1902142044-9">
<tl c="ICE" f="F" n="990" o="80" t="p"/>
<ar pp="9" ppth="München Hbf|München-Pasing|Augsburg Hbf|Günzburg|Ulm Hbf|Stuttgart Hbf|Mannheim Hbf|Frankfurt(M) Flughafen Fernbf" pt="1902150042"/>
</s>
<s id="8573811631662133764-1902142054-6">
<tl c="ICE" f="F" n="520" o="80" t="p"/>
<ar pp="9" ppth="München Hbf|Ingolstadt Hbf|Nürnberg Hbf|Würzburg Hbf|Aschaffenburg Hbf" pt="1902150004"/>
</s>
<s id="1711468741577268284-1902150051-1">
<tl c="RB" f="N" n="15036" o="800535" t="p"/>
<dp l="41" pp="7" ppth="Hanau Hbf|Hanau Nord|Bruchköbel|Ostheim(Kr Hanau)|Nidderau|Assenheim(Oberhess)|Friedberg(Hess)|Bad Nauheim|Ostheim(b Butzbach)|Butzbach|Kirch Göns|Lang Göns|Großen Linden|Gießen|Gießen Oswaldsgarten|Lollar|Friedelhausen|Fronhausen(Lahn)|Niederwalgern|Niederweimar|Marburg Süd|Marburg(Lahn)" pt="1902150051"/>
</s>
<s id="4277600017421966851-1902150012-1">
<tl c="RE" f="N" n="15383" o="800574" t="p"/>
<dp l="70" pp="18" ppth="Frankfurt-Niederrad|Walldorf(Hess)|Mörfelden|Groß Gerau-Dornberg|Riedstadt-Goddelau|Stockstadt(Rhein)|Biebesheim|Gernsheim|Groß Rohrheim|Biblis|Bürstadt|Lampertheim|Mannheim-Waldhof|Mannheim Hbf" pt="1902150012"/>
</s>
<s id="-2147690495976399103-1902150042-1">
<tl c="RB" f="N" n="15540" o="8005KG" t="p"/>
<dp l="51" pp="12" ppth="Frankfurt(Main)Süd|Offenbach(Main)Hbf|Hanau Hbf|Wolfgang(Kr Hanau)|Rodenbach(b Hanau)|Langenselbold|Niedermittlau|Hailer-Meerholz|Gelnhausen|Haitz-Höchst|Wirtheim|Wächtersbach" pt="1902150042"/>
</s>
<s id="6604699306965746197-1902142331-10">
<tl c="RB" f="N" n="24776" o="K4RB" t="p"/>
<ar l="12" pp="22" ppth="Königstein(Taunus)|Schneidhain|Kelkheim-Hornau|Kelkheim|Kelkheim-Münster|Liederbach|Liederbach-Süd|Frankfurt-Unterliederbach|Frankfurt-Höchst" pt="1902150009"/>
</s>
<s id="-7270965197440929462-1902142056-12">
<tl c="ICE" f="F" n="619" o="80" t="p"/>
<ar pp="4" ppth="Dortmund Hbf|Bochum Hbf|Essen Hbf|Duisburg Hbf|Düsseldorf Hbf|Köln Hbf|Köln/Bonn Flughafen|Siegburg/Bonn|Montabaur|Limburg Süd|Frankfurt(M) Flughafen Fernbf" pt="1902142359"/>
<dp pp="4" ppth="Frankfurt(M) Flughafen Fernbf|Mannheim Hbf|Heidelberg Hbf|Wiesloch-Walldorf|Bruchsal|Karlsruhe-Durlach|Karlsruhe Hbf|Pforzheim Hbf|Vaihingen(Enz)|Ludwigsburg|Stuttgart Hbf|Plochingen|Ulm Hbf|Günzburg|Augsburg Hbf|München-Pasing|München Hbf" pt="1902150007"/>
</s>
<s id="6933857052093557078-1902150004-1">
<tl c="S" f="S" n="35682" o="800528" t="p"/>
<dp l="6" pp="13" ppth="Frankfurt(Main)West|Frankfurt-Eschersheim|Frankfurt-Frankfurter Berg|Frankfurt-Berkersheim|Bad Vilbel Süd|Bad Vilbel|Dortelweil|Groß Karben|Okarben|Nieder Wöllstadt|Bruchenbrücken|Friedberg(Hess)" pt="1902150004"/>
</s>
<s id="8097664128135578451-1902150006-1">
<tl c="RB" f="N" n="15443" o="800574" t="p"/>
<dp l="67" pp="10" ppth="Langen(Hess)|Darmstadt Hbf|Darmstadt Süd|Darmstadt-Eberstadt|Bickenbach(Bergstr)|Hähnlein-Alsbach|Zwingenberg(Bergstr)|Bensheim-Auerbach|Bensheim|Heppenheim(Bergstr)|Laudenbach(Bergstr)|Hemsbach|Weinheim(Bergstr)Hbf|Weinheim-Lützelsachsen|Heddesheim/Hirschberg|Ladenburg|Neu-Edingen/Friedrichsfeld|Heidelberg-Pfaffengrund/Wieblingen|Heidelberg Hbf" pt="1902150006"/>
</s>
<s id="403936669958155930-1902142330-10">
<tl c="S" f="S" n="35782" o="800528" t="p"/>
<ar l="7" pp="3" ppth="Riedstadt-Goddelau|Riedstadt-Wolfskehlen|Groß Gerau-Dornheim|Groß Gerau-Dornberg|Mörfelden|Walldorf(Hess)|Zeppelinheim|Frankfurt am Main - Stadion|Frankfurt-Niederrad" pt="1902150006"/>
</s>
<s id="3949100401734490513-1902150045-1">
<tl c="Bus" n="684" o="B4" t="p"/>
<dp l="SEV" pp="" ppth="Frankfurt(Main)West|Frankfurt-Eschersheim|Frankfurt-Frankfurter Berg|Frankfurt-Berkersheim|Bad Vilbel Süd|Bad Vilbel|Dortelweil|Groß Karben|Okarben|Nieder Wöllstadt|Bruchenbrücken|Friedberg(Hess)" pt="1902150045"/>
</s>
<s id="5726617865424892740-1902142311-13">
<tl c="RE" f="N" n="4539" o="8005KG" t="p"/>
<ar l="50" pp="12" ppth="Fulda|Neuhof(Kr Fulda)|Flieden|Schlüchtern|Steinau(Straße)|Bad Soden-Salmünster|Wächtersbach|Gelnhausen|Langenselbold|Hanau Hbf|Offenbach(Main)Hbf|Frankfurt(Main)Süd" pt="1902150031"/>
</s>
<s id="2891128803380922252-1902141946-10">
<tl c="ICE" f="F" n="887" o="80" t="p"/>
<ar pp="8" ppth="Hamburg-Altona|Hamburg Dammtor|Hamburg Hbf|Lüneburg|Uelzen|Hannover Hbf|Göttingen|Kassel-Wilhelmshöhe|Fulda" pt="1902142352"/>
<dp pp="8" ppth="Frankfurt(M) Flughafen Fernbf|Mainz Hbf|Wiesbaden Hbf" pt="1902150013"/>
</s>
</timetable>
<?xml version="1.0" ?>
<timetable station="Frankfurt(Main)Hbf">
<s id="6246205014592858079-1902150009-23">
<tl c="RE" f="N" n="4588" o="800574" t="p"/>
<ar l="70" pp="17" ppth="Mannheim Hbf|Mannheim Handelshafen|Mannheim-Neckarstadt|Mannheim-Luzenberg|Mannheim-Waldhof|Lampertheim|Bürstadt|Bobstadt|Biblis|Groß Rohrheim|Gernsheim|Biebesheim|Stockstadt(Rhein)|Riedstadt-Goddelau|Riedstadt-Wolfskehlen|Groß Gerau-Dornheim|Groß Gerau-Dornberg|Mörfelden|Walldorf(Hess)|Zeppelinheim|Frankfurt am Main - Stadion|Frankfurt-Niederrad" pt="1902150125"/>
</s>
<s id="6043103556626132504-1902150038-9">
<tl c="Bus" n="685" o="B4" t="p"/>
<ar l="SEV" pp="" ppth="Groß Karben|Dortelweil|Bad Vilbel|Bad Vilbel Süd|Frankfurt-Berkersheim|Frankfurt-Frankfurter Berg|Frankfurt-Eschersheim|Frankfurt(Main)West" pt="1902150152"/>
</s>
<s id="-7222985882761989487-1902150105-13">
<tl c="S" f="S" n="35195" o="800528" t="p"/>
<ar l="1" pp="20" ppth="Wiesbaden Hbf|Wiesbaden Ost|Mainz-Kastel|Hochheim(Main)|Flörsheim(Main)|Eddersheim|Hattersheim(Main)|Frankfurt-Sindlingen|Frankfurt-Höchst Farbwerke|Frankfurt-Höchst|Frankfurt-Nied|Frankfurt-Griesheim" pt="1902150149"/>
</s>
<s id="1931688278438632918-1902150115-1">
<tl c="Bus" n="686" o="B4" t="p"/>
<dp l="SEV" pp="" ppth="Frankfurt(Main)West|Frankfurt-Eschersheim|Frankfurt-Frankfurter Berg|Frankfurt-Berkersheim|Bad Vilbel Süd|Bad Vilbel|Dortelweil|Groß Karben|Okarben|Nieder Wöllstadt|Bruchenbrücken|Friedberg(Hess)" pt="1902150115"/>
</s>
<s id="7217092419963954024-1902142223-24">
<tl c="RE" f="N" n="4169" o="8005MW" t="p"/>
<ar l="30" pp="14" ppth="Kassel Hbf|Kassel-Wilhelmshöhe|Edermünde-Grifte|Felsberg-Gensungen|Wabern(Bz Kassel)|Borken(Hess)|Treysa|Neustadt(Kr Marburg)|Stadtallendorf|Kirchhain(Bz Kassel)|Marburg(Lahn)|Marburg Süd|Niederwalgern|Fronhausen(Lahn)|Lollar|Gießen|Großen Linden|Lang Göns|Butzbach|Bad Nauheim|Friedberg(Hess)|Hanau Hbf|Frankfurt(Main)Süd" pt="1902150115"/>
</s>
<s id="-7391468104191938601-1902150030-10">
<tl c="S" f="S" n="35786" o="800528" t="p"/>
<ar l="7" pp="21" ppth="Riedstadt-Goddelau|Riedstadt-Wolfskehlen|Groß Gerau-Dornheim|Groß Gerau-Dornberg|Mörfelden|Walldorf(Hess)|Zeppelinheim|Frankfurt am Main - Stadion|Frankfurt-Niederrad" pt="1902150106"/>
</s>
</timetable>
<?xml version="1.0" ?>
<timetable station="Frankfurt(Main)Hbf">
<s id="-5936166140252434835-1902141838-18">
<tl c="IC" f="F" n="209" o="80" t="p"/>
<ar pp="18" ppth="Kiel Hbf|Neumünster|Hamburg Dammtor|Hamburg Hbf|Hamburg-Harburg|Bremen Hbf|Osnabrück Hbf|Münster(Westf)Hbf|Dortmund Hbf|Essen Hbf|Duisburg Hbf|Düsseldorf Hbf|Köln Hbf|Bonn Hbf|Koblenz Hbf|Mainz Hbf|Frankfurt(M) Flughafen Fernbf" pt="1902150232"/>
<dp pp="18" ppth="Mannheim Hbf|Karlsruhe Hbf|Baden-Baden|Offenburg|Freiburg(Breisgau) Hbf|Basel Bad Bf|Basel SBB" pt="1902150248"/>
</s>
</timetable>
<?xml version="1.0" ?>
<timetable station="Frankfurt(Main)Hbf">
<s id="3777729162778341596-1902142313-10">
<tl c="IC" f="F" n="208" o="80" t="p"/>
<ar pp="19" ppth="Basel SBB|Basel Bad Bf|Freiburg(Breisgau) Hbf|Offenburg|Baden-Baden|Karlsruhe Hbf|Bruchsal|Heidelberg Hbf|Mannheim Hbf" pt="1902150302"/>
<dp pp="19" ppth="Frankfurt(M) Flughafen Fernbf|Mainz Hbf|Koblenz Hbf|Andernach|Bonn Hbf|Köln Hbf|Düsseldorf Hbf|Duisburg Hbf|Essen Hbf|Bochum Hbf|Dortmund Hbf|Münster(Westf)Hbf|Osnabrück Hbf|Bremen Hbf|Hamburg-Harburg|Hamburg Hbf|Hamburg Dammtor|Neumünster|Kiel Hbf" pt="1902150308"/>
</s>
</timetable>
<?xml version="1.0" ?>
<timetable station="Frankfurt(Main)Hbf">
<s id="-4864632360692933117-1902150409-4">
<tl c="S" f="S" n="35103" o="800528" t="p"/>
<ar l="1" pp="20" ppth="Frankfurt-Höchst|Frankfurt-Nied|Frankfurt-Griesheim" pt="1902150422"/>
</s>
<s id="2591693937844576022-1902150431-1">
<tl c="S" f="S" n="35902" o="800528" t="p"/>
<dp l="9" pp="21" ppth="Frankfurt-Niederrad|Frankfurt am Main - Stadion|Frankfurt(M) Flughafen Regionalbf|Kelsterbach" pt="1902150431"/>
</s>
<s id="3043602280117062815-1902150450-1">
<tl c="RB" f="N" n="28601" o="K4RB" t="p"/>
<dp l="58" pp="5" ppth="Frankfurt(Main)Süd|Frankfurt(Main)Ost|Frankfurt-Mainkur|Maintal West|Maintal Ost|Hanau-Wilhelmsbad|Hanau West|Hanau Hbf|Großauheim(Kr Hanau)|Großkrotzenburg|Kahl(Main)|Dettingen(Main)|Rückersbacher Schlucht|Kleinostheim|Aschaffenburg Hbf" pt="1902150450"/>
</s>
<s id="-2823022471268153872-1902150450-1">
<tl c="S" f="S" n="35707" o="800528" t="p"/>
<dp l="7" pp="2" ppth="Frankfurt-Niederrad|Frankfurt am Main - Stadion|Zeppelinheim|Walldorf(Hess)|Mörfelden|Groß Gerau-Dornberg|Groß Gerau-Dornheim|Riedstadt-Wolfskehlen|Riedstadt-Goddelau" pt="1902150450"/>
</s>
<s id="7130605216857004791-1902150319-7">
<tl c="ICE" f="F" n="827" o="80" t="p"/>
<ar pp="13" ppth="Köln Hbf|Köln/Bonn Flughafen|Siegburg/Bonn|Montabaur|Limburg Süd|Frankfurt(M) Flughafen Fernbf" pt="1902150448"/>
<dp pp="13" ppth="Aschaffenburg Hbf|Würzburg Hbf|Nürnberg Hbf|Ingolstadt Hbf|München Hbf" pt="1902150454"/>
</s>
<s id="6289938859164500858-1902150440-1">
<tl c="RB" f="N" n="15500" o="8005KG" t="p"/>
<dp l="51" pp="8" ppth="Frankfurt(Main)Süd|Offenbach(Main)Hbf|Hanau Hbf|Wolfgang(Kr Hanau)|Rodenbach(b Hanau)|Langenselbold|Niedermittlau|Hailer-Meerholz|Gelnhausen|Haitz-Höchst|Wirtheim|Wächtersbach" pt="1902150440"/>
</s>
<s id="8605774015432509832-1902150400-10">
<tl c="S" f="S" n="35704" o="800528" t="p"/>
<ar l="7" pp="2" ppth="Riedstadt-Goddelau|Riedstadt-Wolfskehlen|Groß Gerau-Dornheim|Groß Gerau-Dornberg|Mörfelden|Walldorf(Hess)|Zeppelinheim|Frankfurt am Main - Stadion|Frankfurt-Niederrad" pt="1902150436"/>
</s>
<s id="2539283208056266937-1902150414-4">
<tl c="RE" f="N" n="28696" o="K4RE" t="p"/>
<ar l="59" pp="5" ppth="Hanau Hbf|Offenbach(Main)Hbf|Frankfurt(Main)Süd" pt="1902150438"/>
</s>
<s id="-5526423918324731832-1902150433-1">
<tl c="RE" f="N" n="4551" o="800574" t="p"/>
<dp l="70" pp="17" ppth="Frankfurt-Niederrad|Frankfurt am Main - Stadion|Zeppelinheim|Walldorf(Hess)|Mörfelden|Groß Gerau-Dornberg|Groß Gerau-Dornheim|Riedstadt-Wolfskehlen|Riedstadt-Goddelau|Stockstadt(Rhein)|Biebesheim|Gernsheim|Groß Rohrheim|Biblis|Bobstadt|Bürstadt|Lampertheim|Mannheim-Waldhof|Mannheim-Luzenberg|Mannheim-Neckarstadt|Mannheim Handelshafen|Mannheim Hbf" pt="1902150433"/>
</s>
</timetable>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
from datetime import datetime
import requests
import os
import sys
import time
import xml.dom.minidom
db_api_key = ""
with open("dbapi.token", "r") as f:
db_api_key = f.read()
eva = sys.argv[1]
now = datetime.now()
now_str = now.strftime("%y%m%d")
print(db_api_key)
print(eva)
for t in map(lambda x: str(x).rjust(2, '0'), range(0, 24)):
print(f'Get {eva} for time {t}')
r = requests.get(f'https://api.deutschebahn.com/timetables/v1/plan/{eva}/{now_str}/{t}', headers = {
'Accept': 'application/xml',
'Authorization': f'Bearer {db_api_key}'
})
os.makedirs('{eva}/{now_str}', exist_ok=True)
with open(f'{eva}/{now_str}/{t}.xml', 'w') as f:
dom = xml.dom.minidom.parseString(r.text)
f.write(dom.toprettyxml())
time.sleep(3) # rate limit
package de.codecentric.amuttsch.bahndelayinfo
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder
import com.amazonaws.services.ec2.model.DescribeNetworkInterfacesRequest
import com.amazonaws.services.ecs.AmazonECSClientBuilder
import com.amazonaws.services.ecs.model.{DescribeTasksRequest, ListTasksRequest}
import scala.collection.JavaConverters._
package object awstest {
def getMockServerIp(): String = {
val attachmentsDetails = getRunningMockServerTasks().head.getAttachments.get(0).getDetails.asScala
val networkInterfaceId = attachmentsDetails.find(kvp => kvp.getName == "networkInterfaceId").get
getIpForNetworkInterfaceId(networkInterfaceId.getValue)
}
private def getIpForNetworkInterfaceId(networkInterfaceId: String): String = {
val client = AmazonEC2ClientBuilder.standard.build
val request = new DescribeNetworkInterfacesRequest()
.withNetworkInterfaceIds(networkInterfaceId)
val describeNetworkInterfaceResponse = client.describeNetworkInterfaces(request)
describeNetworkInterfaceResponse.getNetworkInterfaces.get(0).getAssociation.getPublicIp
}
private def getRunningMockServerTasks(): List[com.amazonaws.services.ecs.model.Task] = {
val client = AmazonECSClientBuilder.standard.build
val res = client.listTasks(new ListTasksRequest().withCluster("mockserver-cluster"))
if (res.getTaskArns.isEmpty) {
List.empty
} else {
val tasks = client.describeTasks(new DescribeTasksRequest()
.withCluster("mockserver-cluster")
.withTasks(res.getTaskArns)
)
tasks.getTasks.asScala
.filter(_.getStartedBy == "sbt")
.filter(_.getLastStatus == "RUNNING")
.toList
}
}
}
package de.codecentric.amuttsch.bahndelayinfo.fetcher
import java.net.URI
import com.softwaremill.sttp._
import de.codecentric.amuttsch.bahndelayinfo.models.TimetableInformation
class DBChangedTimetableFetcher extends DBFetcher {
override def fetchUrl(ttr: TimetableRequest): Uri = {
uri"$baseApiUrl/timetables/v1/rchg/${ttr.eva}"
Uri(new URI(s"$baseApiUrl/timetables/v1/rchg/${ttr.eva}"))
}
override def fetchTimetablesForEvas(evaToFetch: List[String]): Seq[TimetableInformation] = {
......
package de.codecentric.amuttsch.bahndelayinfo.fetcher
import java.text.SimpleDateFormat
import java.util.Calendar
import java.net.URI
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import com.softwaremill.sttp._
import de.codecentric.amuttsch.bahndelayinfo.models.TimetableInformation
......@@ -9,18 +10,17 @@ import de.codecentric.amuttsch.bahndelayinfo.models.TimetableInformation
class DBPlannedTimetableFetcher extends DBFetcher {
override def fetchUrl(ttr: TimetableRequest): Uri = {
uri"$baseApiUrl/timetables/v1/plan/${ttr.eva}/${ttr.date}/${ttr.hour}"
Uri(new URI(s"$baseApiUrl/timetables/v1/plan/${ttr.eva}/${ttr.date}/${ttr.hour}"))
}
override def fetchTimetablesForEvas(evaToFetch: List[String]): Seq[TimetableInformation] = {
val now = Calendar.getInstance().getTime
val timetableDateFormat = new SimpleDateFormat("YYMMdd")
val format = DateTimeFormatter.ofPattern("YYMMdd")
var timetables = Seq.empty[TimetableInformation]
evaToFetch.foreach { eva =>
val timetableRequests = (0 to 23).map { hour =>
val formattedDate = timetableDateFormat.format(now)
val formattedDate = LocalDate.now.format(format)
val formattedHour = f"$hour%02d"
TimetableRequest(eva, formattedDate, formattedHour)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment