Exemple #1
0
def export_report():
    request_json = request.json

    report_token = request_json['report_token']
    position_token = request_json['position_token'] # report owner
    results_data = json.dumps(request_json['results_data'])

    r = Report.query.filter(Report.key == report_token and Report.position_token == position_token).first()
    timestamp = str(datetime.datetime.utcnow())

    if r is None:
        r = Report(report_token, position_token, results_data, timestamp)
        db_session.add(r)
    else:
        r.results = results_data
        r.timestamp = timestamp

    db_session.commit()

    res = dict()

    res['timestamp'] = timestamp
    res['message'] = 'success'

    return jsonify(res)
def test_data_insert():
    yyyymm = '201903'
    timestamp = str(datetime.datetime.utcnow())
    for i in range(1,10):
        db_session.add(TradePrice(yyyymm, i, timestamp))

    db_session.commit()
Exemple #3
0
def main_job():
    print("volatilities working...")

    data = {'test': 10}

    category = 'test_category'
    yyyymmdd = '20190830'
    contents = json.dumps(data)

    timestamp = str(datetime.datetime.utcnow())

    p = Volatilities_D.query.filter(
        Volatilities_D.category == category
        and Volatilities_D.yyyymmdd == yyyymmdd).first()

    if p is None:
        p = Volatilities_D(category, yyyymmdd, contents, timestamp)
        db_session.add(p)
        print("volatilities added...")
    else:
        p.category = category
        p.yyyymmdd = yyyymmdd
        p.contents = contents
        p.timestamp = timestamp
        print("volatilities updated...")

    db_session.commit()
Exemple #4
0
def index_test():
    # resp = make_response(render_template('index.html'))
    # resp.set_cookie('userID', 'testID')

    # ------------------------------------------------------------------------
    # Get 인 경우에
    # if cookie 가 없으면 redirect -> login.html
    # cookie 가 있으면 index.html 로 가는데 거기서 js 에서 쿠키로 user정보가져옴
    if request.method == 'GET':
        login_hash = request.cookies.get('login_hash')
        if login_hash is None:
            return redirect(url_for('login'))

        user = UserLogin.query.filter(UserLogin.login_hash == login_hash).first()

        if user is None:
            return redirect(url_for('login'))

        # naver에 서 받아와봄
        userinfo = utilities.get_userinfo(user)

        if userinfo is None:
            return redirect(url_for('login'))

        return render_template('index.html')

    # Post 인 경우에는
    # token이 날라올거기 때문에
    # 내부에 ip, token, hash 를 저장하고 hash를 쿠키에 담아서 날려줌
    # cookie 가 있으므로 index.html로 거기서 js 에서 쿠키로 user정보가져옴
    elif request.method == 'POST':
        access_token = request.json['token']
        ip = request.remote_addr
        login_hash = utilities.get_hash(access_token, ip)

        user = UserLogin.query.filter(UserLogin.access_token == access_token).first()
        timestamp = str(datetime.datetime.utcnow())
        provider = 'naver'

        if user is None:
            user = UserLogin(login_hash, access_token, provider, timestamp)
            db_session.add(user)
        else:
            user.access_token = access_token
            user.login_hash = login_hash
            user.provider = provider
            user.timestamp = timestamp

        db_session.commit()
    else:
        return redirect(url_for('login'))

    return render_template('index.html')
Exemple #5
0
def store_positions():
    #position_token = request.cookies.get('position_token')

    # post
    request_json = request.json

    print(request_json)

    email = request_json['email']
    position_token = request_json['position_token']
    position_list = request_json['position_list']
    results_data = json.dumps(request_json['results_data'])

    #key = utilities.gen_key(email, position_list)
    #p = Position(key, email, positions)

    timestamp = str(datetime.datetime.utcnow())

    p = Position.query.filter(Position.key == position_token).first()

    if p is None:
        p = Position(position_token, email, json.dumps(position_list), timestamp)
        p.results = results_data
        db_session.add(p)
    else:
        p.positions = json.dumps(position_list)
        p.results = results_data
        p.key = position_token
        p.timestamp = timestamp


    db_session.commit()

    res = dict()
    # res['access_key'] = key

    res['timestamp'] = timestamp
    res['message'] = 'success'

    # email 보냄

    return jsonify(res)
