def refresh_keys(eve_id, eve_secret):
    '''
    Only to be used on a seperate thread.
    :param eve_id:
    :param eve_secret:
    :param refresh_key:
    :return:
    '''
    while (True):
        refreshed_keys = authpython.refresh(eve_id, eve_secret,
                                            get_refreshkey())
        write_new_keys_file(refreshed_keys)
        time.sleep(1000)
Пример #2
0
def read_tokens(file: Union[str, os.PathLike[str]]):
    """
    Reading the tokens made from the pythonserver.py functions from a file (mostly it should be 'key.key')
    Input is the file
    The file is formatted into two columns, one line
    output are the two tokens
    """
    keys_file = open(file, "r")
    access_token = refresh_token = 0
    for lines in keys_file:
        pw = lines.split(" ")  # [0] is access_token, #[1] is refresh
        access_token = pw[0]  # First column
        refresh_token = pw[1]  # Second Column
    print(authpython.refresh('1', refresh_token))
    return access_token, refresh_token
Пример #3
0
def fleet_overwatch(fleet_type: str, state_of_fleet: int,
                    fleet_commander_name: str):
    access = input('Do you need to run the server?')
    if access is 'a':
        pythonserver.run()
    ratio_scores = []
    # First we load the two keys from the keys.key file
    access_token, refresh_token = read_tokens("keys.key")
    reader = codecs.getreader("utf-8")
    fleet_id = get_fleet_id(fleet_commander_name, access_token)["fleet_id"]
    url = "https://esi.tech.ccp.is/latest/fleets/" + str(
        fleet_id) + "/?datasource=tranquility&token=" + str(access_token)
    while state_of_fleet == 1:
        time_timer = datetime.datetime.now().time()
        # timeer = "The time is : " + str(time_timer) + "\n" # todo: deprecate
        fleetmembersjson = json.load(
            reader(
                req_esi(
                    'fleets/' + str(fleet_id) +
                    '/members/?datasource=tranquility&language=en-us&token=' +
                    access_token)))
        fleetmemberslength = len(fleetmembersjson)
        print(fleetmemberslength)
        current_doctrine = doctrine(fleet_type)
        fleet_groups, group_ratio, fleet_group_count = process_fleet_comp(
            fleetmembersjson, fleetmemberslength, current_doctrine)
        # fleet_groups is for 'dps,logi,whatever'
        # group_ratio is the assigned values
        # ratiolength = len(fleet_group_count)
        ratio_scores = []
        scores = {}
        for i in range(0, len(fleet_group_count)):
            ratio_scores.append(
                float(fleet_group_count[i] / float(group_ratio[i])))
        minimum = max(ratio_scores)

        for i in range(0, len(fleet_group_count)):
            scores[fleet_groups[i]] = float(ratio_scores[i])

        # sorted(scores.items(), key=lambda x:float(x[1]))
        scores = OrderedDict(sorted(scores.items(), key=lambda x: float(x[1])))
        updatemessage = " "

        timeer = "\n" + updatemessage
        timeer = timeer + "\n****DOCTRINE SHIPS NEEDED****\n"
        for keys in scores.items():
            timeer = timeer + keys[0] + ">"
        timeer = timeer + "else\n"
        """status_put =requests.put(url, data=json.dumps(
            {
                'fleet_id': fleet_id,'new_settings': {"motd": "string"},}))"""

        status_put = requests.put(
            url, json.dumps({
                'fleet_id': fleet_id,
                'motd': timeer
            }))
        time.sleep(2)
        print(authpython.refresh('1', refresh_token))
        print(status_put)
        del current_doctrine
        del scores
Пример #4
0
    eve_id = os.getenv('EVE_CLIENT_ID')
    eve_secret = os.getenv('EVE_SECRET_KEY')


    trello_client = TrelloClient(
        api_key=trello_key,
        api_secret=trello_token
    )

    if len(sys.argv) == 1:
        # If we need to make a new api key
        a = pythonserver.run(eve_id)
    else:
        # if we dont need to (we made one <1200 seconds)
        refreshed_keys = authpython.refresh(eve_id,
                                            eve_secret,
                                            pythonserver.get_refreshkey())
        pythonserver.write_new_keys_file(refreshed_keys)  # todo: could be moved to authpython, under authpython.refresh

    refresh_key_thread = threading.Thread(target=pythonserver.refresh_keys, args=(eve_id, eve_secret), daemon=True)
    refresh_key_thread.start()
    reader = codecs.getreader("utf-8")
    client = discord.Client()


    async def trello_status():
        channel = client.get_channel(manufacturing_admin) # This is manufacturing-administration
        while True:
            await asyncio.sleep(86400)
            for msg in trello_discord_eve_int.discord_remind_manufacture_administration(client,
                                                                                        channel,