-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa27f9a
commit 05ffa2d
Showing
2 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
core/data/src/main/kotlin/xyz/ksharma/krail/data/gtfs_static/parser/AgencyParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package xyz.ksharma.krail.data.gtfs_static.parser | ||
|
||
import timber.log.Timber | ||
import xyz.ksharma.krail.model.gtfs_static.Agency | ||
import java.io.BufferedReader | ||
import java.io.FileReader | ||
import java.io.IOException | ||
import java.nio.file.Path | ||
|
||
object AgencyParser { | ||
|
||
internal fun Path.parseAgency(): List<Agency> { | ||
val agencyList = mutableListOf<Agency>() | ||
|
||
try { | ||
BufferedReader(FileReader(this.toString())).use { reader -> | ||
val headersList = reader.readLine().split(",").trimQuotes() | ||
// todo use headers instead of hard code later. | ||
//Log.d(TAG, "headersList: $headersList") | ||
|
||
while (true) { | ||
val line = reader.readLine() ?: break | ||
val fieldsList = line.split(",").trimQuotes() | ||
|
||
agencyList.add( | ||
Agency( | ||
agencyId = fieldsList[0], | ||
agencyName = fieldsList[1], | ||
agencyUrl = fieldsList[2], | ||
agencyTimezone = fieldsList[3], | ||
agencyLang = fieldsList[4], | ||
agencyPhone = fieldsList[5], | ||
) | ||
) | ||
} | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
Timber.e(e, "parseCalendar: ") | ||
} catch (e: IllegalArgumentException) { | ||
e.printStackTrace() | ||
Timber.e(e, "parseCalendar: ") | ||
} | ||
|
||
return agencyList | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters