Closes WikiDeck/wikideck#9
This commit is contained in:
parent
20931ba41f
commit
2b467ce248
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ mine_data/*
|
||||
mariadb_data/*
|
||||
*.pem
|
||||
*__pycache__*
|
||||
*.swp
|
||||
|
||||
6
cli.py
6
cli.py
@ -263,8 +263,10 @@ def opt_view_deck():
|
||||
msg_array[0] = "You have no cards to view";
|
||||
return;
|
||||
|
||||
for i, card in enumerate(cards):
|
||||
print(f"{i+1}. Card ID: {card['cardId']}, Page ID: {card['pageId']}");
|
||||
msg = ""
|
||||
for card in cards:
|
||||
msg += f"Card ID: {card['cardId']}, Page ID: {card['pageId']}\n"
|
||||
msg_array[0] = msg
|
||||
|
||||
except Exception as e:
|
||||
msg_array[0] = f"Error fetching cards: {str(e)}";
|
||||
|
||||
@ -243,28 +243,23 @@ class Database():
|
||||
|
||||
def get_blocks(self):
|
||||
cur = self.conn.cursor()
|
||||
cur.execute(self.SQL_GET_LAST_BLOCK)
|
||||
cur.execute(self.SQL_GET_BLOCKS)
|
||||
blocks = cur.fetchall()
|
||||
if blocks:
|
||||
blockCard = self.get_card_by_block_id(blocks[0])
|
||||
blockTransactions = self.get_transactions_by_block_id(blocks[0])
|
||||
return [
|
||||
Block(
|
||||
blockId = uuid.UUID(block[0]),
|
||||
previousHash = block[1],
|
||||
timestamp = datetime.datetime.strptime(
|
||||
block[2],
|
||||
"%Y-%m-%d %H:%M:%S.%f%z"
|
||||
),
|
||||
height = block[3],
|
||||
difficulty = block[4],
|
||||
nonce = block[5],
|
||||
card = blockCard,
|
||||
transactions = blockTransactions
|
||||
)
|
||||
]
|
||||
else:
|
||||
return None
|
||||
return [
|
||||
Block(
|
||||
blockId = uuid.UUID(block[0]),
|
||||
previousHash = block[1],
|
||||
timestamp = datetime.datetime.strptime(
|
||||
block[2],
|
||||
"%Y-%m-%d %H:%M:%S.%f%z"
|
||||
),
|
||||
height = block[3],
|
||||
difficulty = block[4],
|
||||
nonce = block[5],
|
||||
card = self.get_card_by_block_id(block[0]),
|
||||
transactions = self.get_transactions_by_block_id(block[0])
|
||||
) for block in blocks
|
||||
] if blocks else []
|
||||
|
||||
def get_last_block(self):
|
||||
cur = self.conn.cursor()
|
||||
|
||||
@ -50,7 +50,8 @@ def generate_origin_block():
|
||||
@mine.get('/')
|
||||
def index_get():
|
||||
try:
|
||||
return flask.jsonify([each.as_dict() for each in db.get_blocks()])
|
||||
blocks = db.get_blocks()
|
||||
return flask.jsonify([block.as_dict() for block in blocks]) if blocks else flask.jsonify({})
|
||||
except Exception as e:
|
||||
return flask.jsonify(
|
||||
{'Error': str(e)}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user