talklib 3.6.4__tar.gz → 3.7.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: talklib
3
- Version: 3.6.4
3
+ Version: 3.7.2
4
4
  Summary: A package to automate processing of shows/segments airing on the TL
5
5
  Author-email: Ben Weddle <ben.weddle@gmail.com>
6
6
  Maintainer-email: Ben Weddle <ben.weddle@gmail.com>
@@ -119,12 +119,12 @@ To repeat, **this package will not work without FFmpeg and FFprobe**.
119
119
 
120
120
  FFmpeg and FFprobe should be two separate binaries.
121
121
 
122
- The easiest way to install FFmpeg (and FFprobe) on Windows is with WinGet:
122
+ The easiest way to install FFmpeg (and FFprobe) on Windows is with WinGet (you may need to run this in a terminal with Admin privileges):
123
123
  ````bash
124
124
  winget install Gyan.FFmpeg
125
125
  ````
126
126
 
127
- This should install both FFmpeg & FFprobe. After WinGet completes installation, test to ensure FFmpeg is installed:
127
+ This should install both FFmpeg & FFprobe. After WinGet completes installation, restart your terminal and then test to ensure FFmpeg is installed:
128
128
  ````bash
129
129
  ffmpeg -version
130
130
  ````
@@ -169,7 +169,7 @@ Before we begin, a general note:
169
169
  - These are some of the reasons why we do not run `.py` files directly from WR.
170
170
  - Instead, we tell WR to run a Batch script (`.bat` file) which in turn will automatically run the Python script (`.py` file).
171
171
  - Ensure the Batch & Python scripts are in the same directory.
