Exemple #1
0
    def get_listings(self, shop_id):
        """
        This method allows us to get all of the active listings given
        a shop_id

        @param shop_id: the id of the Etsy shop
        @return: a list of Listings
        """
        url = self.ETSY_API_URL
        url += self.GET_SHOP_LISTINGS.format(shop_id)
        url += self.API_PARAM.format(self.api_key)

        response = requests.get(url)
        try:
            if response.status_code == 403:
                error = "Error: request is not authenticated please"
                error += " enter a valid API key and try again"
                print(error)
                sys.exit(-1)

            elif response.headers["X-RateLimit-Remaining"] == 0:
                error = "Your rate limit is surpassed please try again "
                error += "in a number of hours"
                print(error)
                sys.exit(-1)

            elif response.status_code == 404:
                return [listing.Listing("", "", "ShopId does not exist")]

            elif response.status_code == 200:
                self.print_help(
                    "Shop id {}'s codes were fetched successfully".format(
                        shop_id))

                response_json = response.json()
                listing_list = []

                for listings in response_json["results"]:
                    product_listing = listing.Listing(listings["title"],
                                                      listings["description"],
                                                      shop_id)

                    listing_list.append(product_listing)

                return listing_list

        except JSONDecodeError:
            return [listing.Listing("", "", "ShopId does not exist")]
Exemple #2
0
def main(stdscr):
    branch_data = branch.get_branches()
    branch_names = branch.get_branch_names()
    (height, width) = branch.get_branch_dimensions(branch_data)

    curses.start_color()
    curses.curs_set(0)
    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)

    border_bounds = 2
    branch_layout = (curses.LINES - 1, curses.COLS, 1, 0)
    # 1 for the nav height itself
    nav_layout = (1, 1, curses.LINES, 0)

    prompt_layout = (5, curses.COLS, 0, 0)
    prompt_option = prompt.Prompt(prompt_layout)

    # Layout is (height, width, y_coord, x_coord)
    branch_list = listing.Listing(branch_layout, branch_data, branch_names)
    branch_list.set_prompt(prompt_option)

    stdscr.addstr(0, 0, ' Press enter to delete a local branch')
    stdscr.refresh()

    # Nav
    nav = navigator.Navigator(nav_layout, {
        's': {
            'window': branch_list
        },
        'd': {
            'window': prompt_option
        }
    }, stdscr)
Exemple #3
0
 def run(self):
     print ""
     self.output.info('Starting others module...')
     allow_method.AllowMethod(agent=self.agent,
                              proxy=self.proxy,
                              redirect=self.redirect,
                              timeout=self.timeout,
                              url=self.url,
                              cookie=self.cookie).run()
     xst.XST(agent=self.agent,
             proxy=self.proxy,
             redirect=self.redirect,
             timeout=self.timeout,
             url=self.url,
             cookie=self.cookie).run()
     dav.Dav(agent=self.agent,
             proxy=self.proxy,
             redirect=self.redirect,
             timeout=self.timeout,
             url=self.url,
             cookie=self.cookie).run()
     listing.Listing(agent=self.agent,
                     proxy=self.proxy,
                     redirect=self.redirect,
                     timeout=self.timeout,
                     url=self.url,
                     cookie=self.cookie).run()
     robots.Robots(agent=self.agent,
                   proxy=self.proxy,
                   redirect=self.redirect,
                   timeout=self.timeout,
                   url=self.url,
                   cookie=self.cookie).run()
     phpinfo.Phpinfo(agent=self.agent,
                     proxy=self.proxy,
                     redirect=self.redirect,
                     timeout=self.timeout,
                     url=self.url,
                     cookie=self.cookie).run()
     htmlobject.HtmlObject(agent=self.agent,
                           proxy=self.proxy,
                           redirect=self.redirect,
                           timeout=self.timeout,
                           url=self.url,
                           cookie=self.cookie).run()
	def post(self):
		netid = self.request.get("netid")

		wantsPasses = self.request.get("wantsPasses")
		if wantsPasses == "True":
			wantsPasses = True
		else:
			wantsPasses = False
		club = self.request.get("club")
		details = self.request.get("details")

		nickname = self.request.get("nickname")
		print nickname

		if club != "select":
			newListing = listing.Listing(parent=listing.listing_key())
			newListing.populate(netid=netid, wantsPasses=wantsPasses,
				club=club.lower(), details=details, nickname=nickname)
			newListing.put()
		if wantsPasses:
			self.redirect("/passes?requested=%s" % club)
		else:
			self.redirect("/latemeal?requested=latemeal")
