-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically extract the download URL from the feed #47
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import feedparser | ||
|
||
from typing import Union | ||
from lxml import html | ||
|
||
|
||
default_feed = "http://www.country-files.com/category/big-cty/feed/" | ||
|
@@ -172,7 +173,9 @@ def update(self) -> bool: | |
|
||
with tempfile.TemporaryDirectory() as temp: | ||
path = pathlib.PurePath(temp) | ||
dl_url = f'http://www.country-files.com/bigcty/download/{update_date[:4]}/bigcty-{update_date}.zip' # TODO: Issue #10 | ||
page = session.get(update_url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably check for status before trying to parse the content There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed |
||
tree = html.fromstring(page.content) | ||
dl_url = tree.xpath("//a[contains(@href,'zip')]/@href")[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed |
||
rq = session.get(dl_url) | ||
if rq.status_code == 404: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this codepath still necessary? I think it exists because there was a change in the feed bafa05d There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that fallback is needed, but very differently, and only if the download URL extraction fails (see other comment) |
||
dl_url = f'http://www.country-files.com/bigcty/download/bigcty-{update_date}.zip' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ sphinx | |
# Dependencies | ||
feedparser | ||
requests | ||
lxml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is lxml not needed as a normal dependency? This file is only used for development, so |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be good to keep that URL as a fallback, like the other URL format already is