111da4aade
新文件: feature/region_feature.py
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
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())
|
|
redisPool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=2)
|
|
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)
|
|
|
|
def get_district():
|
|
seaweeds = []
|
|
keys = {"city": 1, "region": 1, "name": 1, "_id": 0}
|
|
for dis in fangjia.get_collection("fangjia", "seaweed").find({ "cat": "district", "status": 0,'city':'上海'}, keys):
|
|
#for dis in fangjia.get_collection("fangjia", "seaweed").find({ "cat": "district", "status": 0}, keys):
|
|
seaweeds.append(dis)
|
|
return seaweeds
|
|
|
|
|
|
weekend = get_weekend('20180422')
|
|
#send_cmd({"city": "西安", "region": "雁塔", "name": "鸿景花园", "weekend": get_weekend('20180325')})
|
|
if __name__ == "__main__":
|
|
for seaweed in get_district():
|
|
|
|
|
|
send_cmd({"city":seaweed['city'],"region":seaweed['region'],"name":seaweed['name'],'weekend':weekend})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|