import requests
import json


# def update_stats():
#     #url = "http://127.0.0.1:8000/"
#     products = json.load(open(products_path, "r", encoding="utf-8"))
#     # response = requests.get(url)
#     # if response.status_code != 200:
#     #     return
#     # if response.json() == products:
#     #     return
#     json.dump(products, open(products_path, "w", encoding="utf-8"), indent=4)


# class Get:
#     def __init__(self):
#         # self.url = "http://127.0.0.1:8000/"
#         self.json = json.load(open(products_path, "r", encoding="utf-8"))
# 
#     def get_member_count(self):
#         response = requests.get(self.url + "membercount")
#         self.json["member_count"] = response.json()["member_count"]
#         json.dump(self.json, open(products_path, "w", encoding="utf-8"), indent=4)
# 
#     def get_new_members(self):
#         response = requests.get(self.url + "newmembers")
#         self.json["new_members"] = response.json()["new_members"]
#         json.dump(self.json, open(products_path, "w", encoding="utf-8"), indent=4)
# 
#     def get_member_in_voice(self):
#         response = requests.get(self.url + "memberinvoice")
#         self.json["member_in_voice"] = response.json()["member_in_voice"]
#         json.dump(self.json, open(products_path, "w", encoding="utf-8"), indent=4)
# 
#     def get_boost_count(self):
#         response = requests.get(self.url + "boostcount")
#         self.json["boost_count"] = response.json()["boost_count"]
#         json.dump(self.json, open(products_path, "w", encoding="utf-8"), indent=4)
# 
#     def get_count(self, guild_id):
#         response = requests.get(self.url + f"guild/{guild_id}")
#         self.json["guilds"][str(guild_id)] = response.json()["guilds"]["count"]
#         json.dump(self.json, open(products_path, "w", encoding="utf-8"), indent=4)
# 
#     def get_online(self, guild_id):
#         response = requests.get(self.url + f"guild/{guild_id}")
#         self.json["guilds"][str(guild_id)] = response.json()["guilds"]["online"]
#         json.dump(self.json, open(products_path, "w", encoding="utf-8"), indent=4)

products_path = "/home/code/p2g_bot/api_stats.json"


def get_member_count():
    # update_stats()
    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["member_count"]


def get_new_members():
    # update_stats()

    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["new_members"]


def get_member_in_voice():
    # update_stats()
    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["member_in_voice"]


def get_boost_count():
    # update_stats()
    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["boost_count"]


def get_count(guild_id):
    # update_stats()
    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["guilds"][str(guild_id)]


def get_online(guild_id):
    # update_stats()
    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["online"][str(guild_id)]


def get_guilds():
    # update_stats()
    with open(products_path, "r", encoding="utf-8") as f:
        return json.load(f)["guild_count"]
