Skip to content

Commit 15f064a

Browse files
Merge pull request #20 from CreatCodeBuild/dev
Dev
2 parents 8a2b6b1 + 60d4ef6 commit 15f064a

File tree

16 files changed

+603
-32
lines changed

16 files changed

+603
-32
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# common
22
.idea/
33
*.pyc
4-
example/
4+
/example/*
5+
/example/game/game_record.json
56
.cache/
67
__pycache__/
78

89
# package
910
build/
1011
dist/
1112
*.egg-info
13+
!/example/game

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Super Fast HTTP2 Framework for Progressive Web Application
22

33
# Installation
4-
Clone this project to your local directory. In this directory,
5-
```
6-
python setup.py
7-
```
8-
This will automatically install `hyper2web` to the associated Python as a site-package.
4+
At this point, the best way to install it is probably download the zip and extract it to your projects' directory.
5+
6+
I have not figured out how to make it installable with `pip` yet.
97

108
I will make it available on PyPi once I have the first release.
119

@@ -56,6 +54,9 @@ from hyper2web import app
5654
app.App(port=5000).up()
5755
```
5856

57+
# Example
58+
See the example folders for examples.
59+
5960
# Test
6061
Python modules/packages and imports are confusing. You have to do
6162
```python

example/game/app.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
3+
from curio import aopen
4+
5+
from hyper2web import app
6+
from game import update_record, game_record, game_record_path
7+
8+
9+
app = app.App()
10+
# should raise an error if no response method is called
11+
# should raise an error if response method is not called with await
12+
async def post_record(http, stream, para):
13+
record = json.loads(str(stream.data, encoding='utf8'))
14+
update_record(record, game_record)
15+
await http.send_error(stream, 200)
16+
17+
# write records to disk
18+
async with aopen(game_record_path, mode='w') as f:
19+
game_record_string = json.dumps(game_record, indent='\t')
20+
await f.write(game_record_string)
21+
22+
app.post('/post_record', post_record)
23+
24+
25+
async def get_top10(http, stream, para):
26+
level_top10 = game_record.get(para['levelIndex'], [])
27+
string = json.dumps(level_top10)
28+
await http.send_and_end(stream, bytes(string, encoding='utf8'))
29+
app.get('/get_top10/{levelIndex}', get_top10)
30+
31+
app.up()

example/game/game.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
3+
4+
def update_record(this_record, old_records):
5+
timeUsed = this_record['timeUsed']
6+
7+
levelIndex = str(this_record['level'])
8+
level_top10 = old_records.get(levelIndex, [])
9+
10+
i = 0
11+
while i < 10 and i < len(level_top10):
12+
if timeUsed < level_top10[i]['timeUsed']:
13+
level_top10.insert(i, this_record)
14+
break
15+
i += 1
16+
else:
17+
level_top10.insert(i, this_record)
18+
if len(level_top10) > 10:
19+
level_top10.pop()
20+
21+
old_records[levelIndex] = level_top10
22+
23+
24+
game_record_path = 'game_record.json'
25+
26+
try:
27+
with open(game_record_path, encoding='utf8') as f:
28+
game_record = json.load(f, encoding='utf8')
29+
except json.decoder.JSONDecodeError and FileNotFoundError:
30+
print('init a new record')
31+
game_record = {}

example/game/localhost.crt.pem

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDhTCCAm2gAwIBAgIJAOrxh0dOYJLdMA0GCSqGSIb3DQEBCwUAMFkxCzAJBgNV
3+
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
4+
aWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xNTA5MTkxNDE2
5+
NDRaFw0xNTEwMTkxNDE2NDRaMFkxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21l
6+
LVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNV
7+
BAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMqt
8+
A1iu8EN00FU0eBcBGlLVmNEgV7Jkbukra+kwS8j/U2y50QPGJc/FiIVDfuBqk5dL
9+
ACTNc6A/FQcXvWmOc5ixmC3QKKasMpuofqKz0V9C6irZdYXZ9rcsW0gHQIr989yd
10+
R+N1VbIlEVW/T9FJL3B2UD9GVIkUELzm47CSOWZvAxQUlsx8CUNuUCWqyZJoqTFN
11+
j0LeJDOWGCsug1Pkj0Q1x+jMVL6l6Zf6vMkLNOMsOsWsxUk+0L3tl/OzcTgUOCsw
12+
UzY59RIi6Rudrp0oaU8NuHr91yiSqPbKFlX10M9KwEEdnIpcxhND3dacrDycj3ux
13+
eWlqKync2vOFUkhwiaMCAwEAAaNQME4wHQYDVR0OBBYEFA0PN+PGoofZ+QIys2Jy
14+
1Zz94vBOMB8GA1UdIwQYMBaAFA0PN+PGoofZ+QIys2Jy1Zz94vBOMAwGA1UdEwQF
15+
MAMBAf8wDQYJKoZIhvcNAQELBQADggEBAEplethBoPpcP3EbR5Rz6snDDIcbtAJu
16+
Ngd0YZppGT+P0DYnPJva4vRG3bb84ZMSuppz5j67qD6DdWte8UXhK8BzWiHzwmQE
17+
QmbKyzzTMKQgTNFntpx5cgsSvTtrHpNYoMHzHOmyAOboNeM0DWiRXsYLkWTitLTN
18+
qbOpstwPubExbT9lPjLclntShT/lCupt+zsbnrR9YiqlYFY/fDzfAybZhrD5GMBY
19+
XdMPItwAc/sWvH31yztarjkLmld76AGCcO5r8cSR/cX98SicyfjOBbSco8GkjYNY
20+
582gTPkKGYpStuN7GNT5tZmxvMq935HRa2XZvlAIe8ufp8EHVoYiF3c=
21+
-----END CERTIFICATE-----

example/game/localhost.key

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpAIBAAKCAQEAyq0DWK7wQ3TQVTR4FwEaUtWY0SBXsmRu6Str6TBLyP9TbLnR
3+
A8Ylz8WIhUN+4GqTl0sAJM1zoD8VBxe9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