Example #1
0
    def process_listings(self):
        """
        Fetching and parsing stations and listings
        """
        logger.debug('Fetching stations.json for listings')
        stations = self._fetch_json('http://eddb.io/archive/v3/stations.json')

        logger.debug('Processing listings')
        for station in stations:
            if station['listings'] is None or len(station['listings']) == 0:
                continue  # Nothing to do here, moving on!
            for listing in station['listings']:
                listing['collected_at'] = datetime.datetime.fromtimestamp(
                    listing['collected_at'])
                new_listings = Listing(**listing)
                new_listings.save()
        logger.debug('Finished processing listings')
Example #2
0
def __handle_create_listing_post(request):
    try:
        user_id = request.POST['lister']
        lister = User.objects.get(pk=user_id)
        book_id = request.POST['book']
        book = Book.objects.get(pk=book_id)
        price = request.POST['price']
        listing = Listing(
            lister=lister,
            book=book,
            price=price,
            book_title=book.title,
        )
        listing.save()
        return generate_response("listing saved", True, listing)
    except KeyError as e:
        return generate_response("missing %s" % e.args[0].strip("'"), False)
    except Exception as e:
        return generate_response(str(e), False)
def __get_listing(id):
	listing = Listing.get_by_id(int(id))
	if listing is not None:
		return listing
	else:
		abort(404, {'error': LISTING_NOT_FOUND })
def delete(id):
	listing = __get_listing(id)
	Listing.delete(int(id))
	return '', 204
def list():
	rows = [r.to_json() for r in Listing.search(request.args)]
	return jsonify(data=rows), 200
        try:
            data = json.loads(t['data'])
        except ValueError:
            data = {'error': 'Invalid JSON'}

        if data.get('a') == "pl":
            try:
                listing_data = {
                    "tx_id": t['txids'][0],
                    "game_name": data['gn'],
                    "currency_name": data['cn'],
                    "currency_amount": data['ca'],
                    "cost": data['c'],
                    "details": data['d'],
                    "seller_address": t['from_address'],
                    "block_number": t['heights'][0]
                }
                if (listing_data['game_name'] and listing_data['currency_name']
                        and listing_data['currency_amount']
                        and listing_data['cost'] and listing_data['details']):
                    print "listing_data", listing_data
                    try:
                        new_l = Listing(**listing_data)
                        new_l.save()
                    except:
                        print "Error (type error?) while trying to save: ", listing_data
            except KeyError:
                pass

    time.sleep(10)