Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
luissilva1044894 committed May 6, 2020
1 parent d80bc1c commit af850ec
Show file tree
Hide file tree
Showing 49 changed files with 1,855 additions and 1,572 deletions.
7 changes: 7 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
web1: gunicorn -b 0.0.0.0:$PORT main_old:app --log-file=- --preload --env FLASK_ENV=default --timeout 10
web: gunicorn -b 0.0.0.0:$PORT main:app --log-file=-
#release: python manage.py create_db

downgrade: python manage.py db downgrade
init: python manage.py db init
migrate: python manage.py db migrate
upgrade: python manage.py db upgrade

create_db: python manage.py create_db
drop_db: python manage.py drop_db
reset_db: python manage.py reset_db
7 changes: 6 additions & 1 deletion Procfile.windows
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
web: python main.py runserver 0.0.0.0:5000

downgrade: python manage.py db downgrade
init: python manage.py db init
migrate: python manage.py db migrate
upgrade: python manage.py db upgrade
release: python manage.py db upgrade

create_db: python manage.py create_db
drop_db: python manage.py drop_db
reset_db: python manage.py reset_db
45 changes: 17 additions & 28 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,22 @@
#https://flask.palletsprojects.com/en/1.1.x/patterns/favicon/

#https://stackoverflow.com/questions/4239825/static-files-in-flask-robot-txt-sitemap-xml-mod-wsgi
def register(app):
from .views import blueprint
from .utils import replace
app.register_blueprint(blueprint, url_prefix='/{}'.format(replace(__name__, 'app', 'api')))

import os
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
#import importlib
#for _mod in [_ for _ in os.listdir('.') if os.path.isdir(_) and not _.startswith('_')]:
# try:
# _lib = importlib.import_module('.'.join([__name__, _mod]))
# except ModuleNotFoundError:
# pass
# else:
# try:
# _lib.register(app)
# except AttributeError:
# pass
from .utils.lib import import_from
for _mod in [_ for _ in os.listdir('.') if os.path.isdir(_) and not _ in ['utils', 'migrations'] and not _.startswith('_')]:
try:
_lib = import_from('.'.join([__name__, _mod]))
except ModuleNotFoundError:
pass
else:
try:
_lib.register(app)
except AttributeError:
pass
import os

from .views import blueprint
from .utils import replace
from .utils.lib import import_from

def register(app):
app.register_blueprint(blueprint, url_prefix='/{}'.format(replace(__name__, 'app', 'api')))

