Пример #1
0
    def find_steals(self):
        shop_urls = [self._mens_shoes, self._mens_cloths]
        found_steals = []

        for products_url in shop_urls:
            page = 0

            while page<1000:
                print(products_url)
                raw_html = requests.get(products_url).content
                # raw_html = requests.get(products_url+str(page)).content
                # soup_html = BeautifulSoup(raw_html, "html.parser")
                print(raw_html)

                for product_tag in soup_html.find_all('div', {"class": "gl-product-card glass-product-card___1PGiI"}):
                    print(soup_html)
                    if product_tag.find('span', {"class": "gl-price__value gl-price__value--crossed"}):
                        title = product_tag.find('div', {"class": "gl-product-card__name gl-label gl-label--m"}).text
                        old_price = product_tag.find('div', {"class": "gl-price__value gl-price__value--crossed"}).text
                        new_price = product_tag.find('div', {"class": "gl-price__value gl-price__value--sale"}).text
                        url = product_tag.find('a', href=True).attrs['href']
                        url_image = product_tag.find('img', src=True).attrs['src']

                        offer = Offer(title, url, url_image, new_price, old_price)
                        offer.print_offer()
                        found_steals.append(offer)

                page += 48
        return found_steals
Пример #2
0
    def __init__(self, a, b):
        Offer.__init__(self, 'partnership request')

        # FICS informs player A if player B is ratedbanned, but
        # that arguably leaks information unnecessarily

        # block offers from guests if the recipient does not allow tells
        # from guests, to reduce spam
        if a.is_guest and not b.vars_['tell']:
            a.write(_('''Player "%s" isn't listening to unregistered users' tells.\n''' % b.name))
            return
        # check for existing offers
        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        o = next((o for o in b_sent if o.name == self.name and
            o.b == a), None)
        if o:
            # offers intercept
            o.accept()
            return
        o = next((o for o in a_sent if o.name == self.name and
            o.b == b), None)
        if o:
            a.write(_("You are already offering to be %s's partner.\n") %
                b.name)
            return

        self.a = a
        self.b = b
        a.write(_('Making a partnership offer to %s.\n') % b.name)
        b.write_('\n%s offers to be your bughouse partner; type "partner %s" to accept.\n', (a.name, a.name))
        self._register()
        self.pendinfo('partner', '#')
Пример #3
0
    def accept(self):
        Offer.accept(self)
        self.a.write_("\n%s agrees to be your partner.\n", (self.b.name,))
        self.b.write(_("You agree to be %s's partner.\n") % (self.a.name,))

        # end any existing partnerships
        if self.a.session.partner:
            self.a.session.partner.write_("\nYour partner has accepted a partnership with %s.", (self.b,))
            end_partnership(self.a, self.a.session.partner)
        if self.b.session.partner:
            self.b.session.partner.write_("\nYour partner has accepted a partnership with %s.", (self.a,))
            end_partnership(self.b, self.b.session.partner)

        self.a.session.partner = self.b
        self.b.session.partner = self.a
        global_.partners.append(set([self.a, self.b]))

        # end any pending partnership offers
        for offer in self.a.session.offers_sent[:]:
            if offer.name == 'partnership request':
                offer.b.write_('\n%(aname)s, who was offering a partnership with you, has accepted a partnership with %(bname)s.\n', {'aname': self.a.name, 'bname': self.b.name})
                offer.withdraw(notify=False)
        for offer in self.b.session.offers_sent[:]:
            if offer.name == 'partnership request':
                offer.b.write_('\n%(aname)s, who was offering a partnership with you, has accepted a partnership with %(bname)s.\n', {'aname': self.b.name, 'bname': self.a.name})
                offer.withdraw(notify=False)
        for offer in self.a.session.offers_received[:]:
            if offer.name == 'partnership request':
                offer.a.write_('\n%(aname)s, whom you were offering a partnership with, has accepted a partnership with %(bname)s.\n', {'aname': self.a.name, 'bname': self.b.name})
                offer.withdraw(notify=False)
        for offer in self.b.session.offers_received[:]:
            if offer.name == 'partnership request':
                offer.a.write_('\n%(aname)s, whom you were offering a partnership with, has accepted a partnership with %(bname)s.\n', {'aname': self.b.name, 'bname': self.a.name})
                offer.withdraw(notify=False)
Пример #4
0
    def find_steals(self):
        shop_urls = [self._mens_shoes, self._mens_cloths]
        found_steals = []

        for products_url in shop_urls:
            products_json = json.loads(requests.get(products_url).content)
            page = 1

            while products_json['foundProductResults']:
                for property in products_json['sections']:
                    for item in property['items']:
                        if item['inWallContentCard']:
                            continue

                        if item['numberOfColors'] > 1:
                            for color in item['colorways']:
                                if color['overriddenLocalPrice']:
                                    title = str(item['title'])
                                    title = title.replace("'", "")
                                    title = title.replace(" ", "_")
                                    old_price = int(
                                        str(color['localPrice']).split()[0])
                                    new_price = int(
                                        str(color['overriddenLocalPrice']).
                                        split()[0])
                                    url = str(color['pdpUrl'])
                                    url_image = str(color['imageUrl'])
                                    item_color = str(color['colorDescription'])
                                    offer = Offer(title, url, url_image,
                                                  new_price, old_price,
                                                  item_color)
                                    found_steals.append(offer)
                                    # offer.print_offer()
                        elif color['overriddenLocalPrice']:
                            title = str(item['title'])
                            title = title.replace("'", "")
                            title = title.replace(" ", "_")
                            old_price = int(
                                str(color['localPrice']).split()[0])

                            new_price = int(
                                str(color['overriddenLocalPrice']).split()[0])
                            url = str(item['pdpUrl'])
                            url_image = str(item['spriteSheet'])
                            offer = Offer(title, url, url_image, new_price,
                                          old_price, item_color)
                            found_steals.append(offer)
                            # offer.print_offer()

                products_json = json.loads(
                    requests.get(products_url + "=" + str(page)).content)
                page += 1

        # for i in found_steals:
        #     print(i.print_offer())
        return found_steals
Пример #5
0
 def decline(self, notify=True):
     Offer.decline(self, notify)
     if self.variant_name == 'bughouse':
         assert (self.a.session.partner)
         assert (self.b.session.partner)
         self.a.session.partner.write_(
             '\n%s declines the match offer from your partner.\n',
             (self.b.name, ))
         self.b.session.partner.write_(
             '\nYour partner declines the match offer from %s.\n',
             (self.a.name, ))
Пример #6
0
 def decline_logout(self):
     Offer.decline_logout(self)
     self.b.write(_('Challenge from %s removed.\n') % (self.a.name, ))
     self.a.write_(
         '\n%s, whom you were challenging, has departed.\nChallenge to %s withdrawn.',
         (self.b.name, self.b.name))
     if self.variant_name == 'bughouse':
         assert (self.a.session.partner)
         self.a.session.partner.write_(
             '\n%s, whom your partner was challenging, has departed.\n',
             (self.b.name, ))
Пример #7
0
 def withdraw_open(self):
     """ Withdraw this offer due to the sender no longer being open. """
     Offer.withdraw(self, notify=False)
     self.a.write_('Challenge to %s withdrawn.\n', (self.b.name, ))
     self.b.write_(
         '\n%s, who was challenging you, has become unavailable for matches.\n',
         (self.a.name, ))
     self.b.write_('Challenge from %s removed.\n', (self.a.name, ))
     if self.variant_name == 'bughouse':
         self.b.session.partner.write_(
             '\n%s, who was challenging your partner, has become unavailable for matches.\n',
             (self.a.name, ))
Пример #8
0
 def decline_open(self):
     """ Decline this offer due to the receiver no longer being open. """
     Offer.decline(self, notify=False)
     self.b.write(_('Challenge from %s removed.\n') % (self.a.name, ))
     self.a.write_(
         '\n%s, whom you were challenging, has become unavailable for matches.\nChallenge to %s withdrawn.',
         (self.b.name, self.b.name))
     if self.variant_name == 'bughouse':
         assert (self.a.session.partner)
         self.a.session.partner.write_(
             '\n%s, whom your partner was challenging, has become unavailable for matches.\n',
             (self.b.name, ))