172
- - A sample `.bat` file (`Example.bat`) is included in the [misc](https://github.com/Nashville-Public-Library/misc/tree/main/talklib_examples) repo.
172
+ - A sample `.bat` file (`Example.bat`) is included in the [talking-library-misc](https://github.com/Nashville-Public-Library/talking-library-misc/tree/main/talklib_examples) repo (This is a private repo! Contact Shared Systems team to get access).
173
173
  - Download this file and place it in the same folder as your Python file.
174
174
  - Right-Click the file > select `Properties` > select `Unblock` so that it can be executed.
175
175
  - It is a best practice to give the `.bat` and `.py` files the same name, though it is not necessary.
@@ -258,7 +258,7 @@ required for all RSS or permalink shows
258
258
 
259
259
  required for "local" shows
260
260
  - path to the local file as such: `D:\path\to\the\show.wav`
261
- - you will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see the [MISC](https://github.com/talkinglibrary/misc) repo for some examples.
261
+ - you will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see the [talking-library-misc](https://github.com/Nashville-Public-Library/talking-library-misc) repo for some examples (This is a private repo! Contact Shared Systems team to get access).
262
262
 
263
263
  `is_permalink`
264
264
 
@@ -38,12 +38,12 @@ To repeat, **this package will not work without FFmpeg and FFprobe**.
38
38
 
39
39
  FFmpeg and FFprobe should be two separate binaries.
40
40
 
41
- The easiest way to install FFmpeg (and FFprobe) on Windows is with WinGet:
41
+ The easiest way to install FFmpeg (and FFprobe) on Windows is with WinGet (you may need to run this in a terminal with Admin privileges):
42
42
  ````bash
43
43
  winget install Gyan.FFmpeg
44
44
  ````
45
45
 
46
- This should install both FFmpeg & FFprobe. After WinGet completes installation, test to ensure FFmpeg is installed:
46
+ This should install both FFmpeg & FFprobe. After WinGet completes installation, restart your terminal and then test to ensure FFmpeg is installed:
47
47
  ````bash
48
48
  ffmpeg -version
49
49
  ````
@@ -88,7 +88,7 @@ Before we begin, a general note:
88
88
  - These are some of the reasons why we do not run `.py` files directly from WR.
89
89
  - Instead, we tell WR to run a Batch script (`.bat` file) which in turn will automatically run the Python script (`.py` file).
90
90
  - Ensure the Batch & Python scripts are in the same directory.
91
- - A sample `.bat` file (`Example.bat`) is included in the [misc](https://github.com/Nashville-Public-Library/misc/tree/main/talklib_examples) repo.
91
+ - A sample `.bat` file (`Example.bat`) is included in the [talking-library-misc](https://github.com/Nashville-Public-Library/talking-library-misc/tree/main/talklib_examples) repo (This is a private repo! Contact Shared Systems team to get access).
92
92
  - Download this file and place it in the same folder as your Python file.
93
93
  - Right-Click the file > select `Properties` > select `Unblock` so that it can be executed.
94
94
  - It is a best practice to give the `.bat` and `.py` files the same name, though it is not necessary.
@@ -177,7 +177,7 @@ required for all RSS or permalink shows
177
177
 
178
178
  required for "local" shows
179
179
  - path to the local file as such: `D:\path\to\the\show.wav`
180
- - you will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see the [MISC](https://github.com/talkinglibrary/misc) repo for some examples.
180
+ - you will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see the [talking-library-misc](https://github.com/Nashville-Public-Library/talking-library-misc) repo for some examples (This is a private repo! Contact Shared Systems team to get access).
181
181
 
182
182
  `is_permalink`
183
183
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "talklib"
3
- version = "3.6.4"
3
+ version = "3.7.2"
4
4
  description = "A package to automate processing of shows/segments airing on the TL"
5
5
  readme = "README.md"
6
6
  license = "MIT-open-group"
@@ -13,7 +13,7 @@ import requests
13
13
 
14
14
  from talklib.ev import EV
15
15
  from talklib.notify import Notify
16
- from talklib.utils import get_timestamp, clear_screen, raise_exception_and_wait, today_is_weekday
16
+ from talklib.utils import get_timestamp, clear_screen, today_is_weekday
17
17
  from talklib.ffmpeg import FFMPEG
18
18
 
19
19
 
@@ -79,8 +79,9 @@ class TLShow(BaseModel):
79
79
  return file
80
80
  except ffmpeg_error as e:
81
81
  error: str = e.stderr.decode('utf-8')
82
- self.__send_notifications(message=f"FFmpeg error: {error}. Exiting automation...", subject='Error')
83
- raise_exception_and_wait(message=error)
82
+ to_send: str = f"FFmpeg error: {error}. Exiting automation..."
83
+ self.__send_notifications(message=to_send, subject='Error')
84
+ raise e (to_send)
84
85
 
85
86
 
86
87
  def __copy_then_remove(self, fileToCopy):
@@ -149,23 +150,29 @@ class TLShow(BaseModel):
149
150
  else:
150
151
  download_URL = self.__get_RSS_audio_url()
151
152
 
152
- self.__prep_syslog(message=f'Attempting to download audio file.')
153
- input_file = 'input.mp3' # name the file we download
154
- with open (input_file, mode='wb') as downloaded_file:
155
- a = requests.get(download_URL)
156
- downloaded_file.write(a.content)
157
- downloaded_file.close()
158
-
159
- self.__prep_syslog(message=f'File downloaded successfully in {os.getcwd()}.')
160
- return downloaded_file.name
153
+ self.__prep_syslog(message=f'Attempting to download audio file from {download_URL}')
154
+ try:
155
+ input_file = 'input.mp3' # name the file we download
156
+ with open (input_file, mode='wb') as downloaded_file:
157
+ a = requests.get(download_URL)
158
+ downloaded_file.write(a.content)
159
+ downloaded_file.close()
160
+
161
+ self.__prep_syslog(message=f'File downloaded successfully in {os.getcwd()}.')
162
+ return downloaded_file.name
163
+ except Exception as e:
164
+ to_send: str = f"Unable to download the file from: {download_URL}: {e}. Exiting automation!"
165
+ self.__send_notifications(to_send)
166
+ raise e (to_send)
161
167
 
162
168
  def check_downloaded_file(self, fileToCheck, how_many_attempts):
163
169
  '''TODO explain'''
164
170
  try:
165
171
  filesize = os.path.getsize(fileToCheck)
166
172
  except FileNotFoundError as error:
167
- self.__send_notifications(message=f'It looks like the file does not exist. Here is the error: {error}', subject='Error')
168
- raise FileNotFoundError
173
+ to_send: str = f"It looks like the file does not exist. Here is the error: {error}"
174
+ self.__send_notifications(message=to_send, subject='Error')
175
+ raise FileNotFoundError (to_send)
169
176
 
170
177
  is_not_empty = False
171
178
  while how_many_attempts < 3:
@@ -191,6 +198,7 @@ It looks like the downloaded file is empty. Please check manually! Yesterday's f
191
198
  def __prep_syslog(self, message: str, level: str = 'info'):
192
199
  '''send message to syslog server'''
193
200
  message = f'{self.show}: {message}'
201
+ print(message)
194
202
  self.notifications.send_syslog(message=message, level=level)
195
203
 
196
204
 
@@ -228,8 +236,8 @@ It looks like the file either wasn't converted or didn't transfer correctly. \
228
236
  Please check manually!\n\n\
229
237
  {get_timestamp()}")
230
238
  self.__send_notifications(message=toSend, subject='Error')
231
- raise_exception_and_wait(message=toSend)
232
- break
239
+ raise FileNotFoundError (toSend)
240
+
233
241
  if success:
234
242
  self.__countdown()
235
243
 
@@ -282,7 +290,7 @@ Is this a permalink show? Did you forget to set the is_permalink attribute?\n\n\
282
290
  {get_timestamp()}"
283
291
  )
284
292
  self.__send_notifications(subject='Error', message=to_send)
285
- raise_exception_and_wait(message=a)
293
+ raise a (to_send)
286
294
 
287
295
  def __check_feed_updated(self) -> bool:
288
296
  '''
@@ -316,7 +324,7 @@ Is this a permalink show? Did you forget to set the is_permalink attribute?\n\n\
316
324
  to_send = f"There's a Problem with {self.show}. \
317
325
  There is no 'enclosure' tag for the item. Here's the error: {AE}\n\n{get_timestamp()}"
318
326
  self.__send_notifications(message=to_send, subject="error")
319
- raise_exception_and_wait(message=to_send, error=AE)
327
+ raise AE (to_send)
320
328
 
321
329
  def __check_feed_loop(self) -> str:
322
330
  '''
@@ -353,108 +361,13 @@ There is no 'enclosure' tag for the item. Here's the error: {AE}\n\n{get_timesta
353
361
  number = number-1
354
362
  time.sleep(1)
355
363
 
356
- def __check_str_and_bool_type(self, attrib_to_check, type_to_check: str | bool, attrib_return: str):
357
- '''
358
- we are checking whether an attribute is either type str or bool, depending on what is passed in.
359
-
360
- 'attrib_return' is solely for printing the message back out to the screen/log,
361
- it is not needed for the actual type check.
362
- (I can't figure out how else to get the name of the attribute)
363
- '''
364
- if type(attrib_to_check) != type_to_check:
365
- message = f"Sorry, '{attrib_return}' attribute must be type: {type_to_check}, but you used {type(attrib_to_check)}."
366
- self.__send_notifications(message=message, subject="Error")
367
- raise_exception_and_wait(message=message)
368
-
369
- def __check_int_and_float_type(self, attrib_to_check, attrib_return: str):
370
- '''
371
- Attributes passed here can be either int or float.
372
- '''
373
- if not (type(attrib_to_check) == int or type(attrib_to_check) == float):
374
- message = f'Sorry, the {attrib_return} attribute must be a valid number (without quotes).'
375
- self.__send_notifications(message=message, subject="Error")
376
- raise_exception_and_wait(message=message)
377
-
378
- def __check_attributes_are_valid(self):
379
- '''
380
- Run some checks on the attributes the user has set. I.E. the required
381
- attributes have been set, they are the right type, etc.
382
- '''
383
- self.__prep_syslog(message='checking user defined attributes')
384
-
385
- if not self.show:
386
- message = 'Sorry, you need to specify a name for the show.'
387
- self.__send_notifications(message=message, subject="Error")
388
- raise_exception_and_wait(message=message)
389
- else:
390
- self.__check_str_and_bool_type(attrib_to_check=self.show, type_to_check=str, attrib_return='show')
391
-
392
- if not self.show_filename:
393
- message = 'Sorry, you need to specify a filename for the show.'
394
- self.__send_notifications(message=message, subject="Error")
395
- raise_exception_and_wait(message=message)
396
- else:
397
- self.__check_str_and_bool_type(attrib_to_check=self.show_filename, type_to_check=str, attrib_return='show_filename')
398
-
399
- if not self.url:
400
- if not self.is_local:
401
- message = 'Sorry, you need to specify either a URL or a local file'
402
- self.__send_notifications(message=message, subject="Error")
403
- raise_exception_and_wait('Sorry, you need to specify either a URL or a local file')
404
-
405
- if self.url and self.is_local:
406
- message = 'Sorry, you cannot specify both a URL and a local audio file. You must choose only one.'
407
- self.__send_notifications(message=message, subject="Error")
408
- raise_exception_and_wait(message=message)
409
-
410
- if self.url and self.local_file:
411
- message = 'Sorry, you cannot specify both a URL and a local audio file. You must choose only one.'
412
- self.__send_notifications(message=message, subject="Error")
413
- raise_exception_and_wait(message=message)
414
-
415
- if self.url:
416
- self.__check_str_and_bool_type(attrib_to_check=self.url, type_to_check=str, attrib_return='url')
417
-
418
- if self.is_local:
419
- self.__check_str_and_bool_type(attrib_to_check=self.is_local, type_to_check=bool, attrib_return='is_local')
420
-
421
- if self.local_file:
422
- self.__check_str_and_bool_type(attrib_to_check=self.local_file, type_to_check=str, attrib_return='local_file')
423
-
424
- if self.ffmpeg.breakaway:
425
- self.__check_int_and_float_type(attrib_to_check=self.ffmpeg.breakaway, attrib_return='breakaway')
426
-
427
- if self.ffmpeg.compression_level:
428
- self.__check_int_and_float_type(attrib_to_check=self.ffmpeg.compression_level, attrib_return='fflevel')
429
-
430
- if self.is_permalink:
431
- self.__check_str_and_bool_type(attrib_to_check=self.is_permalink, type_to_check=bool, attrib_return='is_permalink')
432
-
433
- if not (self.check_if_above and self.check_if_below):
434
- print('\n(You did not specify check_if_below and/or check_if_above. These checks will not be run.')
435
-
436
- if self.check_if_above:
437
- self.__check_int_and_float_type(attrib_to_check=self.check_if_above, attrib_return='check_if_above')
438
-
439
- if self.check_if_below:
440
- self.__check_int_and_float_type(attrib_to_check=self.check_if_below, attrib_return='check_if_below')
441
-
442
- if self.notifications.syslog_enable:
443
- self.__check_str_and_bool_type(attrib_to_check=self.notifications.syslog_enable, type_to_check=bool, attrib_return='notifications')
444
-
445
- if self.notifications.twilio_enable:
446
- self.__check_str_and_bool_type(attrib_to_check=self.notifications.twilio_enable, type_to_check=bool, attrib_return='twilio_enable')
447
-
448
- if self.notifications.email_enable:
449
- self.__check_str_and_bool_type(attrib_to_check=self.notifications.email_enable, type_to_check=bool, attrib_return='twilio_enable')
450
-
451
364
  def check_ffmpeg_installed(self):
452
365
  ffmpeg = shutil.which("ffmpeg")
453
366
  if not ffmpeg:
454
367
  to_send: str = f"It looks like FFmpeg is either not installed on this computer ({socket.gethostname()}), \
455
368
  or it isn't added to the PATH. You cannot use the talklib package without FFmpeg."
456
369
  self.__send_notifications(message=to_send, subject="Error")
457
- raise_exception_and_wait(message=to_send)
370
+ raise Exception (to_send)
458
371
 
459
372
  def run(self):
460
373
  '''begins to process the file'''
@@ -462,7 +375,6 @@ or it isn't added to the PATH. You cannot use the talklib package without FFmpeg
462
375
  self.__prep_syslog(message=f'Starting script')
463
376
  print(f"I'm working on {self.show}. Just a moment...\n")
464
377
 
465
- # self.__check_attributes_are_valid()
466
378
  self.check_ffmpeg_installed()
467
379
 
468
380
  if self.url and self.is_permalink:
@@ -481,7 +393,7 @@ or it isn't added to the PATH. You cannot use the talklib package without FFmpeg
481
393
  else:
482
394
  message = "Sorry, something bad happened..."
483
395
  self.__send_notifications(message=message, subject="Error")
484
- raise_exception_and_wait(message=message)
396
+ raise Exception (message)
485
397
 
486
398
  def __run_URL_permalink(self):
487
399
  # if url is declared, it's either an RSS or permalink show
@@ -512,7 +424,7 @@ It looks like today's file hasn't yet been posted. Please check and download man
512
424
  {get_timestamp()}"
513
425
  )
514
426
  self.__send_notifications(message=toSend, subject='Error')
515
- raise_exception_and_wait(message=toSend)
427
+ raise Exception (toSend)
516
428
 
517
429
  def __run_local(self):
518
430
  if self.local_file:
@@ -529,4 +441,4 @@ It looks like the source file doesn't exist. Please check manually! Yesterday's
529
441
  {get_timestamp()}"
530
442
  )
531
443
  self.__send_notifications(message=to_send, subject='Error')
532
- raise_exception_and_wait(message=to_send, error=FileNotFoundError)
444
+ raise FileNotFoundError (to_send)
@@ -16,13 +16,6 @@ def clear_screen() -> None:
16
16
  else:
17
17
  os.system('clear')
18
18
 
19
- def raise_exception_and_wait(message: str, error = Exception) -> None:
20
- '''clear terminal and print message to screen.'''
21
- clear_screen()
22
- print(f'{message}\n') # get user's attention!
23
- input('(press enter to close this window)') # force user to acknowledge by closing window
24
- raise error (message)
25
-
26
19
  def today_is_weekday() -> bool:
27
20
  '''crude mechanism for determining if today is a weekday.'''
28
21
  today = datetime.now().strftime('%a')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: talklib
3
- Version: 3.6.4
3
+ Version: 3.7.2
4
4
  Summary: A package to automate processing of shows/segments airing on the TL
5
5
  Author-email: Ben Weddle <ben.weddle@gmail.com>
6
6
  Maintainer-email: Ben Weddle <ben.weddle@gmail.com>
@@ -119,12 +119,12 @@ To repeat, **this package will not work without FFmpeg and FFprobe**.
119
119
 
120
120
  FFmpeg and FFprobe should be two separate binaries.
121
121
 
122
- The easiest way to install FFmpeg (and FFprobe) on Windows is with WinGet:
122
+ The easiest way to install FFmpeg (and FFprobe) on Windows is with WinGet (you may need to run this in a terminal with Admin privileges):
123
123
  ````bash
124
124
  winget install Gyan.FFmpeg
125
125
  ````
126
126
 
127
- This should install both FFmpeg & FFprobe. After WinGet completes installation, test to ensure FFmpeg is installed:
127
+ This should install both FFmpeg & FFprobe. After WinGet completes installation, restart your terminal and then test to ensure FFmpeg is installed:
128
128
  ````bash
129
129
  ffmpeg -version
130
130
  ````
@@ -169,7 +169,7 @@ Before we begin, a general note:
169
169
  - These are some of the reasons why we do not run `.py` files directly from WR.
170
170
  - Instead, we tell WR to run a Batch script (`.bat` file) which in turn will automatically run the Python script (`.py` file).
171
171
  - Ensure the Batch & Python scripts are in the same directory.
172
- - A sample `.bat` file (`Example.bat`) is included in the [misc](https://github.com/Nashville-Public-Library/misc/tree/main/talklib_examples) repo.
172
+ - A sample `.bat` file (`Example.bat`) is included in the [talking-library-misc](https://github.com/Nashville-Public-Library/talking-library-misc/tree/main/talklib_examples) repo (This is a private repo! Contact Shared Systems team to get access).
173
173
  - Download this file and place it in the same folder as your Python file.
174
174
  - Right-Click the file > select `Properties` > select `Unblock` so that it can be executed.
175
175
  - It is a best practice to give the `.bat` and `.py` files the same name, though it is not necessary.
@@ -258,7 +258,7 @@ required for all RSS or permalink shows
258
258
 
259
259
  required for "local" shows
260
260
  - path to the local file as such: `D:\path\to\the\show.wav`
261
- - you will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see the [MISC](https://github.com/talkinglibrary/misc) repo for some examples.
261
+ - you will probably not have a hardcoded path here. Usually, you will be running a short algorithm to determine the path. Please see the [talking-library-misc](https://github.com/Nashville-Public-Library/talking-library-misc) repo for some examples (This is a private repo! Contact Shared Systems team to get access).
262
262
 
263
263
  `is_permalink`
264
264
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes