Fixing scripts
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
fail_fast: true
|
||||
repos:
|
||||
- repo: https://github.com/adamchainz/djade-pre-commit
|
||||
rev: "1.3.2" # Replace with the latest tag on GitHub
|
||||
rev: "1.4.0" # Replace with the latest tag on GitHub
|
||||
hooks:
|
||||
- id: djade
|
||||
args: [--target-version, "4.2"] # Replace with Django version
|
||||
- repo: https://github.com/pycqa/bandit
|
||||
rev: 1.8.3
|
||||
hooks:
|
||||
- id: bandit
|
||||
args: ["-iii", "-ll"]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 25.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
language_version: python3.9
|
||||
language_version: python3.12
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
@@ -38,7 +33,7 @@ repos:
|
||||
rev: v3.19.1
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py311-plus]
|
||||
args: [--py312-plus]
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 7.2.0
|
||||
hooks:
|
||||
|
||||
29
hydra.py
29
hydra.py
@@ -26,7 +26,7 @@ class Config:
|
||||
|
||||
if config_filename != "":
|
||||
# Update settings if there is a config file
|
||||
with open(config_filename, "r") as file:
|
||||
with open(config_filename) as file:
|
||||
file_text = file.read()
|
||||
config_json = json.loads(file_text)
|
||||
self.tags = config_json.get("tags", self.tags)
|
||||
@@ -37,7 +37,9 @@ class Config:
|
||||
self.threads = config_json.get("threads", self.threads)
|
||||
self.timeout = config_json.get("timeout", self.timeout)
|
||||
self.OK = config_json.get("OK", self.OK)
|
||||
self.graceful_exit = config_json.get("graceful_exit", self.graceful_exit)
|
||||
self.graceful_exit = config_json.get(
|
||||
"graceful_exit", self.graceful_exit
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
text = (
|
||||
@@ -55,7 +57,7 @@ class Parser(HTMLParser):
|
||||
"""Parse tags found in webpages to get more links to check"""
|
||||
|
||||
def __init__(self, config):
|
||||
super(Parser, self).__init__()
|
||||
super().__init__()
|
||||
self.links = []
|
||||
self.config = config
|
||||
|
||||
@@ -101,7 +103,7 @@ class Checker:
|
||||
self.broken = []
|
||||
self.domain = extract_domain(url)
|
||||
self.visited = set()
|
||||
self.mailto_links = list()
|
||||
self.mailto_links = []
|
||||
self.pool = futures.ThreadPoolExecutor(max_workers=self.config.threads)
|
||||
self.report = ""
|
||||
|
||||
@@ -120,7 +122,7 @@ class Checker:
|
||||
self.broken.append(entry)
|
||||
|
||||
def load_url(self, page, timeout):
|
||||
""" Try to retrieve contents of a page and record result
|
||||
"""Try to retrieve contents of a page and record result
|
||||
Store the link to be checked and its parent in the result
|
||||
"""
|
||||
result = {
|
||||
@@ -138,7 +140,7 @@ class Checker:
|
||||
},
|
||||
)
|
||||
|
||||
try:
|
||||
try: # noqa: B025
|
||||
http_response = request.urlopen(r, timeout=self.config.timeout)
|
||||
|
||||
encoding = http_response.headers.get("Content-Encoding")
|
||||
@@ -205,10 +207,10 @@ class Checker:
|
||||
parser = Parser(self.config)
|
||||
links = parser.feed_me(page["data"])
|
||||
new_links = [x for x in links if x not in self.visited]
|
||||
full_links = [parse.urljoin(parent, l) for l in new_links]
|
||||
for l in full_links:
|
||||
if l not in self.visited:
|
||||
li = {"parent": parent, "url": l}
|
||||
full_links = [parse.urljoin(parent, element) for element in new_links]
|
||||
for element in full_links:
|
||||
if element not in self.visited:
|
||||
li = {"parent": parent, "url": element}
|
||||
self.TO_PROCESS.put(li)
|
||||
|
||||
def make_report(self):
|
||||
@@ -223,7 +225,10 @@ class Checker:
|
||||
self.report += "\n---\n"
|
||||
sorted_list = sorted(self.broken, key=lambda k: k["code"], reverse=True)
|
||||
for link in sorted_list:
|
||||
self.report += f"\n- code: {link['code']}\n url: {link['link']}\n parent: {link['parent']}\n error: {link['err']}\n"
|
||||
self.report += (
|
||||
f"\n- code: {link['code']}\n url: {link['link']}\n"
|
||||
+ f" parent: {link['parent']}\n error: {link['err']}\n"
|
||||
)
|
||||
return self.report
|
||||
|
||||
def run(self):
|
||||
@@ -232,7 +237,7 @@ class Checker:
|
||||
try:
|
||||
target_url = self.TO_PROCESS.get(block=True, timeout=4)
|
||||
if target_url["url"].startswith("mailto:"):
|
||||
email = target_url["url"][len("mailto:") :]
|
||||
email = target_url["url"][len("mailto:") :] # noqa: E203
|
||||
self.mailto_links.append(email)
|
||||
|
||||
elif target_url["url"] not in self.visited:
|
||||
|
||||
24
make-post.py
24
make-post.py
@@ -1,28 +1,31 @@
|
||||
import datetime
|
||||
import os
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
import random
|
||||
|
||||
|
||||
def post_photo():
|
||||
# get the current year as variable
|
||||
year = str(datetime.datetime.now().year)
|
||||
name = input("Give me the title\n")
|
||||
os.system(f"hugo new photos/{year}/{name.replace(' ','-').replace(',','').lower()}/index.md")
|
||||
os.system(
|
||||
f"hugo new photos/{year}/{name.replace(' ', '-').replace(',', '').lower()}/index.md"
|
||||
)
|
||||
|
||||
|
||||
def post_redirect():
|
||||
# get the current year as variable
|
||||
name = input("Give me the title\n")
|
||||
os.system(f"hugo new redirect/{name.replace(' ','-').replace(',','').lower()}/index.md")
|
||||
os.system(
|
||||
f"hugo new redirect/{name.replace(' ', '-').replace(',', '').lower()}/index.md"
|
||||
)
|
||||
|
||||
|
||||
def post_fc():
|
||||
# get the current year as variable
|
||||
year = str(datetime.datetime.now().year)
|
||||
name = input("Give me the title\n")
|
||||
os.system(f"hugo new post/{year}/{name.replace(' ','-').replace(',','').lower()}/index.md")
|
||||
os.system(
|
||||
f"hugo new post/{year}/{name.replace(' ', '-').replace(',', '').lower()}/index.md"
|
||||
)
|
||||
|
||||
|
||||
def micro_fc():
|
||||
@@ -30,13 +33,18 @@ def micro_fc():
|
||||
name = input("Give me the title\n")
|
||||
year = str(datetime.datetime.now().year)
|
||||
month = str(datetime.datetime.now().month)
|
||||
generated = f"{year.ljust(4,"0")}/{month.ljust(2,"0")}/{name.replace(' ', '-').replace(',', '').lower()}"
|
||||
generated = f"{year.ljust(4, "0")}/{month.ljust(2, "0")}/{name.replace(' ', '-').replace(',', '').lower()}"
|
||||
|
||||
os.system(f"hugo new micro/{generated}/index.md")
|
||||
print(f"Generated {generated}/index.md")
|
||||
|
||||
|
||||
ANSWER = {"post": post_fc, "micro": micro_fc, 'photo': post_photo, 'redirect': post_redirect}
|
||||
ANSWER = {
|
||||
"post": post_fc,
|
||||
"micro": micro_fc,
|
||||
"photo": post_photo,
|
||||
"redirect": post_redirect,
|
||||
}
|
||||
|
||||
|
||||
def main_checker():
|
||||
|
||||
1
makefile
1
makefile
@@ -30,6 +30,7 @@ gomodule: ## Update Go Module
|
||||
.PHONY: hydra
|
||||
hydra: ## Check links
|
||||
@python hydra.py http://localhost:1313/ --config ./hydra-config.json
|
||||
@python hydra.py http://fundor333.com/ --config ./hydra-config.json
|
||||
|
||||
.PHONY: syntax
|
||||
syntax: ## Build the style of the code
|
||||
|
||||
@@ -46,7 +46,7 @@ else:
|
||||
# Now let's check if the user provided a valid account
|
||||
if not valid_account:
|
||||
# Sorry, it's a no go.
|
||||
print(f"'{account}' doesn't look like a valid Mastodon account.")
|
||||
print(f"{account!r} doesn't look like a valid Mastodon account.")
|
||||
exit(-1)
|
||||
|
||||
# If the user provided a valid account,
|
||||
@@ -64,14 +64,14 @@ webfinger_file = os.path.join(well_known_dir, "webfinger")
|
||||
# Let's check if a 'static' directory already exists
|
||||
if not os.path.exists(static_dir):
|
||||
# Nope. We need to create it
|
||||
print(f"Creating static directory at '{static_dir}'")
|
||||
print(f"Creating static directory at {static_dir!r}")
|
||||
os.makedirs(static_dir)
|
||||
|
||||
# Let's check if a '.well-known' sub-directory
|
||||
# already exists inside of the 'static' directory
|
||||
if not os.path.exists(well_known_dir):
|
||||
# Nope. We need to create it
|
||||
print(f"Creating static/.well-known directory at '{well_known_dir}'")
|
||||
print(f"Creating static/.well-known directory at {well_known_dir!r}")
|
||||
os.makedirs(well_known_dir)
|
||||
|
||||
# Let's download the Mastodon account's webfinger file
|
||||
@@ -80,7 +80,7 @@ try:
|
||||
urlretrieve(url, webfinger_file)
|
||||
except URLError:
|
||||
# Uh Oh, something went wrong
|
||||
print(f"Couldn't connect to '{url}'")
|
||||
print(f"Couldn't connect to {url!r}")
|
||||
quit(-1)
|
||||
|
||||
# Everything is done
|
||||
|
||||
@@ -28,6 +28,6 @@ def get_url_from_feed(feed_url: str):
|
||||
send_webmention(link.link)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
for url in feed_url:
|
||||
get_url_from_feed(url)
|
||||
|
||||
Reference in New Issue
Block a user