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