Last active
August 26, 2016 08:02
-
-
Save truongngoclinh/aaa06de1aa9a89c42401584905e44ecf to your computer and use it in GitHub Desktop.
Searching pokemon around your work desk and get notifies by specific pokemons
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
import POGOProtos.Enums.PokemonIdOuterClass; | |
import com.pokegoapi.api.PokemonGo; | |
import com.pokegoapi.api.map.pokemon.CatchablePokemon; | |
import com.pokegoapi.api.map.pokemon.NearbyPokemon; | |
import com.pokegoapi.auth.GoogleUserCredentialProvider; | |
import com.pokegoapi.exceptions.LoginFailedException; | |
import com.pokegoapi.exceptions.RemoteServerException; | |
import okhttp3.OkHttpClient; | |
import java.io.IOException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.LinkedList; | |
import java.util.List; | |
/** | |
* Wrote by LeoLink on 8/24/16. | |
* <p> | |
* | |
* References: | |
* | |
* -- To get access token: | |
* https://accounts.google.com/o/oauth2/auth?client_id=848232511240-73ri3t7plvk96pj4f85uj8otdat2alem.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=openid%20email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email | |
* -- Scanning | |
* Why the scan radius is so small and why was PokeVision running better. - http://www.twitlonger.com/show/n_1sp0ss3 | |
* -- Mac notifier | |
* https://github.com/julienXX/terminal-notifier | |
*/ | |
public class Main { | |
// LOGIN STUFF | |
private static final String LOGIN_URL = GoogleUserCredentialProvider.LOGIN_URL; | |
private static final String ACCESS_TOKEN = ""; | |
private static final String REFRESH_TOKEN = "1/Yiicciga-IyJ2DsAli5zfx_4XreOSkU_tFTnmxKdwJc"; | |
// SCAN STUFF | |
enum Place { | |
MY_DESK(35.611285, 139.629402), | |
WORK_IN_FRONT_OF_TRAIN_STATION(35.611957, 139.626928), | |
WORK_BUS_STATION(35.611775, 139.629103), | |
WORK_BETWEEN_STATION_AND_BUS(35.612397, 139.627890), | |
WORK_MY_SEAT(35.611139, 139.629338), | |
WORK_CAR_PARK(35.610637, 139.632373); | |
public double lat; | |
public double lon; | |
Place(double lat, double lon) { | |
this.lat = lat; | |
this.lon = lon; | |
} | |
} | |
private static final long SCAN_INTERVAL = 13000; // 15 secs | |
private static final List<PokemonIdOuterClass.PokemonId> NEEDED_POKEMON = new LinkedList<PokemonIdOuterClass.PokemonId>(); | |
static { | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.SQUIRTLE); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.WARTORTLE); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.BLASTOISE); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.CHARMANDER); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.CHARMELEON); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.CHARIZARD); | |
// NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.BULBASAUR); | |
// NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.IVYSAUR); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.VENUSAUR); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.GROWLITHE); | |
// NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.EXEGGCUTE); | |
// NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.EXEGGUTOR); | |
NEEDED_POKEMON.add(PokemonIdOuterClass.PokemonId.PORYGON); | |
} | |
public static void main(String[] args) throws LoginFailedException, RemoteServerException, InterruptedException { | |
OkHttpClient httpClient = new OkHttpClient(); | |
GoogleUserCredentialProvider provider = new GoogleUserCredentialProvider(httpClient, REFRESH_TOKEN); | |
System.out.println("Refresh token:" + provider.getRefreshToken()); | |
PokemonGo go = new PokemonGo(provider, httpClient); | |
while (true) { | |
for (Place place : Place.values()) { | |
System.out.printf("\n\n%s - https://www.google.co.jp/maps/place/%f,%f - https://fastpokemap.se/#%f,%f\n", | |
place.toString(), place.lat, place.lon, place.lat, place.lon); | |
go.setLocation(place.lat, place.lon, 1); | |
// nearby | |
Thread.sleep(SCAN_INTERVAL); | |
List<NearbyPokemon> nearbyPokemons = go.getMap().getNearbyPokemon(); | |
for (NearbyPokemon pokemon : nearbyPokemons) { | |
System.out.println(place + " - NEARBY: " + pokemon.getPokemonId()); | |
if (NEEDED_POKEMON.contains(pokemon.getPokemonId())) | |
notify(place, "nearby", pokemon.getPokemonId()); | |
} | |
// catchable | |
Thread.sleep(SCAN_INTERVAL); | |
List<CatchablePokemon> catchablePokemons = go.getMap().getCatchablePokemon(); | |
for (CatchablePokemon pokemon : catchablePokemons) { | |
System.out.println(place + " - CATCHABLE: " + pokemon.getPokemonId()); | |
if (place == Place.MY_DESK || NEEDED_POKEMON.contains(pokemon.getPokemonId())) | |
notify(place, "at", pokemon.getPokemonId()); | |
} | |
} | |
} | |
} | |
private static void notify(Place place, String prefix, PokemonIdOuterClass.PokemonId pokemon) throws InterruptedException { | |
Thread.sleep(500); | |
String message = new SimpleDateFormat("HH:mm:ss").format(new Date()) + " - " + pokemon.toString() + " is " + prefix + " " + place; | |
String mapLink = "http://fastpokemap.se/#" + place.lat + "," + place.lon; | |
System.out.println("\t" + message); | |
String[] commands = {"/usr/local/bin/terminal-notifier", "-message", message, "-title", "PokemonGo Scanner", "-open", mapLink}; | |
try { | |
Runtime.getRuntime().exec(commands); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void getRefreshToken() throws LoginFailedException, RemoteServerException { | |
OkHttpClient httpClient = new OkHttpClient(); | |
GoogleUserCredentialProvider provider = new GoogleUserCredentialProvider(httpClient); | |
provider.login(ACCESS_TOKEN); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
api from: https://github.com/Grover-c13/PokeGOAPI-Java