Example #1
0
def _save_img(data, postfix, content_type):
    the_timestamp = util.get_timestamp()
    the_datetime = util.timestamp_to_datetime(the_timestamp)
    the_id = str(the_timestamp) + "_" + util.uuid()
    filename = the_id + '.' + postfix

    the_dir = '/data/img/bee/' + the_datetime.strftime('%Y-%m-%d')

    util.makedirs(the_dir)

    with open(the_dir + '/' + filename, 'w') as f:
        f.write(data)

    (the_thumbnail, thumbnail_postfix) = _make_thumbnail(data, postfix)
    
    the_dir = '/data/thumbnail/bee/' + the_datetime.strftime('%Y-%m-%d')

    util.makedirs(the_dir)

    thumbnail_filename = the_id + '.' + thumbnail_postfix

    with open(the_dir + '/' + thumbnail_filename, 'w') as f:
        f.write(the_thumbnail)

    db_data = {"filename": the_datetime.strftime('%Y-%m-%d/') + filename, "thumbnail_filename": the_datetime.strftime("%Y-%m-%d/") + thumbnail_filename, "the_id": the_id, 'content_type': content_type, 'save_time': the_timestamp}

    util.db_insert('bee_img', [db_data])

    if '_id' in db_data:
        del db_data['_id']

    return db_data
Example #2
0
def _save_img(data, postfix, content_type):
    the_timestamp = util.get_timestamp()
    the_datetime = util.timestamp_to_datetime(the_timestamp)
    the_id = str(the_timestamp) + "_" + util.uuid()
    filename = the_id + '.' + postfix

    the_dir = '/data/img/bee/' + the_datetime.strftime('%Y-%m-%d')

    util.makedirs(the_dir)

    with open(the_dir + '/' + filename, 'w') as f:
        f.write(data)

    (the_thumbnail, thumbnail_postfix) = _make_thumbnail(data, postfix)
    
    the_dir = '/data/thumbnail/bee/' + the_datetime.strftime('%Y-%m-%d')

    util.makedirs(the_dir)

    thumbnail_filename = the_id + '.' + thumbnail_postfix

    with open(the_dir + '/' + thumbnail_filename, 'w') as f:
        f.write(the_thumbnail)

    db_data = {"filename": the_datetime.strftime('%Y-%m-%d/') + filename, "thumbnail_filename": the_datetime.strftime("%Y-%m-%d/") + thumbnail_filename, "the_id": the_id, 'content_type': content_type, 'save_time': the_timestamp}

    util.db_insert('bee_img', [db_data])

    if '_id' in db_data:
        del db_data['_id']

    return db_data
def p_json_handler(data):
    for each_data in data:
        the_timestamp = util.get_timestamp()
        the_id = str(the_timestamp) + "_" + util.uuid()
        each_data['the_id'] = the_id
        each_data['save_time'] = the_timestamp
        each_data['user_name'] = each_data.get('user_name', '')
        each_data['address'] = each_data.get('address', '')
        each_data['count'] = util._int(each_data['count'])
    util.db_insert('bee', data)

    return {"success": True}
def p_json_handler(data):
    for each_data in data:
        the_timestamp = util.get_timestamp()
        the_id = str(the_timestamp) + "_" + util.uuid()
        each_data['the_id'] = the_id
        each_data['save_time'] = the_timestamp
        each_data['user_name'] = each_data.get('user_name', '')
        each_data['address'] = each_data.get('address', '')
        each_data['count'] = util._int(each_data['count'])
    util.db_insert('bee', data)

    return {"success": True}
