cheerlights-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cheerlights-api might be problematic. Click here for more details.
- cheerlights_api-0.1.0/LICENSE +21 -0
- cheerlights_api-0.1.0/PKG-INFO +62 -0
- cheerlights_api-0.1.0/README.md +46 -0
- cheerlights_api-0.1.0/cheerlights_api/__init__.py +21 -0
- cheerlights_api-0.1.0/cheerlights_api/cheerlights_api.py +120 -0
- cheerlights_api-0.1.0/cheerlights_api.egg-info/PKG-INFO +62 -0
- cheerlights_api-0.1.0/cheerlights_api.egg-info/SOURCES.txt +12 -0
- cheerlights_api-0.1.0/cheerlights_api.egg-info/dependency_links.txt +1 -0
- cheerlights_api-0.1.0/cheerlights_api.egg-info/requires.txt +1 -0
- cheerlights_api-0.1.0/cheerlights_api.egg-info/top_level.txt +1 -0
- cheerlights_api-0.1.0/pyproject.toml +3 -0
- cheerlights_api-0.1.0/setup.cfg +4 -0
- cheerlights_api-0.1.0/setup.py +25 -0
- cheerlights_api-0.1.0/tests/tests_cheerlights_api.py +50 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Hans Scharler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cheerlights-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package to interact with the CheerLights API.
|
|
5
|
+
Home-page: https://github.com/cheerlights/cheerlights-python-package
|
|
6
|
+
Author: Hans Scharler
|
|
7
|
+
Author-email: hscharler@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests>=2.25.1
|
|
16
|
+
|
|
17
|
+
# CheerLights Python Package
|
|
18
|
+
|
|
19
|
+
A Python package to interact with the CheerLights API. It allows users to get the current CheerLights color, retrieve the color history, and perform various color-related utilities.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install the package using pip:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install cheerlights-api
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage Examples
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import cheerlights-api
|
|
33
|
+
|
|
34
|
+
# Get the current color name and hex code
|
|
35
|
+
current_color = cheerlights.get_current_color()
|
|
36
|
+
print(current_color) # Example: {'color': 'red', 'hex': '#FF0000'}
|
|
37
|
+
|
|
38
|
+
# Get the current color name
|
|
39
|
+
color_name = cheerlights.get_current_color_name()
|
|
40
|
+
print(color_name) # Example: 'red'
|
|
41
|
+
|
|
42
|
+
# Get the current hex code
|
|
43
|
+
hex_code = cheerlights.get_current_hex()
|
|
44
|
+
print(hex_code) # Example: '#FF0000'
|
|
45
|
+
|
|
46
|
+
# Get the history of colors
|
|
47
|
+
history = cheerlights.get_color_history(5)
|
|
48
|
+
for entry in history:
|
|
49
|
+
print(f"{entry['timestamp']}: {entry['color']} ({entry['hex']})")
|
|
50
|
+
|
|
51
|
+
# Convert a color name to hex
|
|
52
|
+
hex_code = cheerlights.color_name_to_hex('green')
|
|
53
|
+
print(hex_code) # '#00FF00'
|
|
54
|
+
|
|
55
|
+
# Convert hex code to RGB
|
|
56
|
+
rgb = cheerlights.hex_to_rgb('#00FF00')
|
|
57
|
+
print(rgb) # (0, 255, 0)
|
|
58
|
+
|
|
59
|
+
# Check if a color is valid
|
|
60
|
+
is_valid = cheerlights.is_valid_color('purple')
|
|
61
|
+
print(is_valid) # True
|
|
62
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# CheerLights Python Package
|
|
2
|
+
|
|
3
|
+
A Python package to interact with the CheerLights API. It allows users to get the current CheerLights color, retrieve the color history, and perform various color-related utilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install the package using pip:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install cheerlights-api
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage Examples
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import cheerlights-api
|
|
17
|
+
|
|
18
|
+
# Get the current color name and hex code
|
|
19
|
+
current_color = cheerlights.get_current_color()
|
|
20
|
+
print(current_color) # Example: {'color': 'red', 'hex': '#FF0000'}
|
|
21
|
+
|
|
22
|
+
# Get the current color name
|
|
23
|
+
color_name = cheerlights.get_current_color_name()
|
|
24
|
+
print(color_name) # Example: 'red'
|
|
25
|
+
|
|
26
|
+
# Get the current hex code
|
|
27
|
+
hex_code = cheerlights.get_current_hex()
|
|
28
|
+
print(hex_code) # Example: '#FF0000'
|
|
29
|
+
|
|
30
|
+
# Get the history of colors
|
|
31
|
+
history = cheerlights.get_color_history(5)
|
|
32
|
+
for entry in history:
|
|
33
|
+
print(f"{entry['timestamp']}: {entry['color']} ({entry['hex']})")
|
|
34
|
+
|
|
35
|
+
# Convert a color name to hex
|
|
36
|
+
hex_code = cheerlights.color_name_to_hex('green')
|
|
37
|
+
print(hex_code) # '#00FF00'
|
|
38
|
+
|
|
39
|
+
# Convert hex code to RGB
|
|
40
|
+
rgb = cheerlights.hex_to_rgb('#00FF00')
|
|
41
|
+
print(rgb) # (0, 255, 0)
|
|
42
|
+
|
|
43
|
+
# Check if a color is valid
|
|
44
|
+
is_valid = cheerlights.is_valid_color('purple')
|
|
45
|
+
print(is_valid) # True
|
|
46
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# cheerlights/__init__.py
|
|
2
|
+
|
|
3
|
+
from .cheerlights_api import (
|
|
4
|
+
get_current_color,
|
|
5
|
+
get_current_hex,
|
|
6
|
+
get_current_color_name,
|
|
7
|
+
get_color_history,
|
|
8
|
+
color_name_to_hex,
|
|
9
|
+
hex_to_rgb,
|
|
10
|
+
is_valid_color,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
'get_current_color',
|
|
15
|
+
'get_current_hex',
|
|
16
|
+
'get_current_color_name',
|
|
17
|
+
'get_color_history',
|
|
18
|
+
'color_name_to_hex',
|
|
19
|
+
'hex_to_rgb',
|
|
20
|
+
'is_valid_color',
|
|
21
|
+
]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# cheerlights/cheerlights_api.py
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
CHEERLIGHTS_FEED_URL = "https://api.thingspeak.com/channels/1417/feed.json"
|
|
6
|
+
|
|
7
|
+
def get_current_color():
|
|
8
|
+
"""
|
|
9
|
+
Get the current CheerLights color name and hex code.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
dict: A dictionary with 'color' and 'hex' keys.
|
|
13
|
+
"""
|
|
14
|
+
response = requests.get(CHEERLIGHTS_FEED_URL)
|
|
15
|
+
response.raise_for_status()
|
|
16
|
+
data = response.json()
|
|
17
|
+
color_name = data['feeds'][0]['field1']
|
|
18
|
+
hex_code = data['feeds'][0]['field2']
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
'color': color_name,
|
|
22
|
+
'hex': hex_code
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def get_current_hex():
|
|
26
|
+
"""
|
|
27
|
+
Get the current CheerLights hex color code.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
str: The hex code of the current CheerLights color.
|
|
31
|
+
"""
|
|
32
|
+
return get_current_color()['hex']
|
|
33
|
+
|
|
34
|
+
def get_current_color_name():
|
|
35
|
+
"""
|
|
36
|
+
Get the current CheerLights color name.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
str: The name of the current CheerLights color.
|
|
40
|
+
"""
|
|
41
|
+
return get_current_color()['color']
|
|
42
|
+
|
|
43
|
+
def get_color_history(count=10):
|
|
44
|
+
"""
|
|
45
|
+
Get the history of CheerLights colors.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
count (int): The number of recent colors to retrieve.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
list: A list of dictionaries with 'color', 'hex', and 'timestamp'.
|
|
52
|
+
"""
|
|
53
|
+
url = f"{CHEERLIGHTS_FEED_URL}?results={count}"
|
|
54
|
+
response = requests.get(url)
|
|
55
|
+
response.raise_for_status()
|
|
56
|
+
data = response.json()
|
|
57
|
+
feeds = data['feeds']
|
|
58
|
+
history = []
|
|
59
|
+
for entry in feeds:
|
|
60
|
+
history.append({
|
|
61
|
+
'color': entry['field1'],
|
|
62
|
+
'hex': entry['field2'],
|
|
63
|
+
'timestamp': entry['created_at']
|
|
64
|
+
})
|
|
65
|
+
return history
|
|
66
|
+
|
|
67
|
+
def color_name_to_hex(color_name):
|
|
68
|
+
"""
|
|
69
|
+
Convert a CheerLights color name to its hex code.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
color_name (str): The name of the color.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
str or None: The hex code of the color or None if invalid.
|
|
76
|
+
"""
|
|
77
|
+
color_map = {
|
|
78
|
+
'red': '#FF0000',
|
|
79
|
+
'green': '#00FF00',
|
|
80
|
+
'blue': '#0000FF',
|
|
81
|
+
'cyan': '#00FFFF',
|
|
82
|
+
'white': '#FFFFFF',
|
|
83
|
+
'warmwhite': '#FDF5E6',
|
|
84
|
+
'purple': '#800080',
|
|
85
|
+
'magenta': '#FF00FF',
|
|
86
|
+
'yellow': '#FFFF00',
|
|
87
|
+
'orange': '#FFA500',
|
|
88
|
+
'pink': '#FFC0CB',
|
|
89
|
+
'oldlace': '#FDF5E6',
|
|
90
|
+
}
|
|
91
|
+
return color_map.get(color_name.lower())
|
|
92
|
+
|
|
93
|
+
def hex_to_rgb(hex_code):
|
|
94
|
+
"""
|
|
95
|
+
Convert a hex color code to an RGB tuple.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
hex_code (str): The hex color code.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
tuple: A tuple with (red, green, blue) values.
|
|
102
|
+
"""
|
|
103
|
+
hex_code = hex_code.lstrip('#')
|
|
104
|
+
return tuple(int(hex_code[i:i+2], 16) for i in (0, 2 ,4))
|
|
105
|
+
|
|
106
|
+
def is_valid_color(color_name):
|
|
107
|
+
"""
|
|
108
|
+
Check if a color name is a valid CheerLights color.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
color_name (str): The name of the color.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
bool: True if valid, False otherwise.
|
|
115
|
+
"""
|
|
116
|
+
valid_colors = [
|
|
117
|
+
'red', 'green', 'blue', 'cyan', 'white', 'warmwhite',
|
|
118
|
+
'purple', 'magenta', 'yellow', 'orange', 'pink', 'oldlace'
|
|
119
|
+
]
|
|
120
|
+
return color_name.lower() in valid_colors
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cheerlights-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package to interact with the CheerLights API.
|
|
5
|
+
Home-page: https://github.com/cheerlights/cheerlights-python-package
|
|
6
|
+
Author: Hans Scharler
|
|
7
|
+
Author-email: hscharler@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: requests>=2.25.1
|
|
16
|
+
|
|
17
|
+
# CheerLights Python Package
|
|
18
|
+
|
|
19
|
+
A Python package to interact with the CheerLights API. It allows users to get the current CheerLights color, retrieve the color history, and perform various color-related utilities.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install the package using pip:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install cheerlights-api
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage Examples
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import cheerlights-api
|
|
33
|
+
|
|
34
|
+
# Get the current color name and hex code
|
|
35
|
+
current_color = cheerlights.get_current_color()
|
|
36
|
+
print(current_color) # Example: {'color': 'red', 'hex': '#FF0000'}
|
|
37
|
+
|
|
38
|
+
# Get the current color name
|
|
39
|
+
color_name = cheerlights.get_current_color_name()
|
|
40
|
+
print(color_name) # Example: 'red'
|
|
41
|
+
|
|
42
|
+
# Get the current hex code
|
|
43
|
+
hex_code = cheerlights.get_current_hex()
|
|
44
|
+
print(hex_code) # Example: '#FF0000'
|
|
45
|
+
|
|
46
|
+
# Get the history of colors
|
|
47
|
+
history = cheerlights.get_color_history(5)
|
|
48
|
+
for entry in history:
|
|
49
|
+
print(f"{entry['timestamp']}: {entry['color']} ({entry['hex']})")
|
|
50
|
+
|
|
51
|
+
# Convert a color name to hex
|
|
52
|
+
hex_code = cheerlights.color_name_to_hex('green')
|
|
53
|
+
print(hex_code) # '#00FF00'
|
|
54
|
+
|
|
55
|
+
# Convert hex code to RGB
|
|
56
|
+
rgb = cheerlights.hex_to_rgb('#00FF00')
|
|
57
|
+
print(rgb) # (0, 255, 0)
|
|
58
|
+
|
|
59
|
+
# Check if a color is valid
|
|
60
|
+
is_valid = cheerlights.is_valid_color('purple')
|
|
61
|
+
print(is_valid) # True
|
|
62
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
cheerlights_api/__init__.py
|
|
6
|
+
cheerlights_api/cheerlights_api.py
|
|
7
|
+
cheerlights_api.egg-info/PKG-INFO
|
|
8
|
+
cheerlights_api.egg-info/SOURCES.txt
|
|
9
|
+
cheerlights_api.egg-info/dependency_links.txt
|
|
10
|
+
cheerlights_api.egg-info/requires.txt
|
|
11
|
+
cheerlights_api.egg-info/top_level.txt
|
|
12
|
+
tests/tests_cheerlights_api.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cheerlights_api
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# setup.py
|
|
2
|
+
|
|
3
|
+
from setuptools import setup, find_packages
|
|
4
|
+
|
|
5
|
+
setup(
|
|
6
|
+
name='cheerlights-api',
|
|
7
|
+
version='0.1.0',
|
|
8
|
+
description='A Python package to interact with the CheerLights API.',
|
|
9
|
+
long_description=open('README.md').read(),
|
|
10
|
+
long_description_content_type='text/markdown',
|
|
11
|
+
author='Hans Scharler',
|
|
12
|
+
author_email='hscharler@gmail.com',
|
|
13
|
+
url='https://github.com/cheerlights/cheerlights-python-package',
|
|
14
|
+
license='MIT',
|
|
15
|
+
packages=find_packages(),
|
|
16
|
+
install_requires=[
|
|
17
|
+
'requests>=2.25.1',
|
|
18
|
+
],
|
|
19
|
+
classifiers=[
|
|
20
|
+
'Programming Language :: Python :: 3',
|
|
21
|
+
'License :: OSI Approved :: MIT License',
|
|
22
|
+
'Operating System :: OS Independent',
|
|
23
|
+
],
|
|
24
|
+
python_requires='>=3.6',
|
|
25
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# tests/test_cheerlights_api.py
|
|
2
|
+
|
|
3
|
+
import unittest
|
|
4
|
+
from cheerlights_api import (
|
|
5
|
+
get_current_color,
|
|
6
|
+
get_current_hex,
|
|
7
|
+
get_current_color_name,
|
|
8
|
+
get_color_history,
|
|
9
|
+
color_name_to_hex,
|
|
10
|
+
hex_to_rgb,
|
|
11
|
+
is_valid_color,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
class TestCheerLights(unittest.TestCase):
|
|
15
|
+
|
|
16
|
+
def test_get_current_color(self):
|
|
17
|
+
color_info = get_current_color()
|
|
18
|
+
self.assertIn('color', color_info)
|
|
19
|
+
self.assertIn('hex', color_info)
|
|
20
|
+
|
|
21
|
+
def test_get_current_hex(self):
|
|
22
|
+
hex_code = get_current_hex()
|
|
23
|
+
self.assertTrue(hex_code.startswith('#'))
|
|
24
|
+
|
|
25
|
+
def test_get_current_color_name(self):
|
|
26
|
+
color_name = get_current_color_name()
|
|
27
|
+
self.assertIsInstance(color_name, str)
|
|
28
|
+
|
|
29
|
+
def test_get_color_history(self):
|
|
30
|
+
history = get_color_history(5)
|
|
31
|
+
self.assertEqual(len(history), 5)
|
|
32
|
+
for entry in history:
|
|
33
|
+
self.assertIn('color', entry)
|
|
34
|
+
self.assertIn('hex', entry)
|
|
35
|
+
self.assertIn('timestamp', entry)
|
|
36
|
+
|
|
37
|
+
def test_color_name_to_hex(self):
|
|
38
|
+
hex_code = color_name_to_hex('red')
|
|
39
|
+
self.assertEqual(hex_code, '#FF0000')
|
|
40
|
+
|
|
41
|
+
def test_hex_to_rgb(self):
|
|
42
|
+
rgb = hex_to_rgb('#FF0000')
|
|
43
|
+
self.assertEqual(rgb, (255, 0, 0))
|
|
44
|
+
|
|
45
|
+
def test_is_valid_color(self):
|
|
46
|
+
self.assertTrue(is_valid_color('blue'))
|
|
47
|
+
self.assertFalse(is_valid_color('black'))
|
|
48
|
+
|
|
49
|
+
if __name__ == '__main__':
|
|
50
|
+
unittest.main()
|