From 43d5bec4b78eafbb262151465237105a8ac687ac Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 12 Aug 2016 17:23:45 +0200 Subject: [PATCH] Moved some things around --- main.py | 25 ++++++++++++++++++++----- overwatch.py | 16 +--------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index 674985d1..8dec571b 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,22 @@ import asyncio import discord -client = discord.Client() +import json +import overwatch +d_client = discord.Client() + +# Get player database from the db.json file +file = open("db.json") +db = json.load(file) +file.close() # When the discord client is ready, print something -@client.event +@d_client.event async def on_ready(): print("Connessione riuscita!") - print(client.user.name) - print(client.user.id) + print(d_client.user.name) + print(d_client.user.id) + # Get the discord bot token from "discordtoken.txt" f = open("discordtoken.txt", "r") @@ -16,4 +24,11 @@ token = f.read() f.close() # Start discord bot client but ignore events -client.start(token) +d_client.start(token) + +# List overwatch players +ow_players = list() +for player in db: + if db[player]["overwatch"] is not None: + ow_players.append(db[player]["overwatch"]) + diff --git a/overwatch.py b/overwatch.py index 6babfd31..e9103bd3 100644 --- a/overwatch.py +++ b/overwatch.py @@ -1,19 +1,7 @@ import asyncio import requests -import json loop = asyncio.get_event_loop() -# Get player database from the db.json file -file = open("db.json") -db = json.load(file) -file.close() - -# List overwatch players -players = list() -for player in db: - if db[player]["overwatch"] is not None: - players.append(db[player]["overwatch"]) - # Get player data async def get_player_data(platform: str, region: str, battletag: str): # Unofficial API requires - for discriminator numbers @@ -25,6 +13,4 @@ async def get_player_data(platform: str, region: str, battletag: str): if r.status_code == 200: return r.json() elif r.status_code == 404: - raise Exception("Player not found.") - -loop.run_until_complete(get_player_data("pc", "eu", "SteffoRYG#2876")) + raise Exception("Player not found.") \ No newline at end of file