From 916c567207ca399767f8237cc9a0c3f004f02bbd Mon Sep 17 00:00:00 2001 From: Rune Olsen Date: Mon, 9 Sep 2024 15:41:20 +0200 Subject: [PATCH] Add possibilty to limit to .no or .se. Use: ./app.py E.g.: ./app.py 4 no or ./app.py 0 se --- app.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 1d39f36..149b488 100755 --- a/app.py +++ b/app.py @@ -9,19 +9,39 @@ from bs4 import BeautifulSoup try: max_len = int(sys.argv[1]) + if max_len == 0: + max_len = None except IndexError: max_len = None +try: + top_domain = str(sys.argv[2]) +except IndexError: + top_domain = None def cleanlist(my_list): + retList = [] + retListDomain = [] if max_len != None: - retList = [] for x in my_list: if len(x) <= (max_len + 3): retList.append(x) - return retList - else: + if top_domain != None and len(retList) != 0: + for x in retList: + if x[-2:] == top_domain: + retListDomain.append(x) + elif top_domain != None and len(retList) == 0: + for x in my_list: + if x[-2:] == top_domain: + retListDomain.append(x) + + if len(retList) == 0 and len(retListDomain) == 0: return my_list + elif top_domain == None: + return retList + else: + return retListDomain + def fetch():