diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 00000000..d657a63b --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) diff --git a/app.py b/app.py index 8722d425..b36a211a 100755 --- a/app.py +++ b/app.py @@ -106,7 +106,7 @@ def get_language_by_guessing(self, text): with suppress(Exception): lang = detect(text) if lang and lang != "": - return self.languages_json[lang] + " (Maybe)" + return f"{self.languages_json[lang]} (Maybe)" return "unavailable" def get_language_by_parsing(self, source, encoding): @@ -129,14 +129,13 @@ def decorator(func): @wraps(func) def wrapper(*args, **kwargs): if on_off: - try: + with suppress(Exception): return func(*args, **kwargs) - except Exception as err: - pass - # if not self.silent: self.log.info(e) else: return func(*args, **kwargs) + return wrapper + return decorator def setup_logger(self, uuid=None, file=False, argv=None): @@ -163,39 +162,41 @@ def emit(self, record): emit, based on user choices ''' - if self.argv.output != "json" and self.sa_object.silent == False: - if isinstance(record.msg, Mapping): - if "custom" in record.msg: - for item in record.msg["custom"]: - with suppress(Exception): - if item == record.msg["custom"][0]: - print("-----------------------") - for key, value in item.items(): - if key == "metadata" or key == "extracted": - if (self.argv.metadata and key == "metadata") or (self.argv.extract and key == "extracted"): - with suppress(Exception): - for idx, _item in enumerate(value): - empty_string = key + " " + str(idx) - empty_string = colored(empty_string.ljust(13, ' '), 'blue') + ": " - for _item_key, _item_value in _item.items(): - if self.argv.trim and _item_key == "content" and len(_item_value) > 50: - empty_string += "{} : {} ".format(colored(_item_key, 'blue'), colored(_item_value[:50] + "..", 'yellow')) - else: - empty_string += "{} : {} ".format(colored(_item_key, 'blue'), colored(_item_value, 'yellow')) - print("{}".format(empty_string)) - else: - print(colored(key.ljust(13, ' '), 'blue'), colored(value, 'yellow'), sep=": ") + if self.argv.output == "json" or self.sa_object.silent != False: + return + if isinstance(record.msg, Mapping): + if "custom" in record.msg: + for item in record.msg["custom"]: + with suppress(Exception): + if item == record.msg["custom"][0]: print("-----------------------") - else: - print(record.msg) + for key, value in item.items(): + if ( + key == "metadata" + and self.argv.metadata + or key != "metadata" + and key == "extracted" + and self.argv.extract + ): + with suppress(Exception): + for idx, _item in enumerate(value): + empty_string = f"{key} {str(idx)}" + empty_string = colored(empty_string.ljust(13, ' '), 'blue') + ": " + for _item_key, _item_value in _item.items(): + if self.argv.trim and _item_key == "content" and len(_item_value) > 50: + empty_string += f"""{colored(_item_key, 'blue')} : {colored(f"{_item_value[:50]}..", 'yellow')} """ + else: + empty_string += f"{colored(_item_key, 'blue')} : {colored(_item_value, 'yellow')} " + print(f"{empty_string}") + elif key not in ["metadata", "extracted"]: + print(colored(key.ljust(13, ' '), 'blue'), colored(value, 'yellow'), sep=": ") + print("-----------------------") + else: + print(record.msg) temp_folder = '' if argv.logs: - if self.logs_dir != '': - temp_folder = self.logs_dir - else: - temp_folder = mkdtemp() - + temp_folder = self.logs_dir if self.logs_dir != '' else mkdtemp() if file and uuid: if argv.screenshots: self.screenshots = True @@ -214,7 +215,7 @@ def emit(self, record): if argv.logs and argv.output != "json": if not self.silent: - self.log.info('[init] Temporary Logs Directory {}'.format(temp_folder)) + self.log.info(f'[init] Temporary Logs Directory {temp_folder}') def init_detections(self, detections): ''' @@ -245,8 +246,7 @@ def search_and_change(self, site, _dict): def top_websites(self, top_number): with suppress(Exception): - top_websites = research(self.top_pattern, top_number) - if top_websites: + if top_websites := research(self.top_pattern, top_number): sites = ([d for d in self.websites_entries if d.get('global_rank') != 0]) sites = sorted(sites, key=lambda x: x['global_rank']) for site in sites[:int(top_websites.group(1))]: @@ -282,7 +282,7 @@ def fetch_url(self, site, username, options): checking_url = get_fld(site["url"]) checking_url = checking_url.replace(".{username}", "").replace("{username}.", "") if not self.silent: - self.log.info("[Checking] " + checking_url) + self.log.info(f"[Checking] {checking_url}") source = "" @@ -311,7 +311,7 @@ def fetch_url(self, site, username, options): source = response.text content = response.content encoding = response.encoding - answer = dict((k.lower(), v.lower()) for k, v in response.headers.items()) + answer = {k.lower(): v.lower() for k, v in response.headers.items()} session.close() temp_profile = {} temp_detected = {} @@ -324,7 +324,7 @@ def check_url(url): with suppress(Exception): result = urlparse(url) - if result.scheme == "http" or result.scheme == "https": + if result.scheme in ["http", "https"]: return all([result.scheme, result.netloc]) return False @@ -441,7 +441,7 @@ def detect(): temp_matches.append(parsed) temp_matches_list.append({"name": item["type"], "value": unquote(match)}) - if len(temp_matches_list) > 0: + if temp_matches_list: temp_profile["extracted"] = temp_matches_list temp_profile["text"] = temp_profile["text"].replace("\n", "").replace("\t", "").replace("\r", "").strip() @@ -466,7 +466,7 @@ def detect(): with suppress(Exception): if detections_count != 0: temp_value = round(((temp_profile["found"] / detections_count) * 100), 2) - temp_profile["rate"] = "%" + str(temp_value) + temp_profile["rate"] = f"%{str(temp_value)}" if temp_value >= 100.00: temp_profile["status"] = "good" elif temp_value >= 50.00 and temp_value < 100.00: @@ -487,14 +487,20 @@ def detect(): temp_mata_item = {} add = True if meta.has_attr("property"): - temp_mata_item.update({"property": meta["property"]}) + temp_mata_item["property"] = meta["property"] if meta.has_attr("content"): if meta["content"].replace("\n", "").replace("\t", "").replace("\r", "").strip() != "": - temp_mata_item.update({"content": meta["content"].replace("\n", "").replace("\t", "").replace("\r", "").strip()}) + temp_mata_item["content"] = ( + meta["content"] + .replace("\n", "") + .replace("\t", "") + .replace("\r", "") + .strip() + ) if meta.has_attr("itemprop"): - temp_mata_item.update({"itemprop": meta["itemprop"]}) + temp_mata_item["itemprop"] = meta["itemprop"] if meta.has_attr("name"): - temp_mata_item.update({"name": meta["name"]}) + temp_mata_item["name"] = meta["name"] with suppress(Exception): if "property" in temp_mata_item: @@ -516,7 +522,7 @@ def detect(): temp_meta_list[i]["content"] += ", " + temp_mata_item["content"] add = False - if len(temp_mata_item) > 0 and add: + if temp_mata_item and add: temp_meta_list.append(temp_mata_item) if len(temp_meta_list) > 0: diff --git a/clean-up.logs b/clean-up.logs index b462d0b9..91d898e3 100755 --- a/clean-up.logs +++ b/clean-up.logs @@ -1,4 +1,4 @@ -Tue Aug 8 22:26:51 UTC 2023 +Fri Dec 1 09:15:48 UTC 2023 [X] social-analyzer [X] installing autopep8 & jq [X] running autopep8