Пример #9
0
def edit_offer(id):
    offer - Offer.find(id)
    if request.method == "GET":
        return render_template("edit_offer.html",
                               User=User.get_user(id),
                               offers=Offer.find(id_ad))
    elif request.method == "POST":
        offer.title = request.form['title'],
        offer.description = request.form['description'],
        offer.price = request.form['price'],
        offer.date = request.form['date']
        offer.save()

        return redirect('/{}/'.format(id))
Пример #10
0
    def accept(self):
        Offer.accept(self)

        g = game.PlayedGame(self)
        if self.variant_name == 'bughouse':
            chal2 = copy.copy(self)
            chal2.a = self.a.session.partner
            chal2.b = self.b.session.partner
            chal2.side = g.get_user_side(self.b)
            g2 = game.PlayedGame(chal2)
            g2.bug_link = g
            g.bug_link = g2
            g2.variant.pos.bug_link = g.variant.pos
            g.variant.pos.bug_link = g2.variant.pos
Пример #11
0
def offers1(id):
    if request.method == 'POST':
        return redirect(url_for('index'))

    return render_template('offers.html',
                           User=User.get_user(id),
                           offers=Offer.all())
Пример #12
0
def getOffers(url):
    offers = []
    response = simple_get(url)
    if response.statusCode != 200:
        return response.onError()
    html = BeautifulSoup(response.content, 'html.parser')

    items = html.select('.ad-listitem')
    for item in items:
        details = item.select('.aditem-details')
        main = item.select('.aditem-main')
        if details.__len__() == 0:
            continue
        price_label = details[0].select('strong')
        if len(price_label) == 0 or len(price_label[0].contents) == 0:
            continue

        price = price_label[0].contents[0]
        vb = True if "VB" in price else False

        price = u' '.join(price).encode('utf-8').replace(' ', '').replace(
            '€', '').replace('VB', '').replace('.', '')
        title = main[0].select('h2')[0].select('a')[0].contents[0]
        url = main[0].select('h2')[0].find('a', href=True)
        url = url['href']
        description = main[0].select('p')[0].contents[0]
        #keywords = ['tausche', 'Tausch']
        #if any(re.findall('|'.join(keywords), description)) or any(re.findall('|'.join(keywords), title)):
        if price:
            offers.append(Offer(title, price, description, vb, url))
    return offers
Пример #13
0
 def place_order(self, user, iid, mid, side, price, quantity):
     result = []
     ctype = self.contract_type.lookup(iid, mid)
     messages = Offer(user, ctype, side, price, quantity).place()
     for message in messages:
         if message.account == user.id:
             result.append(message)
     return result
Пример #14
0
def scrap_linux_milan():
    # retrieve links to all recent offers in Milan + 30km related to 'linux'
    r = requests.get(
        "https://it.jobrapido.com/?&w=linux&l=milano&r=45&sortby=publish_date&shm=all"
    )
    soup = BeautifulSoup(r.content, 'html.parser')
    for a in soup.findAll('a', attrs={'class': 'advert-link'}):
        link = a['href']
        Offer('Shitty JobRapido Title', link).save_to_file()
Пример #15
0
def scrap_linux_bologna():
    # retrieve links to all recent offers in Bologna + 30km related to 'linux'
    r = requests.get(
        "https://www.helplavoro.it/ricerca/linux/in-provincia-di-bologna.html")
    soup = BeautifulSoup(r.content, 'html.parser')
    for a in soup.findAll('a', attrs={'class': 'posizione link-offerta'}):
        description = a['title'][18::].title()
        link = 'https://www.helplavoro.it' + a['href']
        Offer(description, link).save_to_file()
Пример #16
0
def new_offer(id):
    if request.method == 'GET':
        return render_template('new_offer.html', User=User.get_user(id))
    elif request.method == "POST":
        values = (None, request.form['title'], request.form['description'],
                  request.form['price'], id)
        Offer(*values).create()

        return redirect('/offers/{}/'.format(id))
