Skip to content

Commit

Permalink
If the api-key.txt file does not exist yet, ask the user to enter a…
Browse files Browse the repository at this point in the history
…n api key.
  • Loading branch information
johndoknjas committed Mar 25, 2024
1 parent 6616aea commit 01c661c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Besides installing the script, this will also automatically install its dependen

Then, create a new folder that will be used to store persistent information (such as friends lists you create).
In this folder, make a textfile called 'api-key.txt', and paste your hypixel api key as the first line.
- To get this api key, make a developer account with hypixel: https://developer.hypixel.net/
- To get this api key, make a [hypixel developer account](https://developer.hypixel.net/).
The first part of [this](https://gist.github.com/camnwalter/c0156c68b1e2a21ec0b084c6f04b63f0#how-to-get-a-new-api-key-after-the-hypixel-api-changes)
guide is helpful to do this.

After setting this up, you will be able to open a terminal window in this directory and run various commands
with the `hypickle` script (explained below).
Expand Down Expand Up @@ -46,4 +48,4 @@ Open the root directory of the project in the terminal, and then:

### Acknowledgements:

The `hypixel.py` and `leveling.py` files were originally from https://github.com/Snuggle/hypixel.py/. Since then I have made a number of modifications to them.
The `hypixel.py` and `leveling.py` files were originally from [Snuggle's repo](https://github.com/Snuggle/hypixel.py/). Since then I have made a number of modifications to them.
12 changes: 10 additions & 2 deletions hypickle/hypixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import List, Optional, Tuple
import re
from copy import deepcopy
import os.path
import requests
import urllib3

Expand All @@ -20,8 +21,15 @@
from .Rank import Rank

def _get_api_keys_from_file() -> List[str]:
""" This function gets the api key(s) from `api-key.txt`, and returns them in a list. """
with open('api-key.txt') as file:
""" This function gets the api key(s) from `api-key.txt`, and returns them in a list. If the file doesn't
exist, it will ask the user for an api key and write it to the new file."""
FILENAME = 'api-key.txt'
if not os.path.isfile(FILENAME):
print("The script needs a hypixel api key. To get one, you can follow the first part of this guide: https://gist.github.com/camnwalter/c0156c68b1e2a21ec0b084c6f04b63f0#how-to-get-a-new-api-key-after-the-hypixel-api-changes")
api_key = input("Please enter your api key: ")
with open(FILENAME, 'w') as file:
file.write(api_key)
with open(FILENAME) as file:
return [line.rstrip() for line in file]

API_KEYS: List[str] = _get_api_keys_from_file()
Expand Down
2 changes: 2 additions & 0 deletions ideas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

# Consider refactoring to not need the HEX.UNKNOWN hacky stuff used in hypixel.py.

# Check whether the api key is valid, when the user enters it if it doesn't exist yet in `hypixel.py`.

# Test the program when there are no `aliases.txt` or `uuids.txt` files. Program should handle it,
not raise an error.

Expand Down

0 comments on commit 01c661c

Please sign in to comment.