Skip to content

Commit c6e35a3

Browse files
authored
Merge pull request #2 from JustCoderdev/Development
1.0.2 - 2022.07.12 | Less crashes
2 parents 7afb6aa + 63585f7 commit c6e35a3

15 files changed

Lines changed: 513 additions & 512 deletions

File tree

Changelog.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Here there is going to be the changelog of the new versions of the plugin
1010

1111
All of the basic features on the plugin
1212

13-
## [1.0.1] - 2022.07.09 | Minor fixes
13+
## [1.0.1] - 2022.07.11 | Minor fixes
1414

1515
### Added
1616

@@ -28,8 +28,18 @@ All of the basic features on the plugin
2828
- Logging event exposing `CLIENT-SECRET` and `CLIENT-ID` of Twitch API now removed
2929
- On the showcase page, the refresh button was colored red every time it was updated instead of green
3030

31-
<!-- ## [Unreleased] -->
31+
## [1.0.2] - 2022.07.12 | Less crashes
32+
33+
### Added
34+
35+
- When entering the list in `Channel Names` it now automatically removes spaces to avoid errors or missing data
3236

37+
### Fixed
38+
39+
- Data in title of previous version now is the correct one
40+
- API requests should now no longer crash the plugin
41+
42+
<!-- ## [Unreleased] -->
3343
<!--
3444
### Added
3545
### Changed
@@ -43,4 +53,5 @@ All of the basic features on the plugin
4353
<!-- [unreleased]: https://github.com/JustCoderdev/TwitchActivity -->
4454

4555
[1.0.0]: https://github.com/JustCoderdev/TwitchActivity/tree/d5b02548cd3f141b0994c05cfed2e136c222fb90
46-
[1.0.1]: https://github.com/JustCoderdev/TwitchActivity/tree/
56+
[1.0.1]: https://github.com/JustCoderdev/TwitchActivity/tree/d4de7b5ebb64ea9d45755294f22e8d6bb2cf3b4a
57+
[1.0.2]: https://github.com/JustCoderdev/TwitchActivity/tree/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This documentation is partially generated with [Python TouchPortal SDK](https://
88

99
1. Import the plugin from the release section on [github](https://github.com/JustCoderdev/TwitchActivity/releases)
1010
2. Go to the plugin settings and change `Channel names` to the names of your followed channels and if you need adjust the refresh time (enter the time in minutes)
11-
> NOTE: `Channel names` **must** be formatted like it is by default (MonikaCinnyRoll,xSgtPepperx) without spaces and separated by a `,` (capital letters have no influence over the functioning of the plugin but you can change it for esthetic) and contain up to 100 channels (the last one are going to be ignored)
11+
> NOTE: `Channel names` **must** be formatted like it is by default (MonikaCinnyRoll,xSgtPepperx)without spaces (otherwise it will automatically remove them) and separated by a `,` (capital letters have no influence over the functioning of the plugin but you can change it for esthetic) and contain up to 100 channels (the last one are going to be ignored)
1212
3. Import a simple button from `helpers/touchportal`
1313
4. Go to the button GUI and change `Open stream` action field to your channel name
1414
5. Press the `On Event` tab and change the value in `Update Button text...` from `${value:com.github.justcoderdev.twitchactivity.state.xSgtPepperx.viewers}` to `${value:com.github.justcoderdev.twitchactivity.state.YOURCHANNELNAME.viewers}` and `Change the icon...` from `xSgtPepperx icon` to `YOURCHANNELNAME icon`

TwitchActivity/entry.tp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": 6,
3-
"version": 2,
3+
"version": 3,
44
"name": "Twitch Activity",
55
"id": "com.github.justcoderdev.twitchactivity",
66
"configuration": {

TwitchActivity/index.exe

-198 Bytes
Binary file not shown.

build/scripts/WebHandler.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def getStreams(self, users: list): #! Check if token is gone #* Channels & Vi
123123

124124
try:
125125
res = get(f'https://api.twitch.tv/helix/streams?{query[1:]}', headers={'Authorization': f'Bearer {self._TOKEN}', 'Client-Id': self._CLIENT_ID}).json()
126-
err = {'error': 'Bad Request', 'status': 400, 'message': 'Malformed query params.'}
127-
return None if res == err else res
126+
return None if res.get('data') == None else res
128127
except ConnectionError:
129128
isOnline = False
130129

@@ -142,8 +141,7 @@ def getUsers(self, users: list): #! Check if token is gone
142141

143142
try:
144143
res = get(f'https://api.twitch.tv/helix/users?{query[1:]}', headers={'Authorization': f'Bearer {self._TOKEN}', 'Client-Id': self._CLIENT_ID}).json()
145-
err = {'error': 'Bad Request', 'status': 400, 'message': 'Invalid login names, emails or IDs in request'}
146-
return None if res == err else res
144+
return None if res.get('data') == None else res
147145
except ConnectionError:
148146
isOnline = False
149147

@@ -159,12 +157,10 @@ def getChannelUserData(usersData: list, channel: str) -> dict:
159157
'defIcon': None,
160158
}
161159

162-
for i in range(len(usersData)):
163-
userData = usersData[i]
164-
160+
for userData in usersData:
165161
if userData['login'] == channel.lower():
166162
output['display_name'] = userData['display_name']
167-
output['defIcon'] = getDefImage(getImgBytesFromUrl(userData['profile_image_url']))
163+
output['defIcon'] = getDefImage(userData['profile_image_url'])
168164
return output
169165

170166
return output
@@ -176,9 +172,7 @@ def getChannelStreamData(streamsData: list, channel: str) -> dict:
176172
'cViewers': '',
177173
}
178174

179-
for i in range(len(streamsData)):
180-
streamData = streamsData[i]
181-
175+
for streamData in streamsData:
182176
if streamData['user_login'] == channel.lower():
183177
output['cState'] = 'Offline' if streamData['type'] == '' else 'Online'
184178
output['cViewers'] = str(streamData['viewer_count'])
@@ -187,21 +181,17 @@ def getChannelStreamData(streamsData: list, channel: str) -> dict:
187181
return output
188182

189183

190-
def getImgBytesFromUrl(imgURL: str) -> bytes | None:
191-
global isOnline, newStates
184+
def getDefImage(imgURL: str) -> str | None:
185+
global isOnline
192186

193187
if not isOnline: return None
194188

195189
try:
196-
return get(imgURL).content
190+
imgBytes = get(imgURL).content
197191
except ConnectionError:
198192
isOnline = False
199193
return None
200194

201-
202-
def getDefImage(imgBytes: bytes) -> str | None:
203-
if imgBytes == None: return None
204-
205195
#!#
206196
imgDef = Image.open(BytesIO(imgBytes))
207197
#!#

build/scripts/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def updateSettings(data):
5454

5555
# Update settings
5656
REFRESH['time'] = int(data[1]['Refresh Time (m)'])
57-
CHANNELS = data[0]['Channel names'].split(',')[:100]
57+
CHANNELS = data[0]['Channel names'].replace(' ', '').split(',')[:100]
5858
DYNAMIC = True if data[2]['Dynamic image (bool)'] == '1' else False
5959

6060
# Create new states

0 commit comments

Comments
 (0)