losetear 最近的时间轴更新
losetear

losetear

V2EX 第 115860 号会员,加入于 2015-05-08 12:59:32 +08:00
losetear 最近回复了
2017-05-05 10:26:31 +08:00
回复了 SaulLawliet 创建的主题 分享创造 查询饿了么品牌馆中有哪些是 <真·五折>
简单改了下,做了个按折扣排序:
#for i in range(5):
url = URL_TEMPLATE % (20)
data = json.loads(requests.get(url).text)
shops = list({})
for restaurant in data:
id = restaurant["id"]
name = restaurant["name"]
for activity in restaurant["activities"]:
if "type" in activity and activity["type"] == 102: # 102 表示满减
tips = activity["tips"]
flag = True
lastzk = 999
for couple in zip(*[iter(re.findall(r'\d+', tips))]*2):
x = float(couple[0])
y = float(couple[1])
zk = (x-y)/x
if lastzk > zk:
lastzk = zk
shop = [id,name.replace(u'\u2219',u''),tips,lastzk]
#print("%d %s %s %s" % (id, name, zk,tips))
#print("%d %s %s %s" % (shop[0], shop[1], shop[2],shop[3]))
shops.append(shop)
shops.sort(key=lambda shop: shop[3])
for shop in shops:
print("%d %s %s %s" % (shop[0], shop[1], shop[2], shop[3]))
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1033 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 21:38 · PVG 05:38 · LAX 13:38 · JFK 16:38
Developed with CodeLauncher
♥ Do have faith in what you're doing.