talklib 3.1.0__tar.gz → 3.2.1__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.2
2
2
  Name: talklib
3
- Version: 3.1.0
3
+ Version: 3.2.1
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>
@@ -523,7 +523,7 @@ nyt.run()
523
523
 
524
524
  To disable ALL notifications, add a line like this:
525
525
 
526
- > This will disable all notifications **including** syslog messages
526
+ > This will disable all notifications **including** syslog messages (shell print statements will not be disabled)
527
527
 
528
528
  ````python
529
529
  from talklib import TLPod
@@ -423,7 +423,7 @@ nyt.run()
423
423
 
424
424
  To disable ALL notifications, add a line like this:
425
425
 
426
- > This will disable all notifications **including** syslog messages
426
+ > This will disable all notifications **including** syslog messages (shell print statements will not be disabled)
427
427
 
428
428
  ````python
429
429
  from talklib import TLPod
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "talklib"
3
- version = "3.1.0"
3
+ version = "3.2.1"
4
4
  description = "A package to automate processing of shows/segments airing on the TL"
5
5
  readme = "README.md"
6
6
  license = {file = "LICENSE.txt"}
@@ -3,7 +3,7 @@ import os
3
3
  import sys
4
4
  import xml.etree.ElementTree as ET
5
5
 
6
- from talklib.pod import SSH
6
+ from talklib.pod import SSH, Notifications
7
7
 
8
8
  def parse_args():
9
9
  parser = argparse.ArgumentParser(description="use talklib in the terminal")
@@ -15,10 +15,32 @@ def parse_args():
15
15
  You MUST have an RSS feed (feed.xml) and logo (image.jpg) in the current directory."
16
16
  parser.add_argument('--new-pod-dir', type=str, help=new_podcast_directory_help, required=False)
17
17
 
18
- args = parser.parse_args()
18
+ download_feed_help:str = "Download the RSS feed from the folder on the server you specify."
19
+ parser.add_argument('--download-feed', type=str, help=download_feed_help, required=False)
20
+
21
+ upload_feed_help:str = "Upload the RSS feed to the folder on the server you specify."
22
+ parser.add_argument('--upload-feed', type=str, help=upload_feed_help, required=False)
19
23
 
24
+ args = parser.parse_args()
20
25
  return args
21
26
 
27
+ def get_SSH():
28
+ Notifications.prefix = "talklib CLI"
29
+ notifications = Notifications()
30
+ notifications.notify.email_enable = False
31
+ ssh = SSH(notifications=notifications)
32
+ return ssh
33
+
34
+ def download_feed(name: str):
35
+ ssh = get_SSH()
36
+ ssh.get_feed_from_folder(folder=name)
37
+
38
+ def upload_feed(name:str):
39
+ if not os.path.isfile("feed.xml"):
40
+ return print(f"cannot find 'feed.xml' in {os.getcwd()}. You must have this file in the current directory.")
41
+ ssh = get_SSH()
42
+ ssh.upload_feed_to_folder(folder=name)
43
+
22
44
  def generate_feed_template():
23
45
  ET.register_namespace(prefix="atom", uri="http://www.w3.org/2005/Atom")
24
46
  ET.register_namespace(prefix="itunes", uri="http://www.itunes.com/dtds/podcast-1.0.dtd")
@@ -38,7 +60,7 @@ def new_podcast_dir(name: str):
38
60
 
39
61
  print("generating new podcast directory called " + name)
40
62
 
41
- ssh = SSH()
63
+ ssh = get_SSH()
42
64
  ssh.make_new_folder(folder=name)
43
65
  ssh.upload_file(file="feed.xml", folder=name)
44
66
  ssh.upload_file(file="image.jpg", folder=name)
@@ -52,9 +74,13 @@ def main():
52
74
  args = parse_args()
53
75
 
54
76
  if args.feed_template:
55
- generate_feed_template()
77
+ return generate_feed_template()
56
78
  if args.new_pod_dir:
57
- new_podcast_dir(name=args.new_pod_dir)
79
+ return new_podcast_dir(name=args.new_pod_dir)
80
+ if args.download_feed:
81
+ return download_feed(name=args.download_feed)
82
+ if args.upload_feed:
83
+ return upload_feed(name=args.upload_feed)
58
84
 
59
85
  feed_template: str = """
60
86
  <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
@@ -20,7 +20,7 @@ from talklib.utils import today_is_weekday
20
20
 
21
21
  class Notifications(BaseModel):
22
22
  prefix: ClassVar[str] = None # prefix all messages with identifier for the show/podcast
23
- notify: Type[Notify] = Notify()
23
+ notify: ClassVar[Type[Notify]] = Notify()
24
24
 
25
25
  def prep_syslog(self, message: str, level: str = 'info'):
26
26
  '''send message to syslog server'''
@@ -67,6 +67,7 @@ class SSH(BaseModel):
67
67
  raise e
68
68
 
69
69
  def download_file(self, file: str, folder: str) -> None:
70
+ folder = folder.lower()
70
71
  try:
71
72
  self.notifications.prep_syslog(message=f"Attempting to download '{file}' from {folder}/ on server")
72
73
  self.connection.get(remote=f"shows/{folder}/{file}")
@@ -94,6 +95,7 @@ The error from the SSH library is: {e}"
94
95
  subject="Error")
95
96
 
96
97
  def make_new_folder(self, folder: str) -> None:
98
+ folder = folder.lower()
97
99
  if self.check_folder_exists_no_exception(folder=folder):
98
100
  raise Exception (f"{folder}/ already exists on server! Exiting...")
99
101
  self.connection.run(f"cd shows && mkdir {folder}", hide=True)
@@ -130,8 +132,12 @@ The error from the SSH library is: {e}"
130
132
  return ret_val
131
133
 
132
134
  def get_feed_from_folder(self, folder: str):
135
+ self.check_folder_exists(folder=folder)
133
136
  self.download_file(file="feed.xml", folder=folder)
134
137
 
138
+ def upload_feed_to_folder(self, folder:str):
139
+ self.upload_file(file="feed.xml", folder=folder)
140
+
135
141
  def check_folder_exists(self, folder: str) -> bool:
136
142
  self.notifications.prep_syslog(message=f"checking if {folder}/ exists on server...")
137
143
  folders = self.get_folders()
@@ -343,9 +349,9 @@ class TLPod(BaseModel):
343
349
  override_filename: bool = False
344
350
  audio_folders:list = EV().destinations
345
351
  notifications: Type[Notifications] = Notifications()
346
- episode: Type[Episode] = Episode(notifications=notifications)
352
+ episode: Type[Episode] = Episode()
347
353
  ffmpeg: Type[FFMPEG] = FFMPEG()
348
- ssh: Type[SSH] = SSH(notifications=notifications)
354
+ ssh: Type[SSH] = SSH()
349
355
 
350
356
  @model_validator(mode='after')
351
357
  def post_update(self):
@@ -366,6 +372,18 @@ class TLPod(BaseModel):
366
372
 
367
373
  return self
368
374
 
375
+ # @model_validator(mode='after')
376
+ # def confirm_SSH_connection(self):
377
+ # # before we carry on, make sure we can successfully connect to the server
378
+ # try:
379
+ # connection = self.ssh.connection.run("ls")
380
+ # except Exception as e:
381
+ # to_send:str = f"Cannot connect to server. Are you sure the SSH keys are set up correctly? Here is the error: {e}"
382
+ # self.notifications.send_notifications(message=to_send, subject="Error")
383
+ # raise e
384
+
385
+ # return self
386
+
369
387
  def get_filename_to_match(self) -> str:
370
388
  if self.override_filename:
371
389
  self.notifications.prep_syslog(message="filename override is turned ON")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: talklib
3
- Version: 3.1.0
3
+ Version: 3.2.1
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>
@@ -523,7 +523,7 @@ nyt.run()
523
523
 
524
524
  To disable ALL notifications, add a line like this:
525
525
 
526
- > This will disable all notifications **including** syslog messages
526
+ > This will disable all notifications **including** syslog messages (shell print statements will not be disabled)
527
527
 
528
528
  ````python
529
529
  from talklib import TLPod
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