Skip to content

Commit 656d17b

Browse files
committed
Make system agnostic to where it is hosted
1 parent 5a4fbf3 commit 656d17b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<body>
1414

1515
<div class="card">
16-
<a href="https://folk.ntnu.no/hermasl/light" style="text-decoration: none;">
16+
<a href="." style="text-decoration: none;">
1717
<div id="header">
1818
<!--<img id="banner" src="logo.svg">-->
1919
<span style="color: rgb(0, 80, 158);">CHALLENGE</span><br>

mail.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
import subprocess
99
import email.mime.text
10+
import os
1011

1112
def mail(recipient, subject, text):
1213
msg = email.mime.text.MIMEText(text, "html")
@@ -79,7 +80,7 @@ def add_subscriber(email):
7980
subscribers = subscribers[len(subscribers)-1000:]
8081
write_subscribers(subscribers, confirmed=False)
8182

82-
link = "http://folk.ntnu.no/hermasl/light/confirm_subscription.php"
83+
link = f"{get_site_root()}/confirm_subscription.php"
8384
link += "?email=" + email + "&code=" + code
8485

8586
subject = "Bekreftelse av varsling ved måling av lysslukking"
@@ -128,7 +129,7 @@ def notify():
128129
subject = "Noen målte nettopp lyset på Fysikkland!"
129130

130131
text_common = ""
131-
text_common += "Navigér til <a href=\"http://folk.ntnu.no/hermasl/light\">folk.ntnu.no/hermasl/light</a> for å se målingen!\n"
132+
text_common += f"Navigér til <a href=\"{get_site_root(prefix=True)}\">{get_site_root(prefix=False)}</a> for å se målingen!\n"
132133
text_common += "\n"
133134
text_common += "Som medlem av Fysikklandlysets epostliste bidrar du til sikker arkivering av lysloggen gjennom et distribuert blockchain-inspirert sikkerhetskopieringssystem.\n"
134135
text_common += "Du vil derfor finne en kopi av lysloggen under.\n"
@@ -146,7 +147,7 @@ def notify():
146147
for subscriber in read_subscribers():
147148
code = subscriber[0]
148149
recipient = subscriber[1]
149-
link = "http://folk.ntnu.no/hermasl/light/unsubscribe.php"
150+
link = f"{get_site_root()}/unsubscribe.php"
150151
link += "?email=" + recipient + "&code=" + code
151152
text_unique = "Dersom du ikke lenger ønsker å varsles når lysslukkingen på Fysikkland registreres, kan du avslutte ditt abonnement <a href=\"%s\">her</a>." % link
152153

@@ -161,3 +162,13 @@ def create_confirmation_code():
161162
for i in range(0, 30):
162163
code += random.choice(string.ascii_lowercase)
163164
return code
165+
166+
def get_ntnu_username():
167+
cwd = os.getcwd() # e.g. /web/folk/hermasl/light
168+
return cwd.split("/")[3] # e.g. hermasl
169+
170+
def get_site_root(prefix=True):
171+
if prefix:
172+
return f"http://folk.ntnu.no/{get_ntnu_username()}/light" # e.g. https://folk.ntnu.no/hermasl/light
173+
else:
174+
return f"folk.ntnu.no/{get_ntnu_username()}/light" # e.g. folk.ntnu.no/hermasl/light

0 commit comments

Comments
 (0)