-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from Sakuten/feature/183-generate-media-to-an…
…nounce `/render_results`エンドポイントの追加
- Loading branch information
Showing
7 changed files
with
320 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
return PDF file that contains the results of previous lotteries | ||
--- | ||
produces: | ||
- application/pdf | ||
responses: | ||
'200': | ||
description: PDF file which contains whole winners for previous winners | ||
schema: | ||
type: file | ||
'400': | ||
description: not acceptable time | ||
schema: | ||
$ref: '#/definitions/ErrorMessage' | ||
summary: return PDF file that contains the results of previous lotteries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title></title> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<style> | ||
body { | ||
color: gray; | ||
} | ||
:root { | ||
--a0-height: 1133.5mm; | ||
--a0-width: 806mm; | ||
} | ||
html { | ||
font-size: 15mm; | ||
font-family: 'MS Gothic'; | ||
} | ||
.one_page { | ||
height: var(--a0-height); | ||
color: black; | ||
} | ||
.inner-page { | ||
margin: 35mm; | ||
} | ||
.kind { | ||
font-size: 3em; | ||
border: 1.5mm solid; | ||
padding: 7mm 10mm; | ||
} | ||
.winner { | ||
font-size: 2em; | ||
font-weight: bold; | ||
line-height: 1.7; | ||
margin: 3mm 20mm 7mm 30mm; | ||
} | ||
.classroom { | ||
font-size: 3em; | ||
font-weight: bold; | ||
margin: 90mm 45mm; | ||
} | ||
li { | ||
display: inline; | ||
} | ||
</style> | ||
<body> | ||
{% for kind in kinds %} | ||
{% for lottery in kind['lotteries'] %} | ||
<div class="one_page"> | ||
<div class="inner-page"> | ||
<p style="margin-bottom: 30mm"> | ||
<span class="kind"> | ||
{% set kind = '来場者' if kind['kind'] == 'visitor' else '生徒' %} | ||
{{ kind }} | ||
</span> | ||
</p> | ||
<p> | ||
<span class="classroom" style="text-decoration: underline;"> | ||
{{ lottery['classroom'] }} | ||
</span> | ||
</p> | ||
<div class="container"> | ||
<ul> | ||
{% for winner in lottery['winners'] %} | ||
<li> | ||
<span class="winner">{{winner}}</span> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
{% endfor %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
import os | ||
sys.path.append(os.getcwd()) # noqa: E402 | ||
from cards.id import load_id_json_file | ||
from urllib.request import Request, urlopen | ||
from urllib.error import HTTPError | ||
from pathlib import Path | ||
import json | ||
|
||
|
||
class client(): | ||
def get(self, _url, _json=None, follow_redirects=False, headers=None): | ||
default_headers = {"Content-Type": "application/json"} | ||
if headers: | ||
default_headers.update(headers) | ||
json_data = json.dumps(_json).encode("utf-8") if _json else None | ||
|
||
url = f'http://localhost:8888{_url}' | ||
request = Request(url, data=json_data, | ||
headers=default_headers, method='GET') | ||
try: | ||
response = urlopen(request) | ||
except HTTPError as e: | ||
print('Error: {}'.format(e.read()), file=sys.stderr) | ||
sys.exit(-1) | ||
else: | ||
response_body = response.read().decode("utf-8") | ||
response.close() | ||
return json.loads(response_body) | ||
|
||
def post(self, _url, _json=None, follow_redirects=False, headers=None): | ||
default_headers = {"Content-Type": "application/json"} | ||
if headers: | ||
default_headers.update(headers) | ||
json_data = json.dumps(_json).encode("utf-8") if _json else None | ||
url = f'http://localhost:8888{_url}' | ||
request = Request(url, data=json_data, | ||
headers=default_headers, method='POST') | ||
|
||
try: | ||
response = urlopen(request) | ||
except HTTPError as e: | ||
print('Error: {}'.format(e.read()), file=sys.stderr) | ||
sys.exit(-1) | ||
else: | ||
response_body = response.read().decode("utf-8") | ||
response.close() | ||
return json.loads(response_body) | ||
|
||
|
||
def login(client, secret_id, rresp): | ||
return client.post('/auth', _json={ | ||
"id": secret_id, | ||
"g-recaptcha-response": rresp | ||
}, follow_redirects=True) | ||
|
||
|
||
client = client() | ||
|
||
|
||
id_list = load_id_json_file(Path(__file__).parent.parent / | ||
Path('cards/test_users.json')) | ||
users = [i for i in id_list if i['authority'] == 'normal'] | ||
|
||
lotteries = client.get('/lotteries/available') | ||
|
||
for lottery in lotteries: | ||
print(f'applying to {lottery["id"]}: ', end='') | ||
for user in users: | ||
token = login(client, user['secret_id'], '')['token'] | ||
client.post(f'/lotteries/{lottery["id"]}', _json={"group_members": ""}, | ||
headers={"Authorization": f"Bearer {token}"}) | ||
print('.', end='') | ||
print(' DONE') | ||
|
||
print('all lotteries are treated') |
Oops, something went wrong.