Пример #17
0
def scrap_linux_bologna():
    # retrieve links to all recent offers in Bologna + 30km related to 'linux'
    r = requests.get(
        "https://it.indeed.com/offerte-lavoro?q=linux&l=Bologna%2C+Emilia-Romagna&sort=date"
    )
    soup = BeautifulSoup(r.content, 'html.parser')
    for a in soup.select('a[onmousedown*="rclk(this,jobmap"]'):
        description = str(a.contents)[4:-2:]
        link = "https://www.indeed.com" + a['href']
        Offer(description, link).save_to_file()
    def _parse_offers(self, raw=False):
        r = requests.get(self.url)
        soup = BeautifulSoup(r.content, "html.parser")
        tables = soup.find_all("table", class_="bs_kurse")
        raw_offers_list = []
        for table in tables:
            raw_offers_list.extend(table.find("tbody").find_all("tr"))

        offers_list = [Offer(offer) for offer in raw_offers_list]
        return offers_list
Пример #19
0
def new_offer():
    if request.method == 'GET':
        return render_template('new_offer.html')
    elif request.method == 'POST':
        # user = User.find(request.form['email'])
        values = (None, user, request.form['title'],
                  request.form['description'],
                  request.form['price'],
                  request.form['date'])
        Offer(*values).create()
        return redirect(url_for('logged'))
Пример #20
0
    def __init__(self):
        self.server_port = 0
        self.server_ip = NETWORK_ADDR
        self.server_socket = None
        self.selector = selectors.DefaultSelector()

        self.udp_broadcast_socket = socket.socket(socket.AF_INET,
                                                  socket.SOCK_DGRAM)
        self.udp_broadcast_socket.setsockopt(socket.SOL_SOCKET,
                                             socket.SO_BROADCAST, 1)
        self.broadcast_thread = None
        self.run_broadcast = True
        self.broadcast_iterations = 0

        self.init_server_socket()
        self.offer = Offer(self.server_port)

        self.on_game = False
        self.init_groups_data()
        self.game_data = GameData()
Пример #21
0
def scrap_linux_bologna():
    # retrieve links to all recent offers in Bologna + 30km related to 'linux'
    r = requests.get(
        "https://www.monster.it/lavoro/cerca/?q=linux&where=Bologna__2C-Emilia-Romagna&client=classic&cy=it&rad=30&intcid=swoop_Hero_Search"
    )
    soup = BeautifulSoup(r.content, 'html.parser')
    for a in soup.findAll('div', attrs={'class': 'summary'}):
        name = (a.find('a', href=True))
        description = str(name.contents)[2:-6:].title()
        link = name['href']
        Offer(description, link).save_to_file()
Пример #22
0
    def make_offer(self, player_maker, resources_from, resources_to):

        #offers are created as {RESOURCE: number_of_cards, .....}

        offer_id = str(uuid.uuid4())
        for r, n in resources_from.items():
            if player_maker.resources[r] < n:
                return False, "You do not have enough resources to create this trade!"
        self.offers[offer_id] = Offer(player_maker, resources_from,
                                      resources_to)
        return True, ''
Пример #23
0
    def submitLoanOffer(self, investor, interest):

        print('submitLoanOffer ... in progress ...')

        validation = self.__isValidOffer(investor, interest)
        if validation['isValid']:
            offer = Offer(investor, interest, self)
            investor.offers.append(offer)
            self.offers.append(offer)
            return print('Thanks your offer is successfully submitted! \n')
        else:
            return print(validation['validationErr'])
Пример #24
0
    def accept(self):
        Offer.accept(self)

        g = game.PlayedGame(self)
        yield g.finish_init(self)
        if self.variant_name == 'bughouse':
            # this should probably be in another module
            chal2 = copy.copy(self)
            chal2.a = self.a.session.partner
            chal2.b = self.b.session.partner
            chal2.b.write_("\nYour partner accepts the challenge of %s.\n",
                           (self.a.name, ))
            chal2.a.write_("\n%s accepts your partner's challenge.\n",
                           (self.b.name))

            chal2.side = g.get_user_side(self.b)
            g2 = game.PlayedGame(chal2)
            yield g2.finish_init(chal2)
            g2.bug_link = g
            g.bug_link = g2
            g2.variant.pos.bug_link = g.variant.pos
            g.variant.pos.bug_link = g2.variant.pos
            g.minmovetime = (g.white.vars_['minmovetime']
                             or g.black.vars_['minmovetime']
                             or g2.white.vars_['minmovetime']
                             or g2.black.vars_['minmovetime'])
            g2.minmovetime = g.minmovetime
            # start clocks immediately for bug
            g.clock.start(WHITE)
            g2.clock.start(WHITE)
            g.send_boards()
            g2.send_boards()
            for p in [g.get_side_user(WHITE), g2.get_side_user(WHITE)]:
                if p.has_timeseal():
                    p.session.ping(for_move=True)
            all_players = set([g.white, g.black, g2.white, g2.black])
            # each player's "say" goes to all the other players except
            # themselves
            for p in all_players:
                p.session.say_to = all_players - set([p])
