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 post_ad_version_handler(params): csv_key = params.get('csv_key', '') if not csv_key: return {"success": False, "error_msg": "no csv_key"} ad_versions = params.get('ad_versions', []) cfg.logger.debug('to update ad_versions: csv_key: %s ad_versions: %s', csv_key, ad_versions) util.db_update('bee_csv', {'csv_key': csv_key}, {'ad_versions': ad_versions, "is_processed_ad_version": True}) db_result = util.db_find_one('bee_csv', {"csv_key": csv_key}, {"_id": False, "town": True, "count": True, "deliver_time": True, "deliver_date": True, "save_time": True, "geo": True, "county": True, "address": True, "user_name": True, "is_processed_ad_version": True, "is_processed_address": True, "csv_key": True, "ad_versions": True, "version_text": True, "memo": True, "deliver_status": True}) the_id = str(db_result.get('save_time', 0)) + "_" + util.uuid() db_result['the_id'] = the_id if db_result.get('is_processed_ad_version', False) and db_result.get('is_processed_address', False): util.db_update('bee', {'csv_key': csv_key}, db_result)
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 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)