nightr/server/nightr/strategies/upstairs_neighbour.py

41 lines
1.2 KiB
Python

import requests
from bs4 import BeautifulSoup
from datetime import datetime
from ..util import Prediction, Context
def update():
requests.post('https://euw.op.gg/summoner/ajax/renew.json/', data={'summonerId': 34009256})
def check_games(context: Context) -> Prediction:
"""
Is Alexanders upstairs neighbour currently playing League of Legends?
"""
update()
r = requests.get('https://euw.op.gg/summoner/userName=Im+Eating+Pros')
#if not "is not in an active game" in str(r.content):
# return 1.0
p = Prediction()
soup = BeautifulSoup(r.content, features='html5lib')
timestamp = int(soup.find('div', {'class': 'GameItemList'}).find('div', {'class': 'GameItem'})['data-game-time'])
last_played_game = datetime.fromtimestamp(timestamp)
last_game_in_hours = (((datetime.now() - last_played_game).seconds)/60/60)
if last_game_in_hours < 2:
p.reasons.append("Alexanders upstairs neighbour is currently playing league")
p.probability = 0.8
else:
last_game_in_hours = min(24.0, last_game_in_hours)
p.reasons.append(f"Alexanders upstairs neighbour has not played league for {last_game_in_hours} hours!")
p.probability = 1 - (last_game_in_hours / 24)
return p