Exemple #6
0
def analysis():
    # post
    request_json = request.json

    position_token = request_json['position_token']
    position_items = request_json['position_list']

    if len(position_items) == 0:
        abort(400, 'position_list is empty')

    res = position_analysis(position_items)
    res['results_data']['timestamp'] = str(datetime.datetime.utcnow())

    p = Position.query.filter(Position.key == position_token).first()

    if p is not None:
        p.results = json.dumps(res['results_data'])
        db_session.commit()

    return jsonify(res)
def test_data_delete():
    yyyymm = '201903'
    TradePrice.query.filter(TradePrice.yyyymm == yyyymm).delete()

    db_session.commit()
def Message():
    while True:

        dataReceive = request.get_json()
        content = dataReceive[u'content']

        if content == u"도움말":
            dataSend = {
                "message": {
                    "text":
                    u"바코드를 사용하여 PPUCHA 서비스를 이용하세요. 바코드를 발급받으신 후, 임신증명사실 절차를 걸쳐야 서비스 이용이 가능해집니다. 자세한 문의는 [email protected] 으로 보내주세요"
                },
                "keyboard": {
                    "type": "buttons",
                    "buttons": [u"등록하기", u"도움말"]
                }
            }

        elif content == u"처음으로":
            dataSend = {
                "message": {
                    "text": u"처음으로 돌아갑니다."
                },
                "keyboard": {
                    "type": "buttons",
                    "buttons": [u"등록하기", u"도움말"]
                }
            }

        elif content == u"완료":
            dataSend = {
                "message": {
                    "text": u"반드시 임신증명사실 절차를 거치세요!"
                },
                "keyboard": {
                    "type": "buttons",
                    "buttons": [u"처음으로"]
                }
            }

        elif content == u"동의합니다":
            dataSend = {
                "message": {
                    "text":
                    u"이름,생년월일,행운의숫자(0~9 중 한 개)를 입력해주세요! 예) 이재근:941125:9 "
                }
            }

        elif content == u"등록하기":
            dataSend = {
                "message": {
                    "text":
                    u"등록을 하기 위해서는 개인정보 이용 동의가 필요합니다. 사용될 개인 정보는 이름, 생년월일 및 임신 사실 여부입니다."
                },
                "keyboard": {
                    "type": "buttons",
                    "buttons": [u"동의합니다", u"처음으로"]
                }
            }

        elif u":" in content:

            info = content.split(':')

            name = info[0]
            birthday = info[1]
            lucky = info[2]

            new_user = Barcode(name, birthday, lucky)

            new_id = new_user.coding(name, birthday, lucky)

            init_db()
            u = User(new_id, name, birthday, lucky)

            db_session.add(u)
            db_session.commit()

            dataSend = {
                "message": {
                    "text":
                    u"귀하의 바코드 입니다! 바코드는 임신 사실 증명 이후 효력을 가집니다. 증빙자료를 [email protected] 으로 보내주세요. 확인은 최대 하루 정도 걸립니다.",
                    "photo": {
                        "url":
                        "https://www.barcodesinc.com/generator/image.php?code="
                        + str(new_id) +
                        "&style=197&type=C128B&width=206&height=50&xres=1&font=3",
                        "width":
                        206,
                        "height":
                        50
                    }
                },
                "keyboard": {
                    "type": "buttons",
                    "buttons": [u"완료", u"도움말"]
                }
            }
            #"photo": {
            #"url": "http://api-bwipjs.rhcloud.com/?bcid=ean13&text="+str(new_id),
            #"width" : 190, "height":144 } } }

        else:
            dataSend = {
                "message": {
                    "text": u"힝...무슨말인지 모르겠어요... '도움말', '등록하기'를 이용해주세요!"
                },
                "keyboard": {
                    "type": "buttons",
                    "buttons": [u"등록하기", u"도움말"]
                }
            }

        return jsonify(dataSend)