mirror of
https://github.com/autistic-symposium/blockchain-data-engineering-toolkit.git
synced 2025-05-18 06:30:36 -04:00
first commit
This commit is contained in:
commit
bb17a2a56e
29 changed files with 1238 additions and 0 deletions
52
token-scanner-api/src/server/database.py
Normal file
52
token-scanner-api/src/server/database.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
import motor.motor_asyncio
|
||||
import json
|
||||
MONGO_DETAILS = "mongodb://localhost:27017"
|
||||
|
||||
#client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_DETAILS)
|
||||
|
||||
from pymongo import MongoClient
|
||||
|
||||
client = MongoClient(MONGO_DETAILS)
|
||||
|
||||
database = client.balances
|
||||
|
||||
collection = database.get_collection("balances_fuckkk")
|
||||
|
||||
|
||||
print(database.list_collection_names())
|
||||
|
||||
|
||||
def wallet_helper(item) -> dict:
|
||||
return {
|
||||
"wallet": item["wallet"],
|
||||
}
|
||||
|
||||
|
||||
from bson.objectid import ObjectId
|
||||
|
||||
async def retrieve_students():
|
||||
bals = collection.find()
|
||||
|
||||
res = []
|
||||
counter = 0
|
||||
for i in bals:
|
||||
res.append(wallet_helper(i))
|
||||
if counter > 2:
|
||||
break
|
||||
counter += 1
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def balancer_helper(item) -> dict:
|
||||
return {
|
||||
"wallet": item["wallet"],
|
||||
"balance": item["balance"],
|
||||
}
|
||||
|
||||
|
||||
# Retrieve a student with a matching ID
|
||||
async def retrieve_student(wallet: str) -> dict:
|
||||
student = collection.find_one({"wallet": wallet})
|
||||
if student:
|
||||
return balancer_helper(student)
|
Loading…
Add table
Add a link
Reference in a new issue