Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update .env load logic #58

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ motor = "~=3.0"
natural = "~=0.2.0"
pymongo = {version = "*", extras = ['srv']} # Required by motor
python-dateutil = "~=2.8.2"
python-dotenv = "~=0.18.0"
sanic = "~=22.6.0"

[scripts]
Expand Down
88 changes: 9 additions & 79 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from sanic import Sanic, response
from sanic.exceptions import NotFound
from jinja2 import Environment, FileSystemLoader
from dotenv import load_dotenv

from core.models import LogEntry

load_dotenv()

if "URL_PREFIX" in os.environ:
print("Using the legacy config var `URL_PREFIX`, rename it to `LOG_URL_PREFIX`")
Expand All @@ -19,9 +21,10 @@
if prefix == "NONE":
prefix = ""

MONGO_URI = os.getenv("MONGO_URI")
MONGO_URI = os.getenv("MONGO_URI") or os.getenv("CONECTION_URI")
if not MONGO_URI:
MONGO_URI = os.environ['CONNECTION_URI']
print("No MONGO_URI config var found. Please enter your MongoDB connection URI in the configuration or .env file.")
exit(1)

app = Sanic(__name__)
app.static("/static", "./static")
Expand Down
14 changes: 7 additions & 7 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
import dateutil.parser

from sanic import response
Expand All @@ -12,10 +12,10 @@ def __init__(self, app, data):
self.app = app
self.key = data["key"]
self.open = data["open"]
self.created_at = dateutil.parser.parse(data["created_at"])
self.human_created_at = duration(self.created_at, now=datetime.utcnow())
self.created_at = dateutil.parser.parse(data["created_at"]).astimezone(timezone.utc)
self.human_created_at = duration(self.created_at, now=datetime.now(timezone.utc))
self.closed_at = (
dateutil.parser.parse(data["closed_at"]) if not self.open else None
dateutil.parser.parse(data["closed_at"]).astimezone(timezone.utc) if not self.open else None
)
self.channel_id = int(data["channel_id"])
self.guild_id = int(data["guild_id"])
Expand All @@ -35,7 +35,7 @@ def system_avatar_url(self):

@property
def human_closed_at(self):
return duration(self.closed_at, now=datetime.utcnow())
return duration(self.closed_at, now=datetime.now(timezone.utc))

@property
def message_groups(self):
Expand Down Expand Up @@ -165,8 +165,8 @@ def __init__(self, data):
class Message:
def __init__(self, data):
self.id = int(data["message_id"])
self.created_at = dateutil.parser.parse(data["timestamp"])
self.human_created_at = duration(self.created_at, now=datetime.utcnow())
self.created_at = dateutil.parser.parse(data["timestamp"]).astimezone(timezone.utc)
self.human_created_at = duration(self.created_at, now=datetime.now(timezone.utc))
self.raw_content = data["content"]
self.content = self.format_html_content(self.raw_content)
self.attachments = [Attachment(a) for a in data["attachments"]]
Expand Down
1 change: 1 addition & 0 deletions passenger_wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from app import app as application
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ multidict==6.0.2; python_version >= '3.7'
natural==0.2.0
pymongo[srv]==4.2.0
python-dateutil==2.8.2
python-dotenv==0.18.0
sanic==22.6.2
sanic-routing==22.3.0
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
Expand Down