Browse Source

Initial commit

tags/Beta
Janis 7 months ago
commit
52225e516a
10 changed files with 110 additions and 0 deletions
  1. +6
    -0
      .gitignore
  2. +0
    -0
      README.md
  3. +15
    -0
      src/app/pott/kaffeepott/collector/Constants.kt
  4. +3
    -0
      src/app/pott/kaffeepott/collector/core/LatLng.kt
  5. +3
    -0
      src/app/pott/kaffeepott/collector/core/LatLngBounds.kt
  6. +7
    -0
      src/app/pott/kaffeepott/collector/core/Main.kt
  7. +29
    -0
      src/app/pott/kaffeepott/collector/osmweb/DBAdapter.kt
  8. +21
    -0
      src/app/pott/kaffeepott/collector/osmweb/QueryBuilder.kt
  9. +11
    -0
      src/app/pott/kaffeepott/collector/osmweb/ResultParser.kt
  10. +15
    -0
      src/app/pott/kaffeepott/collector/reporter/Ticket.kt

+ 6
- 0
.gitignore View File

@@ -0,0 +1,6 @@
.idea/
.classpath
.project
*.iml
lib/
out/

+ 0
- 0
README.md View File


+ 15
- 0
src/app/pott/kaffeepott/collector/Constants.kt View File

@@ -0,0 +1,15 @@
package app.pott.kaffeepott.collector

import java.nio.charset.StandardCharsets

class Constants {
object OSMConstants {
const val SCHEME = "http"
const val DOMAIN = "overpass-api.de"
const val PORT = 80
const val PATH = "/api/interpreter"
const val QUERY = "data="

const val CHARSET = "UTF-8"
}
}

+ 3
- 0
src/app/pott/kaffeepott/collector/core/LatLng.kt View File

@@ -0,0 +1,3 @@
package app.pott.kaffeepott.collector.core

class LatLng(val lat: Double, val lon: Double)

+ 3
- 0
src/app/pott/kaffeepott/collector/core/LatLngBounds.kt View File

@@ -0,0 +1,3 @@
package app.pott.kaffeepott.collector.core

class LatLngBounds(val southWest: LatLng, val northEast: LatLng)

+ 7
- 0
src/app/pott/kaffeepott/collector/core/Main.kt View File

@@ -0,0 +1,7 @@
package app.pott.kaffeepott.collector.core

import app.pott.kaffeepott.collector.osmweb.DBAdapter

fun main() {
DBAdapter().query(LatLngBounds(LatLng(50.6, 7.0), LatLng(50.8, 7.3)))
}

+ 29
- 0
src/app/pott/kaffeepott/collector/osmweb/DBAdapter.kt View File

@@ -0,0 +1,29 @@
package app.pott.kaffeepott.collector.osmweb

import app.pott.kaffeepott.collector.Constants
import app.pott.kaffeepott.collector.core.LatLngBounds
import app.pott.kaffeepott.collector.reporter.Ticket
import java.io.BufferedReader
import java.io.IOException
import java.net.HttpURLConnection
import java.nio.charset.Charset
import kotlin.collections.ArrayList

class DBAdapter {

private val queryBuilder = QueryBuilder()
private val resultParser = ResultParser()

fun query(area: LatLngBounds, amenity: String = "cafe"): List<Ticket> {
val connection = queryBuilder.buildQuery(area, amenity).openConnection() as HttpURLConnection
connection.requestMethod = "GET"
return try {
resultParser.parse(connection.inputStream.bufferedReader(Charset.forName(Constants.OSMConstants.CHARSET)).use(BufferedReader::readText))
} catch (ioException: IOException) {
ioException.printStackTrace()
ArrayList()
}
}


}

+ 21
- 0
src/app/pott/kaffeepott/collector/osmweb/QueryBuilder.kt View File

@@ -0,0 +1,21 @@
package app.pott.kaffeepott.collector.osmweb

import app.pott.kaffeepott.collector.Constants
import app.pott.kaffeepott.collector.core.LatLngBounds
import java.net.URL
import java.net.URI
import java.net.URLEncoder

class QueryBuilder {

fun buildQuery(area: LatLngBounds, amenity: String): URL {
return URI(Constants.OSMConstants.SCHEME, null, Constants.OSMConstants.DOMAIN,
Constants.OSMConstants.PORT, Constants.OSMConstants.PATH, Constants.OSMConstants.QUERY +
getQuery(area, amenity), null).toURL()
}

private fun getQuery(area: LatLngBounds, amenity: String): String {
return "[bbox:" + area.southWest.lat + "," + area.southWest.lon + "," +
area.northEast.lat + "," + area.northEast.lon + "];node[\"amenity\"=\"" + amenity + "\"];out;"
}
}

+ 11
- 0
src/app/pott/kaffeepott/collector/osmweb/ResultParser.kt View File

@@ -0,0 +1,11 @@
package app.pott.kaffeepott.collector.osmweb

import app.pott.kaffeepott.collector.reporter.Ticket

class ResultParser {

fun parse(xml: String): List<Ticket> {
println(xml)
return ArrayList()
}
}

+ 15
- 0
src/app/pott/kaffeepott/collector/reporter/Ticket.kt View File

@@ -0,0 +1,15 @@
package app.pott.kaffeepott.collector.reporter

import app.pott.kaffeepott.collector.core.LatLng

class Ticket {
private val badges: List<String>?
private val name: String
private val location: LatLng

constructor(badges: List<String>?, name: String, location: LatLng) {
this.badges = badges
this.name = name
this.location = location
}
}

Loading…
Cancel
Save