Пример #25
0
def upload():
    if not current_user.is_authenticated:
        return redirect(url_for('index'))

    form = UploadForm()
    if form.validate_on_submit():
        f = form.ffield.data
        filename = secure_filename(f.filename)

        offerManager.removeFile(filename)

        f.save(os.path.join(app.instance_path, '_user_files', filename))

        ending = filename[-3:]

        print("ending: %s" % (ending))

        if ending == "jpg" or ending == "png":
            filetype = "image"
        elif ending == "mp4" or ending == "flv":
            filetype = "video"
        elif ending == "txt" or ending == "doc" or ending == "pdf":
            filetype = "text"
        else:
            filetype = "music"

        offer = Offer(form.price.data, filename, filetype, current_user.id,
                      True)

        offerManager.offers.append(offer)
        offerManager.writeToFile()

        readable_hash = ""
        with open(os.path.join(app.instance_path, '_user_files', filename),
                  "rb") as f:
            bytes = f.read()  # read entire file as bytes
            readable_hash = hashlib.sha256(bytes).hexdigest()

        if url != "undefined":
            requests.post("%s/file/registerFile" % (url),
                          data={
                              "filename": filename,
                              "owner": current_user.email,
                              "type": "filetype",
                              "price": form.price.data,
                              "available": "1",
                              "hash": readable_hash
                          })

        return redirect(url_for('success'))
    else:
        return "nope, no good data"
Пример #26
0
    def __init__(self, a, b):
        Offer.__init__(self, 'partnership request')

        # check for existing offers
        a_sent = a.session.offers_sent
        b_sent = b.session.offers_sent
        o = next((o for o in b_sent if o.name == self.name and o.b == a), None)
        if o:
            # offers intercept
            o.accept()
            return
        o = next((o for o in a_sent if o.name == self.name and o.b == b), None)
        if o:
            a.write(
                _("You are already offering to be %s's partner.\n") % b.name)
            return

        self.a = a
        self.b = b
        a.write(_('Making a partnership offer to %s.\n') % b.name)
        b.write_('%s offers to be your bughouse partner.\n', (a.name, ))
        self._register()
Пример #27
0
def create_offer(offer):
    id = offer['offerId']
    link = 'https://www.travelplanet.pl' + offer['offerUrl']
    country = offer['country']
    region = offer['region']
    hotel_name = offer['hotelName']
    trip_departure_name = offer['tripDepartureName']
    trip_duration = offer['tripDurationText']
    trip_dates = offer['tripDatesText']
    tour_operator = offer['touroperatorName']
    price_one_person = offer['priceOnePerson']

    return Offer(id, link, country, region, hotel_name, trip_departure_name, trip_duration, trip_dates, tour_operator,
                 price_one_person)
Пример #28
0
    def __init__(self, documentPath, buysPath):
        self.documentPath = documentPath
        self.buysPath = buysPath
        self.offers = []
        self.buys = {}

        if not os.path.isfile(self.documentPath):
            with open(self.documentPath, "w+") as fo:
                fo.write('{"offers":[]}')

        if not os.path.isfile(self.buysPath):
            f = open(self.buysPath, "w+")
            f.write('{}')
            f.close()

        dataFile = open(self.documentPath, "r")
        data = dataFile.read()
        dataFile.close()

        offers = json.loads(data)
        for offerObj in offers["offers"]:
            if 'price' in offerObj.keys() and 'filename' in offerObj.keys(
            ) and 'type' in offerObj.keys() and 'offererId' in offerObj.keys(
            ) and 'available' in offerObj.keys():
                offer = Offer(offerObj['price'], offerObj['filename'],
                              offerObj['type'], offerObj['offererId'],
                              offerObj['available'])

                self.offers.append(offer)

        buysFile = open(self.buysPath, "r")
        data = buysFile.read()
        buysFile.close()

        buysData = json.loads(data)
        for buyerId in buysData:
            bId = int(buyerId)
            self.buys[bId] = []
            buysList = buysData[buyerId]

            for singleBuy in buysList:
                self.buys[bId].append(singleBuy)

        print("registered offersmanager at %s with %s stored offers" %
              (self.documentPath, str(len(self.offers))))
