Esempio n. 1
0
from mypackage.user import User, Administrator, Moderator
from mypackage.currency import Currency, GOLD_NAME, SILVER_NAME
from mypackage.achievment import Achievement
from mypackage.counter import Counter
import time
import MySQLdb

connection = MySQLdb.connect('localhost', 'root', 'root', 'mydb')
user1 = Administrator('Vasia', '*****@*****.**', '12345', user_id=1)
print(user1)
user1.currencies[SILVER_NAME] = Currency(name=SILVER_NAME, amount=0, currency_id=1, user_id=1)
user1.currencies[GOLD_NAME] = Currency(name=GOLD_NAME, amount=0, currency_id=2, user_id=1)
user1.counters = Counter(0, 0, 0, 1, counter_id=1, user_id=1)
user1.give_money(SILVER_NAME, 10000)
user1.take_money(SILVER_NAME, 5000)
user1.login_user('12345')
user1.achievements.append(Achievement('killstreak', 'kill 1000000 squirrels in one round', achievement_id=1, user_id=user1.user_id))
user1.counters.exp += 1000
user1.counters.games += 1
user1.logout_user()
time.sleep(1)
user1.login_user('12345')
user1.logout_user()
user1.save_to_db(connection)
del user1
user1 = User()
user1.load_from_db(connection, 1)
user1.login_user('12345')
user1.logout_user()
print(user1.currencies[SILVER_NAME].amount, user1.currencies[GOLD_NAME].amount)
print('user sessions: %s' % len(user1.sessions))
Esempio n. 2
0
from mypackage.user import User, Administrator, Moderator
from mypackage.currency import Currency, GOLD_NAME, SILVER_NAME
from mypackage.achievment import Achievement
from mypackage.counter import Counter


user1 = User('Vasia', '*****@*****.**', '12345')
print(user1)
user1.currencies[SILVER_NAME] = Currency(SILVER_NAME, 0)
user1.currencies[GOLD_NAME] = Currency(GOLD_NAME, 0)
user1.counters = Counter(0, 0, 0, 1)
user1.give_money(SILVER_NAME, 10000)
user1.take_money(SILVER_NAME, 5000)
user1.login_user('12345')
user1.achievements.append(Achievement('killstreak', 'kill 1000000 squirrels in one round'))
user1.counters.exp += 1000
user1.counters.games += 1
user1.logout_user()
user1.save()
del user1
user1 = User()
user1.load('Vasia.json')
print(user1)
user2 = Moderator('Petia', '*****@*****.**', 'password1')
user3 = Administrator('Kolia', '*****@*****.**', 'password2')
user2.ban_user(user1)
user3.delete_user(user1)