Skip to content

Instantly share code, notes, and snippets.

@nevack
Last active October 10, 2019 09:06
Show Gist options
  • Save nevack/e72400015431b6b1e2db53c1d00ca964 to your computer and use it in GitHub Desktop.
Save nevack/e72400015431b6b1e2db53c1d00ca964 to your computer and use it in GitHub Desktop.
import com.beust.klaxon.Klaxon
import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.result.Result
data class PapaJohnsContainer (
val codes: List<PapaJohnsCode>
)
data class PapaJohnsCode (
val name: String,
val code: String
)
var skipRow = false
var beforePrice = 100.0
fun main(args: Array<String>) {
if (args.isNotEmpty())
{
skipRow = args[0].toBoolean()
beforePrice = args[1].toDouble()
}
val (_, _, result) = "https://www.papajohns.by/api/stock/codes".httpGet().responseString()
if (result is Result.Success)
{
val list = Klaxon().parse<PapaJohnsContainer>(result.value)
if (list != null) {
for (x in list.codes) {
if (!x.name.contains("-")) continue
val item = x.name.split("-")
val condition = item[3]
val price = condition.substring(4, 9).toDouble()
if (price > beforePrice) continue
val good = item[2].replace("ТРАД", "см на традиционном тесте")
.replace("ТОНК", "см на тонком тесте")
print(x.code.toUpperCase().padEnd(13))
println(":${condition.padEnd(20)}->$good")
if (skipRow) println()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment