talklib 2.1.0__tar.gz → 2.1.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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: talklib
3
- Version: 2.1.0
3
+ Version: 2.1.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>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "talklib"
3
- version = "2.1.0"
3
+ version = "2.1.2"
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"}
@@ -169,7 +169,25 @@ class Episode(BaseModel):
169
169
  result = f"{minutes}:{seconds:02}"
170
170
  self.notifications.prep_syslog(message=f"itunes:duration will be {result}")
171
171
  return result
172
-
172
+
173
+ def check_for_duplicate_episode(self, title: str):
174
+ self.notifications.prep_syslog(message="checking for duplicate episode...")
175
+ if title == self.episode_title:
176
+ self.cleanup_files_on_abort()
177
+ to_send = "Found episode with identical title already in feed. Aborting..."
178
+ self.notifications.send_notifications(message=to_send, subject="Error")
179
+ raise Exception (to_send)
180
+ self.notifications.prep_syslog(message="no duplicate episode found")
181
+ return
182
+
183
+ def cleanup_files_on_abort(self):
184
+ files = glob.glob("*.mp3")
185
+ for file in files:
186
+ self.notifications.prep_syslog(message=f"Aborting automation, deleting local temp files: {file}")
187
+ os.remove(file)
188
+ self.notifications.prep_syslog(message=f"Aborting automation, deleting local temp files: feed.xml")
189
+ os.remove("feed.xml")
190
+
173
191
  def add_new_episode(self):
174
192
  '''Create an 'item' element. Then create all of the necessary sub elements and append them to the item element'''
175
193
  ET.register_namespace(prefix="atom", uri="http://www.w3.org/2005/Atom")
@@ -178,6 +196,12 @@ class Episode(BaseModel):
178
196
  root = feed.getroot()
179
197
  root = root.find('channel')
180
198
 
199
+ # if we have a new feed, or a feed with no episodes
200
+ try:
201
+ self.check_for_duplicate_episode(title=root.find("item").find("title").text)
202
+ except:
203
+ pass
204
+
181
205
  self.notifications.prep_syslog(message="Building the new <item> element")
182
206
  item = ET.Element('item')
183
207
 
@@ -277,23 +277,29 @@ Is this a permalink show? Did you forget to set the is_permalink attribute?\n\n\
277
277
  a standards organization. Most podcasts/RSS feeds follow this standard.
278
278
  '''
279
279
  root = self.__get_feed()
280
- for channel in root.findall('channel'):
281
- item = channel.find('item') # 'find' only returns the first match!
282
- pub_date = item.find('pubDate').text
283
- today = datetime.now().strftime("%a, %d %b %Y")
284
- if today in pub_date:
285
- self.__prep_syslog(message='The feed is updated.')
286
- return True
280
+ channel = root.find('channel')
281
+ item = channel.find('item') # 'find' only returns the first match!
282
+ pub_date = item.find('pubDate').text
283
+ today = datetime.now().strftime("%a, %d %b %Y")
284
+ if today in pub_date:
285
+ self.__prep_syslog(message='The feed is updated.')
286
+ return True
287
287
 
288
288
  def __get_RSS_audio_url(self) -> str:
289
289
  '''TODO: explain'''
290
290
  root = self.__get_feed()
291
- for channel in root.findall('channel'):
292
- item = channel.find('item') # 'find' only returns the first match!
291
+ channel = root.find('channel')
292
+ item = channel.find('item') # 'find' only returns the first match!
293
+ try:
293
294
  audio_url = item.find('enclosure').attrib
294
295
  audio_url = audio_url.get('url')
295
296
  self.__prep_syslog(message=f'Audio URL is: {audio_url}')
296
297
  return audio_url
298
+ except AttributeError as AE:
299
+ to_send = f"There's a Problem with {self.show}. \
300
+ There is no 'enclosure' tag for the item. Here's the error: {AE}\n\n\{get_timestamp()}"
301
+ self.__send_notifications(message=to_send, subject="error")
302
+ raise_exception_and_wait(message=to_send, error=AE)
297
303
 
298
304
  def __check_feed_loop(self) -> str:
299
305
  '''
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: talklib
3
- Version: 2.1.0
3
+ Version: 2.1.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>
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