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 8 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 @@ -61,6 +61,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 @@ -193,6 +193,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 @@ -68,6 +68,8 @@
"useLuckyEgg" : 1,
"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 @@ -96,10 +96,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
5 changes: 4 additions & 1 deletion src/main/kotlin/ink/abb/pogo/scraper/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package ink.abb.pogo.scraper
import com.google.common.util.concurrent.AtomicDouble
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 @@ -39,6 +40,8 @@ data class Context(

val walking: AtomicBoolean = AtomicBoolean(false),

val pauseWalking: AtomicBoolean = AtomicBoolean(false)
val pauseWalking: AtomicBoolean = AtomicBoolean(false),

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

)
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 @@ -123,6 +123,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 @@ -262,6 +266,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
3 changes: 1 addition & 2 deletions 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 All @@ -53,7 +52,7 @@ class SocketServer {
run {
if (data.lat != null && data.lng != null) {
val coord = S2LatLng.fromRadians(data.lat!!, data.lng!!)
coordinatesToGoTo.add(coord)
ctx.coordinatesToGoTo.add(coord)
}
}
}
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--
}
}
}
7 changes: 4 additions & 3 deletions src/main/kotlin/ink/abb/pogo/scraper/tasks/Walk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class Walk(val sortedPokestops: List<Pokestop>, val lootTimeouts: Map<String, Lo
return
}

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

walk(bot, ctx, settings, S2LatLng.fromDegrees(coordinates.latRadians(), coordinates.lngRadians()), settings.speed, true)
Expand Down