def bulk_collect(): if request.method != 'POST': topics = Topic.select() return render_template('admin/bulk_collect.html', topics=topics) else: urls = request.form['urls'] topic_id = request.form['topic_id'] reason = request.form['reason'] cookie = request.form['cookie'] rate = float(request.form['rate']) manualAudit = request.form['manualAudit'] if manualAudit == '0': manualAudit = 0 else: manualAudit = None item_index = request.form['item_index'] try: total = len(urls.split()) url = urls.split()[int(item_index)] next_index = int(item_index) + 1 if next_index >= total: next_index = 0 d = Data(url) c = Coupon(cookie, reason, d.item_id, rate, manualAudit) cam_rate = c.get_rate() print(cam_rate) if cam_rate == None: return jsonify(message="不符合要求,跳过", title=d.title, item_index=item_index, total=total, next_index=next_index) d.commissionRate = cam_rate d.getinfo() d.topic_id = int(topic_id) d.status = 1 d.setdesc() is_saved = d.save_to() if not is_saved: return jsonify(message="宝贝重复", title=d.title, item_index=item_index, total=total, next_index=next_index, rate=d.commissionRate) try: if c.Campaign != None: c.apply_for_promotion_plan() except: d.commissionRate = -1 return jsonify(message="采集成功", title=d.title, item_index=item_index, total=total, next_index=next_index, rate=d.commissionRate) except Exception as ex: print(traceback.print_exc()) return jsonify(message="采集失败 :" + str(ex), item_index=item_index, total=total, next_index=next_index)
def auto_collect(): if request.method != 'POST': topics = Topic.select() return render_template('admin/auto_collect.html', topics=topics) else: channel = request.form['channel'] topic_id = request.form['topic_id'] reason = request.form['reason'] cookie = request.form['cookie'] rate = float(request.form['rate']) manualAudit = request.form['manualAudit'] if manualAudit == '0': manualAudit = 0 else: manualAudit = None item_index = request.form['item_index'] try: c = get_all_coupon(channel=channel) total = len(c) next_index = int(item_index) + 1 if next_index >= total: next_index = 0 url = c[(0 - int(item_index))]['item']['shareUrl'] d = Data('http:' + url) c = Coupon(cookie, reason, d.item_id, rate, manualAudit) cam = c.get_rate() if cam == None: return jsonify(message="不符合要求,跳过", title=d.title, item_index=item_index, total=total, next_index=next_index) d.commissionRate = cam d.getinfo() d.topic_id = int(topic_id) d.status = 1 d.setdesc() is_saved = d.save_to() if not is_saved: return jsonify(message="宝贝重复", title=d.title, item_index=item_index, total=total, next_index=next_index, rate=d.commissionRate) if c.Campaign != None: try: c.apply_for_promotion_plan() except: print(traceback.print_exc()) d.commissionRate = -1 d.save_to() return jsonify(message="采集成功", title=d.title, item_index=item_index, total=total, next_index=next_index, rate=d.commissionRate) except Exception as ex: print(traceback.print_exc()) return jsonify(message="采集失败 :" + str(ex), item_index=item_index, total=total, next_index=next_index)