Skip to content

Instantly share code, notes, and snippets.

@zhusee2
Created August 9, 2016 04:12
Show Gist options
  • Save zhusee2/931640438ff8ccb7cb4698c2b97b6f9e to your computer and use it in GitHub Desktop.
Save zhusee2/931640438ff8ccb7cb4698c2b97b6f9e to your computer and use it in GitHub Desktop.
Find nearby catchable Pokémons
import pogobuf from 'pogobuf';
import POGOProtos from 'node-pogo-protos';
import chalk from 'chalk';
const USERNAME = '__YOUR_USERNAME__';
const PASSWORD = '__YOUR_PASSWORD__';
// 捷運西門站6號出口
const LAT = 25.0432504;
const LNG = 121.5081401;
const REFRESH_TIME_MS = 30 * 1000;
const clearConsole = () => process.stdout.write('\x1bc');
const ptcLogin = new pogobuf.PTCLogin();
const client = new pogobuf.Client();
ptcLogin.login(USERNAME, PASSWORD)
.then((token) => {
client.setAuthInfo('ptc', token);
client.setPosition(LAT, LNG);
client.init();
})
.then(() => {
let lastTimestamp = Date.now();
console.log('已登入,等待第一次地圖搜尋 (30s)');
global.setInterval(() => {
const cellIDs = pogobuf.Utils.getCellIDs(LAT, LNG);
const sinceTimestamps = Array(cellIDs.length).fill(lastTimestamp);
const dateString = (new Date()).toString();
clearConsole();
console.log(chalk.green(dateString));
client.getMapObjects(cellIDs, sinceTimestamps)
.then(mapObjects => mapObjects.map_cells)
.then(mapCells => mapCells.forEach((cell) => {
cell.catchable_pokemons.forEach((pokemon) => {
const pokemonName = pogobuf.Utils.getEnumKeyByValue(
POGOProtos.Enums.PokemonId,
pokemon.pokemon_id
);
console.log(` - 附近有一隻 ${pokemonName}!`);
});
}));
lastTimestamp = Date.now();
}, REFRESH_TIME_MS);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment