Skip to content

Commit

Permalink
v1.0.0 Just moved all cactive files into one repo
Browse files Browse the repository at this point in the history
  • Loading branch information
SpideyZac committed Jan 14, 2023
1 parent 4fd9bb5 commit 0d9650d
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 35 deletions.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### What is this?
This is a collection of Cactive's NPM Modules rewritten in Python

### How to install and use?
First, by using these modules you agree to our LICENSE: https://github.com/CactiveNetwork/cactive-rewrites/tree/main/python/LICENSE.md

Install:
```bash
pip install cactive
```

To find out the documentation for all modules please type:
```python
import cactive

cactive.get_started()
```

### PyPI
https://pypi.org/project/cactive
File renamed without changes.
1 change: 0 additions & 1 deletion python/hypixel-nick-tracker/requirements.txt

This file was deleted.

28 changes: 0 additions & 28 deletions python/hypixel-nick-tracker/test.py

This file was deleted.

File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Hypixel Nick Tracker and ip-python
requests==2.28.1
10 changes: 5 additions & 5 deletions python/hypixel-nick-tracker/setup.cfg → python/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[metadata]
name = cactive-hypixel-nick-tracker
name = cactive
description_file=README.md
license_files=LICENSE.md
version = 3.0.6
version = 1.0.0
author = Cactive
author_email = [email protected]
description = Wrapper for the exclusive CactiveNetwork unofficial Hypixel API.
description = All of the Cactive NPM modules rewritten in Python
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/CactiveNetwork/cactive-rewrites/tree/main/python/hypixel-nick-tracker
url = https://github.com/CactiveNetwork/cactive-rewrites/tree/main/python/
project_urls =
Bug Tracker = https://github.com/CactiveNetwork/cactive-rewrites/tree/main/python/hypixel-nick-tracker/issues
Bug Tracker = https://github.com/CactiveNetwork/cactive-rewrites/tree/main/python/issues
classifiers =
Programming Language :: Python :: 3
License :: Other/Proprietary License
Expand Down
14 changes: 14 additions & 0 deletions python/src/cactive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__version__ = "1.0.0"

print("By using Cactive's Python Rewrites, you agree to follow this LICENSE: https://github.com/CactiveNetwork/cactive-rewrites/tree/main/python/LICENSE.md")

from . import hypixel_nick_tracker
from . import ip

def get_started() -> None:
'''
Prints documentation for each module
'''

print("Documentation for ip is here: https://github.com/CactiveNetwork/cactive-rewrites/blob/main/python/src/cactive/ip/README.md")
print("Documentation for hypixel-nick-tracker is here: https://github.com/CactiveNetwork/cactive-rewrites/blob/main/python/src/cactive/hypixel_nick_tracker/README.md")
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ You are expected to respect these limits, and if you do not, you will be blocked
To use any implementation code block, you must create a declaration to a new API client.

```python
from cactive_hypixel_nick_tracker import Client
from cactive.hypixel_nick_tracker import Client
client = Client(
key="MY_API_KEY", # replace this field.
cache=False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
API = "https://hypixel.cactive.network/api/v3"

class Client:
'''
Client for connecting to API
'''

def __init__(self, key: str, cache: bool = False) -> None:
self.__key = key
self.__cache = cache
Expand Down Expand Up @@ -36,6 +40,10 @@ def __map_internal_error(self, reason: Any) -> APIResponseTypes:
}

def nickname_history(self, nickname: str) -> APINicknameResponse:
'''
Get nickname history for specific nickname
'''

try:
req = get(f"{API}/nickname-history?key={self.__key}&cache={self.__cache}&nickname={nickname}")
json: APINicknameResponse = APINicknameResponse(*loads(req.text).values())
Expand All @@ -46,6 +54,10 @@ def nickname_history(self, nickname: str) -> APINicknameResponse:
else: raise Exception(self.__map_external_error(json))

def player_data(self, uuid: str) -> APIPlayerData:
'''
Get player data given uuid
'''

try:
req = get(f"{API}/player-data?key={self.__key}&cache={self.__cache}&uuid={uuid}")
json: APIPlayerData = APIPlayerData(*loads(req.text).values())
Expand All @@ -56,6 +68,10 @@ def player_data(self, uuid: str) -> APIPlayerData:
else: raise Exception(self.__map_external_error(json))

def staff_tracker(self, filter: FilterType) -> APIStaffTracker:
'''
Get data for specific staff with given filter
'''

try:
req = get(f"{API}/staff-tracker?key={self.__key}&cache={self.__cache}&filter={filter}")
json: APIStaffTracker = APIStaffTracker(*loads(req.text).values())
Expand All @@ -66,6 +82,10 @@ def staff_tracker(self, filter: FilterType) -> APIStaffTracker:
else: raise Exception(self.__map_external_error(json))

def punishment_data(self, id: str) -> APIPunishmentData:
'''
Get punishment data given id
'''

try:
req = get(f"{API}/punishment-data?key={self.__key}&cache={self.__cache}&id={id}")
json: APIPunishmentData = APIPunishmentData(*loads(req.text).values())
Expand All @@ -76,6 +96,10 @@ def punishment_data(self, id: str) -> APIPunishmentData:
else: raise Exception(self.__map_external_error(json))

def key_data(self) -> APIKeyData:
'''
Get data for specific API Key
'''

try:
req = get(f"{API}/key?key={self.__key}")
json: APIKeyData = APIKeyData(*loads(req.text).values())
Expand Down
65 changes: 65 additions & 0 deletions python/src/cactive/ip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Cactive IP API (Python)

---

### API Information:

This is a free to use API hosted in Melbourne, Australia that provides detailed information of IP addresses.

You can request the API through the HTTP or HTTPS protocol and the `GET` method at [ip.cactive.co/api/lookup/](https://ip.cactive.co/api/lookup/).

You can either provide an IP address with `/api/lookup/[ip]` or leave it blank to get the IP address of the requester.

**Example:** https://ip.cactive.co/api/lookup/8.8.8.8

---

### Installation:

```bash
pip install cactive-ip
```

### Usage:

```python
import cactive.ip as ip

def examples():
# Get the IP address of the client
self = ip.self()
print(self.ip) # eg: 192.168.0.1

# Get the time zone of a domain, IPv4 or IPv6
external = ip.retrieve("cactive.cloud")
print(external.time_zone) # eg: Australia/Melbourne

examples()
```

### Data Schema:

| Field | Type | Example |
|--------------------|----------------|---------------------|
| `ip` | String | `8.8.8.8` |
| `city` | String or None | `Ashburn` |
| `state` | String or None | `Virginia` |
| `state_code` | String or None | `VA` |
| `country` | String or None | `United States` |
| `country_code` | String or None | `US` |
| `country_currency` | String or None | `USD` |
| `continent` | String or None | `North America` |
| `continent_code` | String or None | `NA` |
| `post_code` | String or None | `20149` |
| `time_zone` | String or None | `America/New_York` |
| `latitude` | Number or None | `39.03` |
| `longitude` | Number or None | `-77.5` |
| `reverse_dns` | String or None | `dns.google` |
| `isp` | String or None | `Google LLC` |
| `isp_org` | String or None | `Google Public DNS` |
| `as_number` | String or None | `AS15169` |
| `as_name` | String or None | `GOOGLE` |
| `as_org` | String or None | `Google LLC` |
| `detection_vpn` | Boolean | `false` |
| `detection_server` | Boolean | `true` |
| `detection_mobile` | Boolean | `false` |
101 changes: 101 additions & 0 deletions python/src/cactive/ip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from requests import get, Response
from json import loads, dumps

from typing import Union


class IPData:
'''
The class which holds all IPData
'''

def __init__(
self,
ip: str,
city: Union[str, None],
state: Union[str, None],
state_code: Union[str, None],
country: Union[str, None],
country_code: Union[str, None],
country_currency: Union[str, None],
continent: Union[str, None],
continent_code: Union[str, None],
post_code: Union[str, None],
time_zone: Union[str, None],
latitude: Union[float, None],
longitude: Union[float, None],
reverse_dns: Union[str, None],
isp: Union[str, None],
isp_org: Union[str, None],
as_number: Union[str, None],
as_name: Union[str, None],
as_org: Union[str, None],
detection_vpn: bool,
detection_server: bool,
detection_mobile: bool,
) -> None:
self.ip = ip
self.city = city
self.state = state
self.state_code = state_code
self.country = country
self.country_code = country_code
self.country_currency = country_currency
self.continent = continent
self.continent_code = continent_code
self.post_code = post_code
self.time_zone = time_zone
self.latitude = latitude
self.longitude = longitude
self.reverse_dns = reverse_dns
self.isp = isp
self.isp_org = isp_org
self.as_number = as_number
self.as_name = as_name
self.as_org = as_org
self.detection_vpn = detection_vpn
self.detection_server = detection_server
self.detection_mobile = detection_mobile

def __str__(self) -> str:
return dumps(self.__dict__)


class IPError(Exception):
'''
Custom exception for errors in IPData
'''

def __init__(self, error: str) -> None:
Exception.__init__(self, error)


def fetch(ip: Union[str, None]) -> IPData:
'''
Do not call this function directly. Please use self or retrieve
'''

ip = ip if ip is not None else ""

r: Response = get(f"https://ip.cactive.co/api/lookup/{ip}")
d: dict = loads(r.text)

if "errors" in d:
raise IPError(d["errors"][0]["message"])
return IPData(*d.values())


def self() -> IPData:
'''
Get the IP data for yourself
'''

return fetch(None)


def retrieve(ip: str) -> IPData:
'''
Get IP data for another IP address
'''

return fetch(ip)
3 changes: 3 additions & 0 deletions python/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import cactive

cactive.get_started()
File renamed without changes.

0 comments on commit 0d9650d

Please sign in to comment.