示例#1
0
def run():
    global s, b, db_connection

    db_connection = db.connect_db()
    try:
        with db_connection.cursor() as cursor:
            # get lastest block num
            sql = 'SELECT block_num FROM task_log ORDER BY block_num DESC limit 1'
            cursor.execute(sql)
            lastest_block_num = int(cursor.fetchone()['block_num'])
            # get unfinished tasks
            sql = '''
                SELECT block_num
                FROM task_log
                WHERE
                    block_num < (%s-500) and
                    status = 0
                ;
            '''
            cursor.execute(sql % lastest_block_num)
            unfinished_tasks = cursor.fetchall()
            if unfinished_tasks == ():
                print('None unfinished tasks')
            else:
                block_num_list = []
                for task in unfinished_tasks:
                    block_num_list.append(task['block_num'])
                # do work
                worker(block_num_list)
    except:
        print('error:', sys.exc_info())
    finally:
        db_connection.close()
示例#2
0
def run():
    db_connection = db.connect_db()
    t1 = int(time.mktime(time.strptime("2020-05-04T00:00:00", "%Y-%m-%dT%H:%M:%S")))
    t2 = int(time.mktime(time.strptime("2020-05-05T00:00:00", "%Y-%m-%dT%H:%M:%S")))
    t3 = int(time.mktime(time.strptime("2020-05-06T00:00:00", "%Y-%m-%dT%H:%M:%S")))
    t4 = int(time.mktime(time.strptime("2020-05-07T00:00:00", "%Y-%m-%dT%H:%M:%S")))
    t5 = int(time.mktime(time.strptime("2020-05-08T00:00:00", "%Y-%m-%dT%H:%M:%S")))
    t6 = int(time.mktime(time.strptime("2020-05-09T00:00:00", "%Y-%m-%dT%H:%M:%S")))
    with db_connection.cursor() as cursor:
        sql = db.create_account_from_op_sql
        # op_type: claim_account
        cursor.execute(sql % (t1, t2, 1, '%'+'\"creator\": \"steem\"'+'%'))
        n1 = cursor.fetchone()['num']
        cursor.execute(sql % (t2, t3, 1, '%'+'\"creator\": \"steem\"'+'%'))
        n2 = cursor.fetchone()['num']
        cursor.execute(sql % (t3, t4, 1, '%'+'\"creator\": \"steem\"'+'%'))
        n3 = cursor.fetchone()['num']
        cursor.execute(sql % (t4, t5, 1, '%'+'\"creator\": \"steem\"'+'%'))
        n4 = cursor.fetchone()['num']
        cursor.execute(sql % (t5, t6, 1, '%'+'\"creator\": \"steem\"'+'%'))
        n5 = cursor.fetchone()['num']

    
    msg = ''':evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree:

5月4日 -- 5月8日 @steem账号申请牌子数量统计:

05.04:%s
05.05:%s
05.06:%s
05.07:%s
05.08:%s

'''

    slack.send(msg % (
        n1,
        n2,
        n3,
        n4,
        n5
        ))
    print('send success')
    db_connection.close()
示例#3
0
#!/usr/bin/env python3
import re
import uuid

#from flask import Flask, request, jsonify, render_template
from flask import Flask, request, render_template

from lib.db import connect_db
from lib.calc import OPERATORS, calculate


## Global constants
# Flask app
APP = Flask(__name__)

DATABASE = connect_db()

