Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Add GPX support #1008

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "com.corundumstudio.socketio:netty-socketio:1.7.7"

compile group: 'org.jdom', name: 'jdom', version: '2.0.0'


compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-undertow'
Expand Down
5 changes: 5 additions & 0 deletions config.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ export=
# Initial map size (S2 tiles) to fetch (max. 9: ~3*3km area)
initial_map_size=9

# GPX file to be added on the bot's start
gpx_file=
# Number of times the bot must repeat this GPX file
gpx_repeat=-1

# For artificial pauses/rests
# Chance to wait randomly at a pokestop in %, recommended about 10 or less, default disabled
wait_chance=0.0
Expand Down
2 changes: 2 additions & 0 deletions json-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"evolveTimeDelay" : 300,
"export" : "",
"guiPortSocket" : 8001,
"gpxFile": "",
"gpxRepeat": -1,
"initialMapSize" : 9,
"waitChance" : 0.0,
"waitTimeMin" : 0,
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ class Bot(val api: PokemonGo, val settings: Settings) {
val evolve = EvolvePokemon()
val hatchEggs = HatchEggs()
val export = Export()
val readGpx = ReadGpx()

if (settings.export.length > 0)
task(export)

task(readGpx)

task(keepalive)
Log.normal("Getting initial pokestops...")

Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.google.common.util.concurrent.AtomicDouble
import com.google.maps.GeoApiContext
import com.pokegoapi.api.PokemonGo
import com.pokegoapi.api.player.PlayerProfile
import com.pokegoapi.google.common.geometry.S2LatLng
import ink.abb.pogo.scraper.gui.SocketServer
import java.time.LocalDateTime
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -45,5 +46,7 @@ data class Context(

val pauseWalking: AtomicBoolean = AtomicBoolean(false),

val coordinatesToGoTo: MutableList<S2LatLng> = mutableListOf<S2LatLng>()

val geoApiContext: GeoApiContext?
)
7 changes: 7 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ class SettingsParser(val properties: Properties) {

guiPortSocket = getPropertyIfSet("Port where the socketserver should listen", "gui_port_socket", defaults.guiPortSocket, String::toInt),

gpxFile = getPropertyIfSet("GPX file that the bot will follow", "gpx_file", defaults.gpxFile, String::toString),

gpxRepeat = getPropertyIfSet("Number of time that the GPX file will be repeated", "gpx_repeat", defaults.gpxRepeat, String::toInt),

restApiPassword = getPropertyIfSet("REST API password for the bot", "rest_api_password", defaults.restApiPassword, String::toString),

initialMapSize = getPropertyIfSet("Initial map size (S2 tiles) to fetch", "initial_map_size", defaults.initialMapSize, String::toInt),
Expand Down Expand Up @@ -289,6 +293,9 @@ data class Settings(

var initialMapSize: Int = 9,

var gpxFile: String = "",
var gpxRepeat: Int = -1,

val version: String = Settings.version,

val waitChance: Double = 0.0,
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/ink/abb/pogo/scraper/gui/SocketServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class SocketServer {
private var ctx: Context? = null
private var server: SocketIOServer? = null

val coordinatesToGoTo = mutableListOf<S2LatLng>()

fun start(ctx: Context, port: Int) {
val config = Configuration()
Expand Down
47 changes: 47 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/tasks/ReadGpx.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ink.abb.pogo.scraper.tasks

import com.pokegoapi.google.common.geometry.S2LatLng
import ink.abb.pogo.scraper.Bot
import ink.abb.pogo.scraper.Context
import ink.abb.pogo.scraper.Settings
import ink.abb.pogo.scraper.Task
import ink.abb.pogo.scraper.util.Log
import org.jdom2.Document

import org.jdom2.input.SAXBuilder
import java.io.File

/**
* Created by Peyphour on 8/11/16.
*/

class ReadGpx : Task {
override fun run(bot: Bot, ctx: Context, settings: Settings) {

var builder: SAXBuilder = SAXBuilder()
var document: Document
try {
document = builder.build(File(settings.gpxFile))
} catch(e: Exception) {
// Invalid file or no file specified : Expected behaviour
return
}

val coords = document.rootElement.getChild("trk", document.rootElement.namespace)
.getChild("trkseg", document.rootElement.namespace)

var i: Int = settings.gpxRepeat

Log.green("GPX plugin : reading file " + settings.gpxFile + " with $i repeats")

// gpxRepeat == 0 or -1 : No coordinates will be added
while(i > 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe put this in a task to add the next iteration when the previous ended. That way an "infinite" option is possible in a "clean" way (instead of adding your route eg "99999" times, which can be very memory intensive)

for (element in coords.children)
ctx.coordinatesToGoTo.add(S2LatLng.fromRadians(
element.getAttribute("lat").doubleValue,
element.getAttribute("lon").doubleValue
))
i--
}
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/ink/abb/pogo/scraper/tasks/Walk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ class Walk(val sortedPokestops: List<Pokestop>, val lootTimeouts: Map<String, Lo
if (!ctx.walking.compareAndSet(false, true)) {
return
}

if (ctx.server.coordinatesToGoTo.size > 0) {
val coordinates = ctx.server.coordinatesToGoTo.first()
ctx.server.coordinatesToGoTo.removeAt(0)
Log.normal("Using supplied coordinate, number of remaining points : " + ctx.coordinatesToGoTo.size)
Log.normal("Walking to ${coordinates.latDegrees()}, ${coordinates.lngDegrees()}")

walk(bot, ctx, settings, coordinates, settings.speed, true, null)
} else {
val nearestUnused: List<Pokestop> = sortedPokestops.filter {
Expand Down