Exemple #5
0
def create_listing_classes(list_of_listings):
    list_of_homes = []
    days = days_between(date_1, date_2)
    for x in list_of_listings:
        #If statement adds San Diego and Oceanside taxes. Applies flat 10% tax.
        if x['listing']['city'] == 'San Diego' or 'Oceanside':
            untaxed_price = int(x['pricing_quote']['price']['total']['amount'])
            real_price = untaxed_price + untaxed_price * .10
        else:
            real_price = x['pricing_quote']['price']['total']['amount']
        fake_rate = x['pricing_quote']['rate']['amount']
        fake_price = int(fake_rate) * int(days)
        nightly_rate = int(real_price / days)
        listing_obj = x['listing']
        if 'neighborhood' in listing_obj:
            neighborhood = listing_obj['neighborhood']
        else:
            neighborhood = listing_obj['city']

        amenities = listing_obj['amenity_ids']
        if 'beds' in listing_obj:
            pass
        else:
            listing_obj['beds'] = 1
        monthly_rate = nightly_rate * 30
        a_listing = listing.Listing(amenities=amenities,
                                    fake_price=fake_price,
                                    price=real_price,
                                    nightly_rate=nightly_rate,
                                    monthly_rate=monthly_rate,
                                    name=listing_obj['name'],
                                    bathrooms=listing_obj['bathrooms'],
                                    beds=listing_obj['beds'],
                                    neighborhood=neighborhood,
                                    listing_id=listing_obj['id'])
        list_of_homes.append(a_listing)
    return list_of_homes