os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
for _mod in [_ for _ in os.listdir('.') if os.path.isdir(_) and not _ in ['utils', 'migrations'] and not _.startswith('_')]:
try:
_lib = import_from('.'.join([__name__, _mod]))
_lib.register(app)
except (ModuleNotFoundError, AttributeError):
print(f'>>> Failed to load: {_lib.__name__}')
else:
print(f'>>> Blueprint loaded: {_lib.__name__}')
16 changes: 8 additions & 8 deletions app/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@
"BUTTTON": "Command List",
"TITLES": [ "Action", "Description", "URL", "Option 1", "Option 2", "Option 3", "Option 4" ],
"PALADINS": [
[ "Current Match", "All players rank in a live match", "url_for:getCurrentMatch", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ],
[ "Decks", "Decks of a champion", "url_for:getDecks", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=EN" ],
[ "KDA", "KDA of a player or champion", "url_for:getWinrate", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=EN" ],
[ "Last Match", "Info about the last played match", "url_for:getLastMatch", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ],
[ "Rank", "Currently rank of a specified player", "url_for:getRank", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ],
[ "Server", "Currently status of Paladins Server", "url_for:getGameVersion", "&platform=PLATFORM", "&language=EN", "", "" ],
[ "Stalk", "Currently online status of a specified player", "url_for:getStalk", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ]
[ "Current Match", "All players rank in a live match", "url_for:live_match_handler", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ],
[ "Decks", "Decks of a champion", "url_for:decks_handler", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=EN" ],
[ "KDA", "KDA of a player or champion", "url_for:kda_handler", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=EN" ],
[ "Last Match", "Info about the last played match", "url_for:last_match_handler", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ],
[ "Rank", "Currently rank of a specified player", "url_for:rank_handler", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ],
[ "Server", "Currently status of Paladins Server", "url_for:version_handler", "&platform=PLATFORM", "&language=EN", "", "" ],
[ "Stalk", "Currently online status of a specified player", "url_for:stalk_handler", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ]
],
"OVERWATCH": [
[ "Rank", "Currently rank of a specified player", "url_for:rank", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ]
[ "Rank", "Currently rank of a specified player", "url_for:rank_handler", "?player=IGN", "&platform=PLATFORM", "&language=EN", "" ]
]
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@
"BUTTTON": "Command List",
"TITLES": [ "Action", "Description", "URL", "Option 1", "Option 2", "Option 3", "Option 4" ],
"PALADINS": [
[ "Partida actual", "Todos los rank del jugadores en una partida", "url_for:getCurrentMatch", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ],
[ "Decks", "Decks de un campeón", "url_for:getDecks", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=ES" ],
[ "KDA", "KDA de un jugador o campeón", "url_for:getWinrate", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=ES" ],
[ "Última partida", "Información sobre la última partida jugada", "url_for:getLastMatch", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ],
[ "Rank", "Rank actual de un jugador específico", "url_for:getRank", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ],
[ "Server", "Estado actual del servidor Paladins", "url_for:getGameVersion", "&platform=PLATFORM", "&language=ES", "", "" ],
[ "Stalk", "Estado actual en línea de un jugador específico", "url_for:getStalk", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ]
[ "Partida actual", "Todos los rank del jugadores en una partida", "url_for:live_match_handler", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ],
[ "Decks", "Decks de un campeón", "url_for:decks_handler", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=ES" ],
[ "KDA", "KDA de un jugador o campeón", "url_for:kda_handler", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=ES" ],
[ "Última partida", "Información sobre la última partida jugada", "url_for:last_match_handler", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ],
[ "Rank", "Rank actual de un jugador específico", "url_for:rank_handler", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ],
[ "Server", "Estado actual del servidor Paladins", "url_for:version_handler", "&platform=PLATFORM", "&language=ES", "", "" ],
[ "Stalk", "Estado actual en línea de un jugador específico", "url_for:stalk_handler", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ]
],
"OVERWATCH": [
[ "Rank", "Currently rank of a specified player", "url_for:rank", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ]
[ "Rank", "Currently rank of a specified player", "url_for:rank_handler", "?player=IGN", "&platform=PLATFORM", "&language=ES", "" ]
]
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@
"BUTTTON": "Command List",
"TITLES": [ "Action", "Description", "URL", "Option 1", "Option 2", "Option 3", "Option 4" ],
"PALADINS": [
[ "Current Match", "All players rank in a live match", "url_for:getCurrentMatch", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ],
[ "Decks", "Decks of a champion", "url_for:getDecks", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=PL" ],
[ "KDA", "KDA of a player or champion", "url_for:getWinrate", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=PL" ],
[ "Last Match", "Info about the last played match", "url_for:getLastMatch", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ],
[ "Rank", "Currently rank of a specified player", "url_for:getRank", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ],
[ "Server", "Currently status of Paladins Server", "url_for:getGameVersion", "&platform=PLATFORM", "&language=PL", "", "" ],
[ "Stalk", "Currently online status of a specified player", "url_for:getStalk", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ]
[ "Current Match", "All players rank in a live match", "url_for:live_match_handler", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ],
[ "Decks", "Decks of a champion", "url_for:decks_handler", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=PL" ],
[ "KDA", "KDA of a player or champion", "url_for:kda_handler", "?player=IGN", "&champion=CHAMPION", "&platform=PLATFORM", "&language=PL" ],
[ "Last Match", "Info about the last played match", "url_for:last_match_handler", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ],
[ "Rank", "Currently rank of a specified player", "url_for:rank_handler", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ],
[ "Server", "Currently status of Paladins Server", "url_for:version_handler", "&platform=PLATFORM", "&language=PL", "", "" ],
[ "Stalk", "Currently online status of a specified player", "url_for:stalk_handler", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ]
],
"OVERWATCH": [
[ "Rank", "Currently rank of a specified player", "url_for:rank", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ]
[ "Rank", "Currently rank of a specified player", "url_for:rank_handler", "?player=IGN", "&platform=PLATFORM", "&language=PL", "" ]
]
}
}
Expand Down
16 changes: 8 additions & 8 deletions app/lang/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@
"BUTTTON": "Comandos disponíveis",
"TITLES": [ "Comando", "Descrição", "Link", "Opção 1", "Opção 2", "Opção 3", "Opção 4" ],
"PALADINS": [
[ "Partida", "Mostra os ranks dos jogadores em uma partida", "url_for:getCurrentMatch", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ],
[ "Decks", "Baralhos de um campeão", "url_for:getDecks", "?player=JOGADOR", "&champion=CAMPEÃO", "&platform=PLATAFORMA", "&language=PT" ],
[ "KDA", "KDA de um jogador ou campeão", "url_for:getWinrate", "?player=JOGADOR", "&champion=CAMPEÃO", "&platform=PLATAFORMA", "&language=PT" ],
[ "Última partida", "Informações sobre a última partida jogada", "url_for:getLastMatch", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ],
[ "Rank", "O rank atual de um jogador", "url_for:getRank", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ],
[ "Server", "Status do servidor do Paladins", "url_for:getGameVersion", "&platform=PLATAFORMA", "&language=PT", "", "" ],
[ "Stalk", "Status sobre um jogador", "url_for:getStalk", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ]
[ "Partida", "Mostra os ranks dos jogadores em uma partida", "url_for:live_match_handler", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ],
[ "Decks", "Baralhos de um campeão", "url_for:decks_handler", "?player=JOGADOR", "&champion=CAMPEÃO", "&platform=PLATAFORMA", "&language=PT" ],
[ "KDA", "KDA de um jogador ou campeão", "url_for:kda_handler", "?player=JOGADOR", "&champion=CAMPEÃO", "&platform=PLATAFORMA", "&language=PT" ],
[ "Última partida", "Informações sobre a última partida jogada", "url_for:last_match_handler", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ],
[ "Rank", "O rank atual de um jogador", "url_for:rank_handler", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ],
[ "Server", "Status do servidor do Paladins", "url_for:version_handler", "&platform=PLATAFORMA", "&language=PT", "", "" ],
[ "Stalk", "Status sobre um jogador", "url_for:stalk_handler", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ]
],
"OVERWATCH": [
[ "Rank", "O rank atual de um jogador", "url_for:rank", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ]
[ "Rank", "O rank atual de um jogador", "url_for:rank_handler", "?player=JOGADOR", "&platform=PLATAFORMA", "&language=PT", "" ]
]
}
}
Expand Down
10 changes: 4 additions & 6 deletions app/overwatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def register(app):
from .views import blueprint

from ..utils import replace
app.register_blueprint(blueprint, url_prefix='/{}'.format(replace(__name__, 'app.', 'api/')))
from .views import blueprint
from ..utils import replace

#return app
def register(app):
app.register_blueprint(blueprint, url_prefix='/{}'.format(replace(__name__, 'app.', 'api/')))
88 changes: 46 additions & 42 deletions app/overwatch/controllers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

from bs4 import BeautifulSoup
import time

from ..utils import (
winratio,
get_url,
)

def get_battle_net(battle_net):
return battle_net.replace('#', '-', 1)

Expand Down Expand Up @@ -26,54 +34,50 @@ def get_rank_name(skill_rating):
return '???'

def rank_func(battle_net, platform, paladins_like=False, format_average_sr=False):
from ..utils import winratio, get_url
if not battle_net:
return '🚫 ERROR: Player not specified!'
return '🚫 ERROR: Player not specified!'
try:
#https://github.com/Addonexus/OverwatchWebscraper/blob/master/scraper.py
from bs4 import BeautifulSoup
import requests
import time
rank = {}
last_time = time.time()
for item in BeautifulSoup(requests.get(f'https://playoverwatch.com/en-us/career/{platform}/{get_battle_net(battle_net)}').text, 'html.parser').findAll('div', {'class': 'competitive-rank-role'}):
rank[str(item.findAll('div', {'class': 'competitive-rank-tier-tooltip'})[0]['data-ow-tooltip-text'].split()[0]).lower()] = int(item.findAll('div', {'class': 'competitive-rank-level'})[0].text)
print(f'That took {time.time() - last_time} seconds\r\n\r\n{rank}')
#https://github.com/Addonexus/OverwatchWebscraper/blob/master/scraper.py
rank = {}
last_time = time.time()
for item in BeautifulSoup(get_url(f'https://playoverwatch.com/en-us/career/{platform}/{get_battle_net(battle_net)}'), 'html.parser').findAll('div', {'class': 'competitive-rank-role'}):
rank[str(item.findAll('div', {'class': 'competitive-rank-tier-tooltip'})[0]['data-ow-tooltip-text'].split()[0]).lower()] = int(item.findAll('div', {'class': 'competitive-rank-level'})[0].text)
print(f'That took {time.time() - last_time} seconds\r\n\r\n{rank}')
except:
pass
pass
else:
try:
_ratings, high_sr, __x__, __y__ = [], -1, 0, 0
for x in rank:
if format_average_sr:
__x__ += 1
__y__ += rank[x]
if rank[x] > high_sr:
high_sr = rank[x]
_ratings.append(f'{x.title()} {rank[x]} SR')
_rat = ' | '.join(_ratings)
_rank = __x__ / __y__ if format_average_sr else high_sr
except:
pass
else:
if rank:
return f'{battle_net.split("-")[0]} is {get_rank_name(_rank)} ({_rank} SR){f" - {_rat}" _rat else ""}'
try:
_ratings, high_sr, __x__, __y__ = [], -1, 0, 0
for x in rank:
if format_average_sr:
__x__ += 1
__y__ += rank[x]
if rank[x] > high_sr:
high_sr = rank[x]
_ratings.append(f'{x.title()} {rank[x]} SR')
_rat = ' | '.join(_ratings)
_rank = __x__ / __y__ if format_average_sr else high_sr
except:
pass
else:
if rank:
return f'{battle_net.split("-")[0]} is {get_rank_name(_rank)} ({_rank} SR){f" - {_rat}" if _rat else ""}'
_json = get_url(f'https://ow-api.com/v1/stats/{platform}/us/{get_battle_net(battle_net)}/profile')
if isinstance(_json, dict):
if _json.get('error'):
return '🚫 ERROR: ' + _json['error']
if _json.get('private'):
return '🔒 ERROR: Private account!'
_ratings, high_sr = [], -1
for x in _json.get('ratings', ()):
if x['level'] > high_sr:
high_sr = x['level']
_ratings.append('{} {} SR'.format(x['role'].title(), x['level']))
_rat = ' | '.join(_ratings)
_rank = _json['rating'] if format_average_sr else high_sr
if paladins_like:
return "{} is {} ({} SR{}) with {} wins and {} losses. (Win rate: {}%)".format(_json['name'].split('#')[0], get_rank_name(_rank), _rank, ' - {}'.format(_rat) if _rat else '', _json['competitiveStats']['games']['won'], _json['competitiveStats']['games']['played'] - _json['competitiveStats']['games']['won'], winratio(_json['competitiveStats']['games']['won'], _json['competitiveStats']['games']['played']))
return F'{_json["name"].split("#")[0]} is {get_rank_name(_rank)} ({_rank} SR){f" - {_rat}" if _rat else ""}'
if _json.get('error'):
return '🚫 ERROR: ' + _json['error']
if _json.get('private'):
return '🔒 ERROR: Private account!'
_ratings, high_sr = [], -1
for x in _json.get('ratings', ()):
if x['level'] > high_sr:
high_sr = x['level']
_ratings.append('{} {} SR'.format(x['role'].title(), x['level']))
_rat = ' | '.join(_ratings)
_rank = _json['rating'] if format_average_sr else high_sr
if paladins_like:
return "{} is {} ({} SR{}) with {} wins and {} losses. (Win rate: {}%)".format(_json['name'].split('#')[0], get_rank_name(_rank), _rank, ' - {}'.format(_rat) if _rat else '', _json['competitiveStats']['games']['won'], _json['competitiveStats']['games']['played'] - _json['competitiveStats']['games']['won'], winratio(_json['competitiveStats']['games']['won'], _json['competitiveStats']['games']['played']))
return F'{_json["name"].split("#")[0]} is {get_rank_name(_rank)} ({_rank} SR){f" - {_rat}" if _rat else ""}'
return '🚫 ERROR'
#valid_regions = ['en-us', 'en-gb', 'es-es', 'es-mx', 'pt-br', 'pl-pl']
#valid_platforms = ['pc', 'psn', 'xbl']
Expand Down
Loading

0 comments on commit af850ec

Please sign in to comment.