Skip to content

Commit

Permalink
Merge branch 'master' into coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
modrzew committed Aug 12, 2016
2 parents e8a8bc0 + 622a4a9 commit 668e2e3
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ db.sqlite
*.log
templates/footer.html
*.so
*.dll
*.dylib
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ And here are workers together with their area of scan:

[/u/gprez](https://www.reddit.com/u/gprez) made [a great tutorial on Reddit](https://www.reddit.com/r/pokemongodev/comments/4tz66s/pokeminer_your_individual_pokemon_locations/d5lovb6). Check it out if you're not accustomed with Python applications.

Note: Pokeminer works best with Python 3.5. Python 2.7 is supported **for time being** and I plan on moving away from it. Seriously, it's 2016, Python 2.7 hasn't been developed for 6 years, why don't you upgrade already?

Create the database by running Python interpreter. Note that if you want more than 10 workers simultaneously running, SQLite is probably not the best choice.

```py
Expand Down
1 change: 1 addition & 0 deletions config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MAP_END = (13.4567, 35.6789)
GRID = (2, 2) # row, column
CYCLES_PER_WORKER = 3
SCAN_DELAY = 10 # seconds
PROXIES = None # Insert dictionary with 'http' and 'https' keys to enable

SCAN_RADIUS = 70 # metres

Expand Down
8 changes: 4 additions & 4 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ class Sighting(Base):
expire_timestamp = Column(Integer, index=True)
encounter_id = Column(String(32))
normalized_timestamp = Column(Integer)
lat = Column(String(16), index=True)
lon = Column(String(16), index=True)
lat = Column(String(20), index=True)
lon = Column(String(20), index=True)


class Fort(Base):
__tablename__ = 'forts'

id = Column(Integer, primary_key=True)
external_id = Column(String(64), unique=True)
lat = Column(String(16), index=True)
lon = Column(String(16), index=True)
lat = Column(String(20), index=True)
lon = Column(String(20), index=True)

sightings = relationship(
'FortSighting',
Expand Down
7 changes: 5 additions & 2 deletions gyms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ def get_stats():
prestige[team] += fort['prestige']
total_prestige = sum(prestige.values())
for team in db.Team:
percentages[team.value] = count.get(team.value) / len(forts) * 100
# TODO: remove float(...) as soon as we move to Python 3
percentages[team.value] = (
count.get(team.value) / float(len(forts)) * 100
)
prestige_percent[team.value] = (
prestige.get(team.value) / total_prestige * 100
prestige.get(team.value) / float(total_prestige) * 100
)
if guardians[team.value]:
pokemon_id = sorted(
Expand Down
5 changes: 5 additions & 0 deletions migrations/v0.5.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# MySQL only; SQLite doesn't support CHANGE COLUMN. You need to export data,
# remove database, recreate database and import data. Be careful while doing
# it, or you may lose what you gathered.
ALTER TABLE `sightings` CHANGE COLUMN `lat` `lat` VARCHAR(20);
ALTER TABLE `sightings` CHANGE COLUMN `lon` `lon` VARCHAR(20);
2 changes: 1 addition & 1 deletion templates/gyms.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3>You literally own {{ area_size }} km² of {{ area_name }}.</h3>
{% endfor %}
</div>

<p>Out of {{ total_count }} gyms in Wrocław, {{ team_names[order[0]] }} owns <span class="label label-{{ styles[order[0]] }}">{{ count[order[0]] }} ({{ '%0.1f' % percentages[order[0]] }}%)</span> of them. They have <span class="label label-{{ styles[order[0]] }}">{{ prestige[order[0]] }} ({{ '%0.1f' % prestige_percent[order[0]] }}%) prestige</span> amassed right now.</p>
<p>Out of {{ total_count }} gyms in {{ area_name }}, {{ team_names[order[0]] }} owns <span class="label label-{{ styles[order[0]] }}">{{ count[order[0]] }} ({{ '%0.1f' % percentages[order[0]] }}%)</span> of them. They have <span class="label label-{{ styles[order[0]] }}">{{ prestige[order[0]] }} ({{ '%0.1f' % prestige_percent[order[0]] }}%) prestige</span> amassed right now.</p>
<p>Next in line is {{ team_names[order[1]] }}, which owns <span class="label label-{{ styles[order[1]] }}">{{ count[order[1]] }} ({{ '%0.1f' % percentages[order[1]] }}%)</span> Gyms right now. They accumulated <span class="label label-{{ styles[order[1]] }}">{{ prestige[order[1]] }} ({{ '%0.1f' % prestige_percent[order[1]] }}%) prestige</span>.</p>
<p>And the loser is {{ team_names[order[2]] }} with just <span class="label label-{{ styles[order[2]] }}">{{ count[order[2]] }} ({{ '%0.1f' % percentages[order[2]] }}%)</span> Gyms in possesion, with <span class="label label-{{ styles[order[2]] }}">{{ prestige[order[2]] }} ({{ '%0.1f' % prestige_percent[order[2]] }}%) prestige</span> total.</p>
<p>By the way, <span class="label label-default">{{ count[0] }} ({{ '%0.1f' % percentages[0] }}%)</span> Gyms are empty.</p>
Expand Down
9 changes: 6 additions & 3 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ def report_main():
session, [r[0] for r in bottom_pokemon]
)
stage2_pokemon = db.get_stage2_pokemon(session)
stage2_sightings = db.get_all_sightings(
session, [r[0] for r in stage2_pokemon]
)
if stage2_pokemon:
stage2_sightings = db.get_all_sightings(
session, [r[0] for r in stage2_pokemon]
)
else:
stage2_sightings = []
js_data = {
'charts_data': {
'punchcard': db.get_punch_card(session),
Expand Down
2 changes: 2 additions & 0 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def __init__(
self.api.activate_signature(config.ENCRYPT_PATH)
self.api.set_position(center[0], center[1], 100) # lat, lon, alt
self.api.set_logger(self.logger)
if hasattr(config, 'PROXIES') and config.PROXIES:
self.api.set_proxy(config.PROXIES)

async def first_run(self):
loop = asyncio.get_event_loop()
Expand Down

0 comments on commit 668e2e3

Please sign in to comment.