Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit f4afc23

Browse files
committed
Send statistics after game
1 parent ce0283b commit f4afc23

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

project/game/stat.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

project/tenhou/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from mahjong.tile import TilesConverter
1212

1313
from game.client import Client
14-
from game.stat import Statistics
1514
from tenhou.decoder import TenhouDecoder
1615

1716
from utils.settings_handler import settings
17+
from utils.statistics import Statistics
1818

1919
logger = logging.getLogger('tenhou')
2020

@@ -171,12 +171,15 @@ def start_game(self):
171171
self.looking_for_game = False
172172
game_id, seat = self.decoder.parse_log_link(message)
173173
log_link = 'http://tenhou.net/0/?log={}&tw={}'.format(game_id, seat)
174+
174175
self.statistics.game_id = game_id
175176

176177
if '<UN' in message:
177178
values = self.decoder.parse_names_and_ranks(message)
178179
self.table.set_players_names_and_ranks(values)
179180

181+
self.statistics.username = values[0]['name']
182+
180183
if '<LN' in message:
181184
self._send_message(self._pxr_tag())
182185

project/utils/statistics.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
import requests
3+
4+
from utils.settings_handler import settings
5+
6+
7+
class Statistics(object):
8+
"""
9+
Send data to https://github.com/MahjongRepository/mahjong-stat/ project
10+
"""
11+
game_id = ''
12+
username = ''
13+
14+
def send_statistics(self):
15+
url = settings.STAT_SERVER_URL
16+
if not url or not self.game_id:
17+
return False
18+
19+
url = '{0}/api/v1/tenhou/game/add/'.format(url)
20+
data = {
21+
'id': self.game_id,
22+
'username': self.username
23+
}
24+
25+
result = requests.post(url, data, headers={'Token': settings.STAT_TOKEN})
26+
27+
return result.status_code == 200 and result.json()['success']

0 commit comments

Comments
 (0)