DESCRIPTION = """
Сомнительный калькулятор® 2.0

В строку ниже вводится операция для подсчета

Формат ввода: NUM1,OPERATOR,NUM2

Поддерживаемые операторы:
{}

Пример строки ввода:
1,+,2

В системе есть ограничение на хранение результатов в 100 результатов. Если вы получили ошибку, то почистите базу данных нажатием на соответствующую кнопку ниже
示例#4
0
def run():
    db_connection = db.connect_db()
    analytic_db_connection = dbAnalytic.connect_db()
    today = datetime.date.today()
    timeArray = time.strptime(str(today), "%Y-%m-%d")
    now = int(time.mktime(timeArray))
    start_time = now - 24 * 3600
    start_time_str = datetime.datetime.utcfromtimestamp(start_time).strftime("%Y-%m-%d")
    with db_connection.cursor() as cursor:
        # get steem account
        sql = db.create_account_from_op_sql
        # op_type: claim_account
        cursor.execute(sql % (start_time, now, 1, '%'+'\"creator\": \"steem\"'+'%'))
        claim_num = cursor.fetchone()['num']

        # op_type: create_claimed_account
        cursor.execute(sql % (start_time, now, 2, '%'+'\"creator\": \"steem\"'+'%'))
        claim_account_num = cursor.fetchone()['num']

        # op_type: account_create
        cursor.execute(sql % (start_time, now, 3, '%'+'\"creator\": \"steem\"'+'%'))
        account_create_num = cursor.fetchone()['num']

        # get all accounts
        sql = db.create_account_from_op_sql2
        # op_type: claim_account
        cursor.execute(sql % (start_time, now, 1))
        all_claim_num = cursor.fetchone()['num']

        # op_type: create_claimed_account
        cursor.execute(sql % (start_time, now, 2))
        all_claim_account_num = cursor.fetchone()['num']

        # op_type: account_create
        cursor.execute(sql % (start_time, now, 3))
        all_account_create_num = cursor.fetchone()['num']

        # order accounts
        sql = db.create_account_order_sql
        # op_type: claim_account
        cursor.execute(sql % (start_time, now, 1))
        claim_account_order_list = cursor.fetchall()
    
    number_icons = {
        1: ":one:",
        2: ":two:",
        3: ":three:",
        4: ":four:",
        5: ":five:",
        6: ":six:",
        7: ":seven:",
        8: ":eight:",
        9: ":nine:",
        10: ":keycap_ten:",
    }

    order_list = []
    i = 1
    for o in claim_account_order_list:
        op_detail = json.loads(o['op_data'])
        creator = "@%s" % op_detail[1]['creator']
        order_list.append("%s %s               %s" % (number_icons[i], creator, o['total']))
        i = i + 1

    msg = ''':evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree: :evergreen_tree:
:earth_asia:  Analytics Data for Last 24 Hours:

the `pending claimed accounts` number of @steem created:     %s
the `pending claimed accounts` number of @steem used:        %s
the number of @steem created accounts by spending steem:    %s
the number of `pending claimed accounts` created:           %s
the number of `pending claimed accounts` used:               %s
the number of spending steem to create new account:         %s

:gem: Top 10 in last 24 hours(`pending claimed accounts` created):

%s
'''

    time_tuple = time.strptime(start_time_str, "%Y-%m-%d")
    created_at = datetime.datetime(
        time_tuple.tm_year,
        time_tuple.tm_mon,
        time_tuple.tm_mday,
        time_tuple.tm_hour,
        time_tuple.tm_min,
        time_tuple.tm_sec)
    dbAnalytic.insert_data(analytic_db_connection ,[
        "(%s, %s, '%s')" % (6, claim_num, created_at),
        "(%s, %s, '%s')" % (7, claim_account_num, created_at),
        "(%s, %s, '%s')" % (8, account_create_num, created_at),
        "(%s, %s, '%s')" % (9, all_claim_num, created_at),
        "(%s, %s, '%s')" % (10, all_claim_account_num, created_at),
        "(%s, %s, '%s')" % (11, all_account_create_num, created_at),
    ])

    # send data to faucet analytics api
    api.send('6', claim_num, start_time_str)
    api.send('7', claim_account_num, start_time_str)
    api.send('8', account_create_num, start_time_str)
    api.send('9', all_claim_num, start_time_str)
    api.send('10', all_claim_account_num, start_time_str)
    api.send('11', all_account_create_num, start_time_str)

    # trigger report action
    api.report()

    # send data to slack
    slack.send(msg % (
        claim_num,
        claim_account_num,
        account_create_num,
        all_claim_num,
        all_claim_account_num,
        all_account_create_num,
        "\n".join(order_list)
        ))
    log.output('send slack success')
    # send data to discord
    discord.send(msg % (
        claim_num,
        claim_account_num,
        account_create_num,
        all_claim_num,
        all_claim_account_num,
        all_account_create_num,
        "\n".join(order_list)
        ))
    log.output('send discord success')
    db_connection.close()
    if analytic_db_connection != -1:
        analytic_db_connection.close()