Skip to content

Commit

Permalink
reverse sort timezone output (elm/time#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
piratejon committed Mar 13, 2019
1 parent 9470595 commit e2308c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion birdplans/tzhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def make_tzinfo(tz, window_start, window_stop):

changes = [
make_tzinfo_entry(tz.localize(_))
for _ in tz._utc_transition_times # pylint: disable=protected-access
for _ in sorted(tz._utc_transition_times) # pylint: disable=protected-access
if window_start <= pytz.utc.localize(_) <= window_stop
]

Expand All @@ -41,4 +41,6 @@ def make_tzinfo(tz, window_start, window_stop):
if end_entry['offset'] != changes[-1]['offset']:
changes = changes + [end_entry]

changes = sorted(changes, key=lambda x: x['start'], reverse=True)

return changes
18 changes: 15 additions & 3 deletions birdplans/uwsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,21 @@ def default_handler(self, env, start_response):
'''Default handler, returns the main application.
'''

with open('static/index.html', 'r') as fin:
start_response('200 OK', [('Content-Type', 'text/html; charset=' + self.encoding)])
yield bytes(fin.read(), self.encoding) # TODO less sponge plz
index = uwsgi.cache_get('./static/index.html')
if index is None:
with open('static/index.html', 'r') as fin:
index = bytes(fin.read(), self.encoding)
uwsgi.cache_set('./static/index.html', index)
print('set cache for index')
else:
print('using cached copy')

start_response('200 OK', [
('Content-Type', 'text/html; charset=' + self.encoding)
, ('Yark-Content-Type', 'text/html; charset=' + self.encoding)
])

yield index

@staticmethod
def decode_grid(grid):
Expand Down
4 changes: 3 additions & 1 deletion launch_uwsgi.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash

tip=`git rev-parse HEAD 2>/dev/null || echo none`
uwsgi --http :9090 --wsgi-file birdplans/uwsgi.py --master --processes 8 --pyargv $tip --safe-pidfile ./pidfile.txt --check-static static
diff=`git diff --quiet && echo 0 || echo 1`
uwsgi --http :9090 --wsgi-file birdplans/uwsgi.py --master --processes 8 --safe-pidfile ./pidfile.txt --check-static static --add-header "Tip: ${tip}.${diff}" --add-header 'Cache-Control: public, max-age=315360000' --load-file-in-cache ./static/index.html

0 comments on commit e2308c1

Please sign in to comment.