Skip to content

Commit f7ce497

Browse files
committed
Adds basic Auth to mw2html
1 parent a520c3c commit f7ce497

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

.github/workflows/update_manual.yml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Update Audacity Manual
33
on:
44
workflow_dispatch:
55

6+
env:
7+
MW2HTML_USER: ${{ secrets.MW2HTML_USER }}
8+
MW2HTML_PASSWORD: ${{ secrets.MW2HTML_PASSWORD }}
9+
610
jobs:
711
update:
812
runs-on: ubuntu-latest

scripts/mw2html_audacity/mw2html.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
__version__ = '0.1.0.3'
2323

24+
import base64
2425
import re
2526
import sys
2627
import getopt
@@ -269,7 +270,7 @@ def pre_html_transform(doc, url):
269270
doc = fix_move_href_tags(doc)
270271
if config.remove_history:
271272
doc = html_remove_image_history(doc)
272-
273+
273274
doc = html_remove_translation_links(doc)
274275

275276
return doc
@@ -449,7 +450,7 @@ def monobook_hack_skin_css(doc, url):
449450
'\n/* end edit by mw2html */\n')
450451

451452
doc = doc.replace('h3 { font-size: 90%; }', 'h3 { font-size: 130%; }')
452-
453+
453454
# Remove external link icons.
454455
if config.remove_png:
455456
doc = re.sub(r'#bodyContent a\[href \^="https://"\][\s\S]+?\}', r'', doc)
@@ -681,14 +682,14 @@ def url_to_filename(url):
681682
if L[4].startswith('title=') and L[2].endswith('index.php'):
682683
L[4] = L[4][len('title='):]
683684
L[2] = L[2][:-len('index.php')]
684-
685+
685686
if lpath[-1]=='man':
686687
L[2] = INDEX_HTML
687688
if lpath[-1].lower().startswith( 'quick_help'):
688689
L[2] = QHELP_HTML
689690
L[3] = ''
690-
691-
691+
692+
692693

693694
L[2] = L[2].strip('/')
694695

@@ -881,7 +882,7 @@ def should_follow(url):
881882
# JKC: we do allow css from 'strange' places.
882883
if '.css' in L[-1]:
883884
return True
884-
885+
885886
forbidden_parents = ['.php', '.html', '.htm']
886887
for fp in forbidden_parents:
887888
if fp in L[-1]:
@@ -915,7 +916,7 @@ def parse_html(doc, url, filename):
915916

916917
# in this code we change each absolute url in L
917918
# into a relative one.
918-
# we also kick-off zillions of subthreads to collect
919+
# we also kick-off zillions of subthreads to collect
919920
# more pages.
920921
for item in L:
921922
u = item.url
@@ -1059,14 +1060,14 @@ def run(out=sys.stdout):
10591060
if config.debug:
10601061
out.write(url + '\n => ' + filename + '\n\n')
10611062
n += 1
1062-
1063+
10631064
# Enqueue URLs that we haven't yet spidered.
10641065
for u in new_urls:
10651066
if normalize_url(u) not in complete:
10661067
# Strip off any #section link.
10671068
if '#' in u:
10681069
u = u[:u.index('#')]
1069-
pending.add(u)
1070+
pending.add(u)
10701071

10711072
conn.close()
10721073
print("connection to", domain, "closed.")
@@ -1202,6 +1203,10 @@ def main():
12021203
if opt in ['-i', '--index']:
12031204
config.index = arg
12041205

1206+
user = os.environ.get('MW2HTML_USER', '')
1207+
passw = os.environ.get('MW2HTML_PASSWORD', '')
1208+
if user != '' and passw != '':
1209+
headers["Authorization"] = "Basic {}".format(base64.b64encode(bytes(f"{user}:{passw}", "utf-8")).decode("ascii"))
12051210
# Run program
12061211
run()
12071212

0 commit comments

Comments
 (0)