Skip to content

Commit

Permalink
šŸ› Fix spyreports. It would fail when spy report was not fully populatā€¦
Browse files Browse the repository at this point in the history
ā€¦ed due to game mechanics on spying in ogame
  • Loading branch information
PiecePaperCode committed Nov 15, 2021
1 parent 68e1e31 commit 4b21f03
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ogame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ def friendly_fleet(self):
fleet_ids = bs4.find_all_partial(id='fleet')
fleet_ids = [id['id'] for id in fleet_ids]
fleet_ids = [
re.search('fleet(.*)', id).group(1)
int(re.search('fleet(.*)', id).group(1))
for id in fleet_ids
]

Expand Down Expand Up @@ -1120,7 +1120,6 @@ def abandon_planet(self, id):
return False

def spyreports(self, firstpage=1, lastpage=30):
# get links for the last 30 pages
report_links = []
while firstpage <= lastpage:
try:
Expand All @@ -1133,7 +1132,8 @@ def spyreports(self, firstpage=1, lastpage=30):
'pagination': firstpage,
'ajax': 1}
).text
except:
except Exception as e:
print(e)
break
bs4 = BeautifulSoup4(response)
for link in bs4.find_all_partial(href='page=messages&messageId'):
Expand Down Expand Up @@ -1161,7 +1161,7 @@ def spyreports(self, firstpage=1, lastpage=30):

def get_tech_and_quantity(tech_type):
tech_list = bs4.find('ul', {'data-type': tech_type})
for tech in tech_list.find_all('li'):
for tech in tech_list.find_all('li', {'class': 'detail_list_el'}):
tech_id = int(re.search(r'([0-9]+)', tech.find('img')['class'][0]).group(1))
tech_amount = int(tech.find('span', 'fright').text.replace('.', ''))
yield (tech_id, tech_amount)
Expand Down

0 comments on commit 4b21f03

Please sign in to comment.