Ejemplo n.º 1
0
 def __load_data(self):
     logging.info('load data begin')
     self.coupon = Coupon(datadir=self.datadir,
                          feature_list=self.feature_list,
                          top_n=self.top_n)
     self.coupon.load_myqsl(
         self.mysql_engine,
         self.coupon_cust_access,
         self.coupon_cust_order,
         is_read_coupon_result=self.is_read_coupon_result)
     self.item = Item(datadir=self.datadir, top_n=self.top_n)
     self.item.load_mysql(
         self.mysql_engine,
         self.cpns_brand,
         self.cpns_cat,
         is_read_brand_cat_result=self.is_read_brand_cat_result)
     self.user = User(datadir=self.datadir,
                      coupon_brand_count=self.coupon_brand_count,
                      coupon_cat_count=self.coupon_cat_count)
     self.user.load_mysql(self.mysql_engine, self.member_seibel,
                          self.siebel_id_brand_id_q5,
                          self.siebel_id_subclass_id_q5)
     # self.user.load_tsv(self.member_filename, self.custer_txndeail_filename01, self.custer_txndeail_filename02)
     if self.is_read_coupon_info_feature is '0':
         cpns_id = ccs.GetCpnsid()
         Info = ccs.GetEventInfo()
         KeyWord = ccs.GetKeyWord()
         bi_num = ccs.InfoMatchKeyword(Info, KeyWord)
         dataset = ccs.ComputeSimilarity(bi_num)
         ccs.InsertInfoToPymysql(dataset, cpns_id)
  def generate_coupon(self, rule: Type[CouponRule]) -> Coupon:
    if len(self.coupon_codes) >= self.__max_coupons:
      raise Exception(f"[CouponGenerator] Generated the max possible # of coupons for length {self.code_length} codes")

    while True:
      new_code = self.__get_code()
      if not new_code in self.coupon_codes:
        self.coupon_codes.add(new_code)
        break

    coupon = Coupon(rule, new_code)
    return coupon
Ejemplo n.º 3
0
 def create_coupon(self, code, max_uses):
     if not db.session.query(exists().where(Coupon.code == code)).scalar():
         coupon = Coupon(code, max_uses)
         self.coupons.append(coupon)
         db.session.add(coupon)
         db.session.commit()
Ejemplo n.º 4
0
from coupon import Coupon
from store import *

import urllib
from bs4 import BeautifulSoup

c = Coupon()

c.get_coupons()
print c.all_coupons()

e = Extra()

print e.call_me()
Ejemplo n.º 5
0
 def getCouponByNumber(self, number):
     for item in self.coupons:
         if item.getCode() == number:
             return item
         # Return a null coupon if none of this account's coupons don't match the one passed in.
         return Coupon(-1, "Null Coupon", datetime.datetime(2000, 1, 1), datetime.datetime.now(), Item(-1, "Null Item"), -1)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
specialSauce = Customization("Special Sauce", .25)
cream = Customization("Cream", .25)
sugar = Customization("Sugar", .00)

burgerCustomization = [specialSauce]
coffeeCustomization = [cream, cream, sugar]

cheeseburgerWithSauce = CustomizedItem(number=1,
                                       name="Cheeseburger",
                                       size="(one size only)",
                                       price=5.00,
                                       customizations=burgerCustomization)
mediumFrenchFries = CustomizedItem(2, "French Fries", "medium", 2.75, [])
smallVanillaShake = CustomizedItem(3, "Vanilla Milkshake", "small", 3.25, [])
coffeeWithTwoCreamOneSugar = CustomizedItem(4, "Coffee", "medium", 2.50,
                                            coffeeCustomization)

vanillaShakeCoupon = Coupon(100, "Memorial Day Milkshake",
                            datetime.datetime(2019, 5, 25),
                            datetime.datetime(2019, 6, 1),
                            Item(3, "Vanilla Milkshake"), 1.00)

travis = Account(200, "Travis", "Wichtendahl", "*****@*****.**",
                 [vanillaShakeCoupon])

myOrder = Order(travis, [
    cheeseburgerWithSauce, mediumFrenchFries, smallVanillaShake,
    coffeeWithTwoCreamOneSugar
])
myOrder.processOrder()