V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  losetear  ›  全部回复第 1 页 / 共 1 页
回复总数  1
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   ·   实用小工具   ·   1949 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 9ms · UTC 00:44 · PVG 08:44 · LAX 16:44 · JFK 19:44
Developed with CodeLauncher
♥ Do have faith in what you're doing.