Example #1
0
    def _get_all_fund(self):
        db = data.get_db()
        cursor = db.cursor()
        cursor.execute("SELECT i.*, p.last_date FROM share_info i join ( SELECT share_code, MAX(date) as last_date FROM share_price GROUP BY share_code) p ON p.share_code = i.code")
        shares = cursor.fetchall()
        all_shares = []
        index_shares = {}
        for share in shares:

            all_shares.append(
                {
                    "code": share[1],
                    "name": share[2],
                    "managed": share[3],
                    "buy_1": share[4],
                    "buy_2": share[5],
                    "sell": share[6],
                    "pinyin": share[7],
                    "last_date": share[8],
                }
            )
            index_shares[share[7]] = len(all_shares) - 1
            index_shares[share[1]] = len(all_shares) - 1

        all_fund = {"index": index_shares, "data": all_shares}
        cache.set("all_sharess", all_fund)
        logging.debug("Return from DB")
        db.commit()
        db.close()
        return all_fund
Example #2
0
    def get(self, share_q):
        db = data.get_db()
        cursor = db.cursor()
        cursor.execute("SELECT * FROM share_info "
                       "WHERE code LIKE %(share_code)s "
                       "OR name LIKE %(share_name)s OR name_pinyin LIKE %(share_pinyin)s",
                       {"share_name": "%{}%".format(share_q),
                        "share_code": "%{}%".format(share_q),
                        "share_pinyin": "%{}%".format(share_q)})
        results = cursor.fetchall()


        if results is not None:
            shares = []
            for result in results:
                shares.append({
                    "id": result[0],
                    "code": result[1],
                    "name": result[2],
                    "managed": result[3],
                    "buy_1": result[4],
                    "buy_2": result[5],
                    "sell": result[6]
                })
            return_data = {
                "error": False,
                "shares" : shares

            }

        else:
            return_data = {"error": True, "reason": "share not found"}
        db.commit()
        db.close()
        return return_data
Example #3
0
def login(username, passwd):
	sql_db = data.get_db()
	cursor = sql_db.cursor()
	cursor.execute("SELECT passwd FROM account WHERE account_name='%s'"%username)
	passwd_sql = cursor.fetchone()
	# print passwd == passwd_sql[0]
	if passwd_sql and passwd == passwd_sql[0]:
		return True
	else: 
		return False
Example #4
0
def setup_function():
    conn = data.get_db()
    # create mock data
    conn['notes'].insert_one({
        'title': 'The quick brown fox',
        'tags': ['important'],
        'content': 'The quick brown fox'
    })

    conn['notes'].insert_one({
        'title': 'The quick brown fox',
        'tags': ['important', 'test'],
        'content': 'The quick brown fox'
    })
Example #5
0
    def get(self, share_id):
        db = data.get_db()
        cursor = db.cursor()
        cursor.execute("SELECT * FROM share_price WHERE share_code= %(share_id)s", {"share_id": share_id})
        results = cursor.fetchall()
        rtn = []
        for r in results:
            rtn.append({
                "id": r[0],
                "share_code": r[1],
                "date": r[2],
                "price": r[3],
            })
        db.commit()
        db.close()

        return rtn
Example #6
0
def register():
  form = RegistrationForm(request.form)
  conn = data.get_db()

  if (request.method == 'POST'):
    username = form.username.data
    sql = "SELECT username from users WHERE username= '******'"
    if (len(conn.cursor().execute(sql).fetchall()) != 0):

      flash("user doesn't exist try again")
    else:
      email = form.email.data
      password = sha256_crypt.encrypt(str(form.password.data))
      sql = "INSERT INTO users (username, password, email) VALUES ('"+ username +"', '"+ password +"', '"+ email +"')"
      conn.cursor().execute(sql)
      conn.commit()
      flash("Thanks for joining")
      conn.cursor().close()
      conn.close()
    return redirect(url_for('profile'))
  else:
    return render_template('register.html', form = form)
Example #7
0
def register():
    form = RegistrationForm(request.form)
    conn = data.get_db()

    if (request.method == 'POST'):
        username = form.username.data
        sql = "SELECT username from users WHERE username= '******'"
        if (len(conn.cursor().execute(sql).fetchall()) != 0):

            flash("user doesn't exist try again")
        else:
            email = form.email.data
            password = sha256_crypt.encrypt(str(form.password.data))
            sql = "INSERT INTO users (username, password, email) VALUES ('" + username + "', '" + password + "', '" + email + "')"
            conn.cursor().execute(sql)
            conn.commit()
            flash("Thanks for joining")
            conn.cursor().close()
            conn.close()
        return redirect(url_for('profile'))
    else:
        return render_template('register.html', form=form)
Example #8
0
 def __init__(self):
     self.bot = data.get_bot()
     self.db = data.get_db()
     self.eco = economy_handler.EconomyHandler(self.db)
Example #9
0
from discord.ext import commands, tasks
import random
import data
from datetime import datetime, timedelta
import economy_handler

config = data.get_config()
bot = data.get_bot()
db = data.get_db()
eco = economy_handler.EconomyHandler(db)

extensions = [
    "cogs.economy",
    "cogs.moderation",
]


@bot.event
async def on_ready():
    for ext in extensions:
        bot.load_extension(ext)

    bot.owner_id = 279392238319173632

    print('Bot is ready!')


@bot.event
async def on_message(msg):
    if msg.channel.guild is None or msg.author.bot:
        return
Example #10
0
def init_db_connection():
    data.get_db()