Skip to content

Commit

Permalink
Merge pull request #17 from ueckoken/flat-layout
Browse files Browse the repository at this point in the history
flat layout
  • Loading branch information
otariidae authored Aug 21, 2023
2 parents c437d3e + 22c1a63 commit 7292a1c
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 184 deletions.
6 changes: 0 additions & 6 deletions Register.sh

This file was deleted.

3 changes: 0 additions & 3 deletions Reset.py

This file was deleted.

6 changes: 0 additions & 6 deletions Unregister.sh

This file was deleted.

Empty file added km4k2/__init__.py
Empty file.
47 changes: 47 additions & 0 deletions km4k2/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
from datetime import timedelta

import redis
from RPi import GPIO

import km4k2.rb303 as servo
from km4k2.card_sdk import CardSDK
from km4k2.km4k import start_system
from km4k2.redis_cache_aside_card_verifier import RedisCacheAsideCardVerifier


def main():
isopen = False
okled_pin = 19
ngled_pin = 26
# 有効期間1週間
cache_expires_delta = timedelta(weeks=1)

# Redisに接続
conn = redis.StrictRedis(
host=os.environ["REDIS_HOST"],
port=os.environ["REDIS_PORT"],
db=os.environ["REDIS_DB"],
)
api_verifier = CardSDK("https://card.ueckoken.club", os.environ["API_KEY"])
redis_cached_api_verifier = RedisCacheAsideCardVerifier(
api_verifier,
conn,
cache_expires_delta,
)

servo.reset()
GPIO.setmode(GPIO.BCM)
GPIO.setup(okled_pin, GPIO.OUT)
GPIO.setup(ngled_pin, GPIO.OUT)

try:
print("Welcome to Koken Kagi System")
start_system(isopen, okled_pin, ngled_pin, redis_cached_api_verifier)
except Exception as e: # noqa: BLE001
print("An error has occured!")
print(e)


if __name__ == "__main__":
main()
File renamed without changes.
12 changes: 6 additions & 6 deletions card_verifier_interface.py → km4k2/card_verifier_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing_extensions import Protocol


class CardVerifierInterface(Protocol):
def verify(self, idm: str) -> bool:
...
from typing_extensions import Protocol


class CardVerifierInterface(Protocol):
def verify(self, idm: str) -> bool:
...
49 changes: 2 additions & 47 deletions KM4K.py → km4k2/km4k.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#!/usr/bin/python3

import binascii
import os
import sys
import time
from datetime import timedelta

import nfc
import redis
from RPi import GPIO

import rb303 as servo
from card_sdk import CardSDK
from card_verifier_interface import CardVerifierInterface
from redis_cache_aside_card_verifier import RedisCacheAsideCardVerifier
import km4k2.rb303 as servo
from km4k2.card_verifier_interface import CardVerifierInterface

suica = nfc.clf.RemoteTarget("212F")
suica.sensf_req = bytearray.fromhex("0000030000")
Expand Down Expand Up @@ -65,40 +57,3 @@ def start_system(isopen, okled_pin, ngled_pin, verifier: CardVerifierInterface):
time.sleep(0.1)
GPIO.output(ngled_pin, GPIO.LOW)
time.sleep(1.7)


def main(_):
isopen = False
okled_pin = 19
ngled_pin = 26
# 有効期間1週間
cache_expires_delta = timedelta(weeks=1)

# Redisに接続
conn = redis.StrictRedis(
host=os.environ["REDIS_HOST"],
port=os.environ["REDIS_PORT"],
db=os.environ["REDIS_DB"],
)
api_verifier = CardSDK("https://card.ueckoken.club", os.environ["API_KEY"])
redis_cached_api_verifier = RedisCacheAsideCardVerifier(
api_verifier,
conn,
cache_expires_delta,
)

servo.reset()
GPIO.setmode(GPIO.BCM)
GPIO.setup(okled_pin, GPIO.OUT)
GPIO.setup(ngled_pin, GPIO.OUT)

try:
print("Welcome to Koken Kagi System")
start_system(isopen, okled_pin, ngled_pin, redis_cached_api_verifier)
except Exception as e: # noqa: BLE001
print("An error has occured!")
print(e)


if __name__ == "__main__":
main(sys.argv)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from redis import Redis

from card_verifier_interface import CardVerifierInterface
from km4k2.card_verifier_interface import CardVerifierInterface


class RedisCacheAsideCardVerifier:
Expand Down
4 changes: 4 additions & 0 deletions km4k2/reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from km4k2.rb303 import lock

if __name__ == "__main__":
lock()
112 changes: 0 additions & 112 deletions test_KM4K.py

This file was deleted.

Empty file added tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion test_card_sdk.py → tests/test_card_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import requests_mock

from card_sdk import CardSDK
from km4k2.card_sdk import CardSDK


class TestCardSDK(TestCase):
Expand Down
Loading

0 comments on commit 7292a1c

Please sign in to comment.