Example #5
0
def p_json_handler(data):
    '''
    data: [{deliver_time, deliver_date, ad_versions, geo, count, user_name, address, county, town, deliver_status, memo}]
    deliver_date: time in iso-8601 format (with millisecond precision)
    deliver_time: deliver_date as timestamp (secs after Unix epoch) in int.
    ad_versions: list of ad_versions. the name of ad is based on "name" in /get/adData
    geo: geojson format. accepting LineString and Point
    count: in int number
    user_name: string
    address: string
    county: string, based on app/scripts/services/TWCounties in frontend
    town: string, based on app/scripts/services/TWTown in frontend
    deliver_status: string
    memo: string

    ex: {"town":"東區","count":10,"deliver_time":1398724259,"deliver_date":"2014-04-28T22:30:59.383Z","geo":[{"type":"LineString","coordinates":[[120.99337719999994,24.7905385],[120.99452376365662,24.79139038370729],[120.99501729011536,24.79084493848351]]}],"ad_versions":["鳥籠監督條例"],"county":"新竹市","deliver_status":"test","address":"nthu","user_name":"test_user_name","memo":"test"}

    ex2: {"town":"內湖區","count":3000,"deliver_time":1398164891,"deliver_date":"2014-04-22T11:08:11.835Z","geo":[{"type":"Point","coordinates":[121.61277294158936,25.06670789727661]}],"ad_versions":["20140421_二類電信RE"],"county":"台北市","address":"康寧路三段","user_name":"test_user_name"}
    '''
    for each_data in data:
        for key in _MUST_HAVE_KEYS:
            if key not in each_data:
                return {"success": False, "errorMsg": "no key: key: %s each_data: %s" % (key, util.json_dumps(each_data))}

        the_timestamp = util.get_timestamp()
        the_id = str(the_timestamp) + "_" + util.uuid()
        each_data['the_id'] = the_id

        if 'deliver_time' not in each_data:
            (error_code, deliver_time) = _parse_deliver_time(each_data)
            if error_code != S_OK:
                return {"success": False, "error_msg": "deliver_date not fit format: deliver_date: %s each_data: %s" % (each_data.get('deliver_date', ''), util.json_dumps(each_data))}
            each_data['deliver_time'] = deliver_time

        each_data['save_time'] = the_timestamp
        each_data['user_name'] = each_data.get('user_name', '')
        each_data['address'] = each_data.get('address', '')
        each_data['count'] = util._int(each_data['count'])
    util.db_insert('bee', data)

    return {"success": True}
def _login(client_id, scope, register_uri, authorization_base_url, request,
           params):
    (session_struct, session_struct2) = util_user.process_session(request)
    cfg.logger.debug('session_struct: %s session_struct2: %s', session_struct,
                     session_struct2)

    the_path = params.get('url', '')
    the_timestamp = util.get_timestamp()

    cfg.logger.debug('params: %s the_path: %s', params, the_path)

    the_auth = OAuth2Session(client_id, scope=scope, redirect_uri=register_uri)

    authorization_url, state = the_auth.authorization_url(
        authorization_base_url, approval_prompt="auto")

    util.db_insert(
        'login_info', {
            "state": state,
            "the_timestamp": the_timestamp,
            "params": params,
            "url": the_path
        })

    is_cron_remove_expire = cfg.config.get('is_cron_remove_expire', True)
    if not is_cron_remove_expire:
        expire_timestamp_session = cfg.config.get(
            'expire_unix_timestamp_session',
            EXPIRE_UNIX_TIMESTAMP_SESSION) * 1000
        util.db_remove('login_info', {
            "the_timestamp": {
                "$lt": the_timestamp - expire_timestamp_session
            }
        })

    cfg.logger.debug(
        'after authorization_url: authorization_url: %s state: %s',
        authorization_url, state)

    redirect(authorization_url)
def _login(client_id, scope, register_uri, authorization_base_url, request, params):
    (session_struct, session_struct2) = util_user.process_session(request)
    cfg.logger.debug('session_struct: %s session_struct2: %s', session_struct, session_struct2)

    the_path = params.get('url', '')
    the_timestamp = util.get_timestamp()

    cfg.logger.debug('params: %s the_path: %s', params, the_path)

    the_auth = OAuth2Session(client_id, scope=scope, redirect_uri=register_uri)

    authorization_url, state = the_auth.authorization_url(authorization_base_url, approval_prompt="auto")

    util.db_insert('login_info', {"state": state, "the_timestamp": the_timestamp, "params": params, "url": the_path})

    is_cron_remove_expire = cfg.config.get('is_cron_remove_expire', True)
    if not is_cron_remove_expire:
        expire_timestamp_session = cfg.config.get('expire_unix_timestamp_session', EXPIRE_UNIX_TIMESTAMP_SESSION) * 1000
        util.db_remove('login_info', {"the_timestamp": {"$lt": the_timestamp - expire_timestamp_session}})

    cfg.logger.debug('after authorization_url: authorization_url: %s state: %s', authorization_url, state)

    redirect(authorization_url)
Example #8
0
def p_json_handler(data):
    for each_data in data:
        the_timestamp = each_data.get('save_time', 0)
        the_id = str(the_timestamp) + "_" + util.uuid()
        each_data['the_id'] = the_id
    util.db_insert('bee', data)