cheerlights-api 0.1.0__py3-none-any.whl

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.

@@ -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,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,7 @@
1
+ cheerlights_api/__init__.py,sha256=sM_lbEHRG1ASEPfaN2jNuweQoC2jt4BDVIiFV0WcEeE,397
2
+ cheerlights_api/cheerlights_api.py,sha256=reDPHKYE5WzF_B-UEjK2koIOfpFA9AwNlwj5xptTTR8,3001
3
+ cheerlights_api-0.1.0.dist-info/LICENSE,sha256=IBcoeWgPBSEW06W4oQw4r17OLCppuQcuRsuu7gPoxmg,1070
4
+ cheerlights_api-0.1.0.dist-info/METADATA,sha256=0PmwUE1RMVKBm6-Hh4t3a47XQ60-tK3tYOucL6kSxEA,1742
5
+ cheerlights_api-0.1.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
6
+ cheerlights_api-0.1.0.dist-info/top_level.txt,sha256=VwXYaDCbDHTxHyRkBNjCfV9_ssYR-Xfhfy6DEaiyMZs,16
7
+ cheerlights_api-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.3.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ cheerlights_api