Пример #29
0
    def find_steals(self):

        self._db_connection_cursor.execute("SELECT * FROM offers")
        raw_db_steals = self._db_connection_cursor.fetchall()
        db_steals = []

        for db_steal in raw_db_steals:
            db_steal = (db_steal[:3] + db_steal[3 + 1:])
            db_steal = Offer(db_steal[0], db_steal[1], db_steal[2],
                             db_steal[3], db_steal[4], db_steal[5])
            # print(db_steal.print_offer())
            db_steals.append(db_steal)

        nikeScrapper = NikeScrapper()
        # adidasScrapper = AdidasScrapper()
        shop_steals = nikeScrapper.find_steals()
        # shop_steals = adidasScrapper.find_steals()

        exists = 0
        self._new_steals = []
        for new_steal in shop_steals:
            for db_steal in db_steals:
                if new_steal._title == db_steal._title and new_steal._color == db_steal._color:
                    exists = 1
            if not exists:
                self._new_steals.append(new_steal)
                self._db_connection_cursor.execute(
                    new_steal.get_insert_offer_query())
                db_steals.append(new_steal)
            exists = 0
        self._db_connection.commit()

        exists = 0
        self._removed_steals = []
        for db_steal in db_steals:
            for new_steal in shop_steals:
                if new_steal._title == db_steal._title and new_steal._color == db_steal._color:
                    exists = 1
            if not exists:
                self._removed_steals.append(db_steal)
                self._db_connection_cursor.execute(
                    "DELETE FROM offers WHERE title=? AND color=?",
                    (db_steal._title, db_steal._color))
            exists = 0
        self._db_connection.commit()
Пример #30
0
    def executeTradeStrategy(self, currentManager):
        teams_ranking_last_season = sorted(
            self.model.managers,
            key=lambda manager: manager.game_history[-34:].count(1),
            reverse=True)
        own_ranking_place = teams_ranking_last_season.index(currentManager)
        n_traitors_recruiting = 0
        lower_boundary_wins = 0.4
        middle_boundary_wins = 0.7
        proportion_won_last_season = currentManager.game_history[-34:].count(
            1) / 34
        if proportion_won_last_season < lower_boundary_wins:
            n_traitors_recruiting = 5
        if lower_boundary_wins <= proportion_won_last_season <= middle_boundary_wins:
            n_traitors_recruiting = 3
        budget_for_replacing_player = currentManager.assets / n_traitors_recruiting if n_traitors_recruiting != 0 else 0

        candidates_recruitment = []
        for better_team in teams_ranking_last_season[:own_ranking_place - 1]:
            for pos, player in better_team.team.items():
                if player != None:
                    if player.stats[
                            'Release Clause'] <= budget_for_replacing_player:
                        candidates_recruitment.append(player)

        narrowed_down_candidate_list = []
        if len(candidates_recruitment) >= n_traitors_recruiting:
            for i in range(n_traitors_recruiting):
                candidate = random.choice(candidates_recruitment)
                narrowed_down_candidate_list.append(candidate)
                candidates_recruitment.remove(candidate)

        elif len(candidates_recruitment) < n_traitors_recruiting:
            if len(candidates_recruitment) != 0:
                for i in range(len(candidates_recruitment)):
                    candidate = random.choice(candidates_recruitment)
                    narrowed_down_candidate_list.append(candidate)
                    candidates_recruitment.remove(candidate)

        for final_candidate in narrowed_down_candidate_list:
            Offer(currentManager, final_candidate, final_candidate.position)