commit 9a1ce4aacc0674fa6f15629b7cbe54c220cc99c4
parent 659bf81bfec12e471099b0ab83e4b06c0126cda9
Author: Isak Lindhé <isak.e.lindhe@gmail.com>
Date: Thu, 20 Dec 2018 23:13:41 +0100
better input validation
Diffstat:
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/txtv.py b/txtv.py
@@ -11,22 +11,22 @@ def err(txt):
def get_page_number() -> int:
+ if len(sys.argv) > 2:
+ err('Maybe we will support more arguments in the future, but not today.')
if len(sys.argv) == 1:
return 100
try:
num = int(sys.argv[1])
except ValueError:
err('txtv <PAGE>\nexample: txtv 130')
- if num < 0:
- err('don\'t be so negative.')
+ if num < 100 or num > 999:
+ err('Text tv pages range from 100 to 999')
return num
def get_page(num) -> list:
res = rq.get(f'https://www.svt.se/svttext/web/pages/{num}.html')
- if res.status_code == 404:
- err(f'There is no page number {num}. Pretty sure they start at 100.')
- elif res.status_code != 200:
+ if res.status_code != 200:
err(f'When i tried to get the page i just got HTTP status code {res.status_code}.')
soup = bs4.BeautifulSoup(res.content, 'html.parser')
root = soup.find('pre', class_='root')