Exemple #6
0
def notify_me(recipient=None,
              search_term=None,
              maxprice=None,
              sortlistings='newest',
              itemcondition='parts',
              buyitnow=True,
              best_offer=False,
              load_results=5):
    recommended: set = load(f'{recipient}.dat')
    html_template = \
        '''
    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>
    <h1 style="text-align: center;"><strong>{0}</strong></h1>
    <pre>URL {1}</pre>
    <pre>Condition: {2}</pre>
    <pre>Price: {3}</pre>
    <pre>Shipping: {4}</pre>
    <pre>Auction: {5}</pre>
    <pre>Best Offer: {6}</pre>
    <pre>Images:</pre>
    {7}
    </body>
    </html>
        '''
    img_template = '<p><img src="{0}" alt="" /></p>\n'

    s = requests.Session()
    # using ebay_url.py to generate a search results page url
    searchresultspage_url = ebay_url.get_searchresults_url(
        s,
        search_term,
        item_condition=itemcondition,
        sort_listings=sortlistings,
        max_price=maxprice)
    source = s.get(searchresultspage_url).text
    #print(source)
    soup = BeautifulSoup(source, 'lxml')
    html_str = soup.prettify()

    # Using regex to search for links to listings, titles, and item condition in the HTML.
    # Split method and stuff is used to separate link, titles, and item condition from other useless things.
    pattern = re.compile(
        r'href=".+">\n\s+<h3\sclass="s-item__title">\s+.+\n\s+</h3>\n\s*.*\n\s*.*\n\s*.*SECONDARY_INFO">\n\s+.+\n'
    )
    listing_results = pattern.findall(html_str)

    #listings_found = 1
    for match in listing_results[:load_results]:
        matched_parts = match.split('\n')
        url = matched_parts[0][6:-2]
        # print(url)
        listing_title = matched_parts[2][13:]
        # print(listing_title)
        item_condition = matched_parts[7][13:]
        # print(item_condition)

        # GOING INTO THE PAGE FOR EACH LISTING, AWAY FROM SEARCH RESULTS PAGE
        if url in recommended:
            print("An email was sent before already!")
            continue  # continue if we already sent a mail about it
        r = s.get(str(url))
        page_html = r.text

        # FOR TESTING PURPOSES ONLY
        # with open('temp1.html', 'a') as f:
        # f.write(page_html)

        # find price on page
        pattern = re.compile(r'>US\s\$\d+\.\d\d')
        matches = pattern.findall(page_html)
        for match in matches:
            item_price = match[4:]
            # print(item_price)

        # Auction?
        auction_ = False
        if "Current bid" in page_html:
            auction_ = True
        elif "Place bid" in page_html:
            auction_ = True

        # Best Offer?
        best_offer = False
        if "Best Offer" in page_html:
            # print('or Best Offer')
            best_offer = True

        # Free Shipping? If no, how much?
        pattern = re.compile(r'fshippingCost.+\n\s+<span>(FREE|\$\d+\.\d+)')
        matches = pattern.findall(page_html)
        # the findall will only find things in the group, so it will only return FREE or $xx.xx.
        shipping_cost = r'$0.00'
        for match in matches:
            if match == 'FREE':
                shipping_cost = r'$0.00'
            else:
                shipping_cost = match

        # Description. Description on ebay listings is another webpage. First we find the link to this webpage:
        pattern = re.compile(r'src=".+"\stitle="S')
        matches = pattern.findall(page_html)
        for match in matches:
            # separate the URL from other useless things in the search result
            match = match.split('" ')
            desc_url = match[0][5:]
            # going to the desc_url and getting the HTML data for the page
            r = s.get(desc_url)
            desc_html = r.text
            # searching for the actual description inside the desc_html. This only works when the description is
            # completely unformatted, so doesn't work often.
            pattern = re.compile(r'ds_div">\n\s+(.+)\s</div>')
            matches = pattern.findall(desc_html)
            for match in matches:
                ##print(match)
                pass

        # Find image URLs.
        # Create a set with URLs.
        # Find the first big image.
        image_str = ""
        pattern = re.compile(r'image"\ssrc="(.+)"\ss')
        matches = pattern.findall(page_html)
        big_image = None
        for match in matches[:-1]:
            match = match.replace('300', '1000')
            big_image = match
            # print(big_image)
            image_str += img_template.format(big_image)
        # Find the small images (thumbanails).
        pattern = re.compile(r'img\ssrc="(.+)"\sstyle')
        matches = pattern.findall(page_html)
        for match in matches:
            full_size_thumbnail_url = match.replace('64', '1000')
            # making sure we don't get the big image and the same thumbnail
            if big_image == full_size_thumbnail_url:
                pass
            else:
                # print(full_size_thumbnail_url)
                image_str += img_template.format(full_size_thumbnail_url)

        # create instance of class Listing, starting with name listing1 for instance and so forth, and print
        # attributes of instance
        # instance_title = 'listing' + str(listings_found)
        instance_title = listing.Listing(listing_title, url, item_condition,
                                         item_price, shipping_cost, best_offer,
                                         auction_)
        print(instance_title.__dict__)

        html = html_template.format(instance_title.Title, instance_title.URL,
                                    instance_title.Condition,
                                    instance_title.Price,
                                    instance_title.Shipping,
                                    instance_title.Auction,
                                    instance_title.Best_Offer, image_str)
        textcontent = f'''
        Link: {instance_title.URL}

        Condition: {instance_title.Condition}
        Price: {instance_title.Price}
        Shipping: {instance_title.Shipping}
        Auction: {instance_title.Auction}
        Best Offer: {instance_title.Best_Offer}'''
        # print(html)
        # print(image_str)

        # Send email based on Best Offer, then auction/buyitnow.
        if best_offer:
            if float(str(instance_title.Price[1:])) + float(
                    str(instance_title.Shipping[1:])) <= maxprice and str(
                        instance_title.Auction
                    ) == "False" and buyitnow:  #buyitnow
                sendemail.send_an_email(
                    subject=f'We found a {instance_title.Title}',
                    recipient=recipient,
                    text_content=textcontent,
                    html_content=html)
                recommended.add(instance_title.URL)  # add to set
                print('Sent an email')
            elif float(str(instance_title.Price[1:])) + float(
                    str(instance_title.Shipping[1:])) <= maxprice and str(
                        instance_title.Auction
                    ) == "True" and not buyitnow:  #auction
                sendemail.send_an_email(
                    subject=f'We found a {instance_title.Title}',
                    recipient=recipient,
                    text_content=textcontent,
                    html_content=html)
                recommended.add(instance_title.URL)  # add to set
        elif not best_offer:
            if float(str(instance_title.Price[1:])) + float(
                    str(instance_title.Shipping[1:])) <= maxprice and str(
                        instance_title.Auction
                    ) == "False" and buyitnow:  #buy it now
                sendemail.send_an_email(
                    subject=f'We found a {instance_title.Title}',
                    recipient=recipient,
                    text_content=textcontent,
                    html_content=html)
                recommended.add(instance_title.URL)  # add to set
                print('Sent an email')
            elif float(str(instance_title.Price[1:])) + float(
                    str(instance_title.Shipping[1:])) <= maxprice and str(
                        instance_title.Auction
                    ) == "True" and not buyitnow:  #auction
                sendemail.send_an_email(
                    subject=f'We found a {instance_title.Title}',
                    recipient=recipient,
                    text_content=textcontent,
                    html_content=html)
                recommended.add(instance_title.URL)  # add to set
                print('Sent an email')

        save(f'{recipient}.dat', recommended)  # saving the set to file
        print('\n')
Exemple #7
0
import listing
import random
import string

for i in range(50000):
    title_size = random.randrange(10, 180)
    title = ''.join(random.choice(string.ascii_uppercase + "        ") for x in range(title_size))

    description_size = random.randrange(50, 250)
    description = ''.join(random.choice(string.ascii_uppercase + "        ") for x in range(description_size))

    price = random.lognormvariate(4, .5)

    list = listing.Listing(1+i, title, description, price)
    print list.toJson()