35 lines
808 B
Python
35 lines
808 B
Python
import pymongo
|
|
import random
|
|
|
|
from accounts import *
|
|
|
|
client = pymongo.MongoClient("mongodb://192.168.86.221:27017/")
|
|
db = client.VE
|
|
|
|
def get_balance(code):
|
|
coll = db.economy
|
|
user = coll.find_one({"account_id": code})
|
|
|
|
if user is None:
|
|
did_create = create_econ_account(code)
|
|
if did_create is False:
|
|
print("Something went wrong...")
|
|
return
|
|
|
|
user = coll.find_one({"account_id": code})
|
|
return user['balance']
|
|
|
|
return user['balance']
|
|
|
|
def create_econ_account(code):
|
|
coll = db.economy
|
|
user = coll.find_one({"account_id": code})
|
|
|
|
if user is not None:
|
|
print("User already has an account")
|
|
return False
|
|
|
|
coll.insert_one({"_id": random.randint(000000, 999999), "account_id": code, "balance": 0})
|
|
|
|
return True
|