添加按companyid返回广告列表的方法

This commit is contained in:
pengtao 2019-07-11 11:35:03 +08:00
parent 22bfc069df
commit 98be9cc6c4
3 changed files with 71 additions and 1 deletions

View File

@ -68,9 +68,9 @@ class Ad(Resource):
log.info(f"sql={sel_sql},data={data}")
if data:
all = []
ad_info = {}
try:
for line in data:
ad_info = {}
ad_info['id'], ad_info['name'], ad_info['begin_time'], ad_info['end_time'], ad_info['ad_num'], \
ad_info['ad_title'], ad_info['ad_body'], ad_info['ad_image'], ad_info['ad_url'], ad_info[
'ad_sort'], ad_info['status'], ad_info['companyid'], ad_info['locationid'], ad_info[

46
oss_api.py Normal file
View File

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# pip install -U cos-python-sdk-v5
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import sys
import logging
from flask import Flask, jsonify
from flask_restful import reqparse, abort, Api, Resource
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
parser = reqparse.RequestParser()
parser.add_argument('id')
parser.add_argument('gameid')
parser.add_argument('area')
parser.add_argument('type')
parser.add_argument('in_used')
class Cos_sdk(Resource):
def __init__(self):
secret_id = 'COS_SECRETID' # 替换为用户的 secretId
secret_key = 'COS_SECRETKEY' # 替换为用户的 secretKey
region = 'ap-beijing' # 替换为用户的 Region
token = None # 使用临时密钥需要传入 Token默认为空可不填
scheme = 'https' # 指定使用 http/https 协议来访问 COS默认为 https可不填
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
# 2. 获取客户端对象
self.client = CosS3Client(config)
self.args = parser.parse_args()
self.bucket = " client-1256832210"
self.base_dirs = "/ad"
self.url="https://test.kingsome.cn"
def post(self):
filename = self.args['filename']
cos_filename = f"{self.base_dirs}/{filename}"
body = self.args['body']
url = ""
response = self.client.put_object(Bucket=self.bucket, Body=body, Key=cos_filename, StorageClass='STANDARD',
EnableMD5=False)
return jsonify({'code': 200, 'message': f'files {filename} uploads ,url={url},response={response}'})

24
up_oss.py Normal file
View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
# pip install flask-restful
from flask import Flask, jsonify
from flask_restful import reqparse, abort, Api, Resource
from log.mylog import define_logger
import logging
from handler.company import Company
from handler.location import Location
from handler.ad import Ad
define_logger("/data/logs/promotion.log")
log = logging.getLogger(__name__)
app = Flask(__name__)
api = Api(app)
# 设置路由
api.add_resource(Company, '/company')
api.add_resource(Location, '/location')
api.add_resource(Ad, '/ad')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=8888)