新文件: PriceSystem/ones_Sender.py
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import json
|
||||
import redis
|
||||
import fangjia
|
||||
import config
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
###
|
||||
from datetime import date
|
||||
|
||||
|
||||
class CJsonEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, datetime.datetime):
|
||||
return obj.strftime('%Y-%m-%d')
|
||||
elif isinstance(obj, date):
|
||||
return obj.strftime('%Y-%m-%d')
|
||||
else:
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
QUEUE = "calc_cmd"
|
||||
redisPool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=config.get_redis_db())
|
||||
client = redis.Redis(connection_pool=redisPool)
|
||||
logger = fangjia.get_logger("CalcCmdSender")
|
||||
|
||||
|
||||
def send_cmd(seaweed):
|
||||
json_cmd = json.dumps(seaweed, ensure_ascii=False, cls=CJsonEncoder)
|
||||
client.rpush(QUEUE, json_cmd)
|
||||
logger.info("命令发送成功:" + json_cmd)
|
||||
|
||||
import pytz
|
||||
def get_weekend(tt):
|
||||
|
||||
from dateutil.parser import parse
|
||||
bb=parse(tt)
|
||||
pacific = pytz.timezone('Asia/Shanghai')
|
||||
return pacific.localize(bb)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
weekend = ""
|
||||
send_cmd({"city": "西安", "region": "未央", "name": "金仕华城", "weekend": get_weekend('20170318')})
|
||||
#sys.exit(0)
|
||||
Reference in New Issue
Block a user