Skip to content

Commit 3480ef3

Browse files
committed
installed a global opener for urlopen - works great!
1 parent d65ab0a commit 3480ef3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tuipod/models/podcast.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def remove_episode(self, url: str) -> None:
2828
break
2929

3030
def get_episode_list(self) -> []:
31-
req = urllib.request.Request(self.url)
32-
req.add_header("User-Agent", "Mozilla/9.9 (github.com/mwhickson/tuipod) Chrome/999.9.9.9 Gecko/99990101 Firefox/999 Safari/999.9")
33-
with urllib.request.urlopen(req) as response:
31+
with urllib.request.urlopen(self.url) as response:
3432
result = response.read()
3533

3634
episodes = ET.fromstring(result)

tuipod/ui/podcast_app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22

3+
from urllib.request import build_opener, install_opener
4+
35
from textual import on
46
from textual.app import App, ComposeResult
57
from textual.binding import Binding
@@ -42,6 +44,12 @@ def __init__(self):
4244
self.current_podcast = None
4345
self.current_episode = None
4446

47+
# REF: https://theorangeone.net/posts/urllib-useragent/#global-opener
48+
# NOTE: _opener is not available for import, but it's not necessary (presumably within an app context)
49+
opener = build_opener()
50+
install_opener(opener)
51+
opener.addheaders = [("User-Agent", "Mozilla/9.9 (github.com/mwhickson/tuipod) Chrome/999.9.9.9 Gecko/99990101 Firefox/999 Safari/999.9")]
52+
4553
def compose(self) -> ComposeResult:
4654
yield Header(icon="#", show_clock=True, time_format="%I:%M %p")
4755

0 commit comments

Comments
 (0)