How to use the funcy.silent function in funcy

To help you get started, we’ve selected a few funcy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github idrdex / star-django / tags / views.py View on Github external
def search(request):
    # Save last specie in session
    specie = request.GET.get('specie')
    if specie != request.session.get('specie'):
        request.session['specie'] = specie

    q = request.GET.get('q')
    if not q:
        return {'series': None}

    exclude_tags = lkeep(silent(int), request.GET.getlist('exclude_tags'))
    series_tags, tag_series, tag_ids = series_tags_data()

    # Parse query
    q_string, q_tags = _parse_query(q)
    q_tags, wrong_tags = lsplit(lambda t: t.lower() in tag_ids, q_tags)
    if wrong_tags:
        message = 'Unknown tag%s %s.' % ('s' if len(wrong_tags) > 1 else '', ', '.join(wrong_tags))
        messages.warning(request, message)
    if not q_string and not q_tags:
        return {'series': None}

    # Build qs
    qs = search_series_qs(q_string)
    if specie:
        qs = qs.filter(specie=specie)
github SteemData / steemdata-mongo / src / scraper.py View on Github external
log_output += \
            f'(Posts: {r.upserted_count} upserted, {r.modified_count} modified) '
    if comments:
        r = mongo.Comments.bulk_write(
            [UpdateOne({'identifier': x['identifier']},
                       {'$set': {**x, 'updatedAt': dt.datetime.utcnow()}},
                       upsert=True)
             for x in comments],
            ordered=False,
        )
        log_output += \
            f'(Comments: {r.upserted_count} upserted, {r.modified_count} modified) '

    # We are only querying {type: 'comment'} blocks and sometimes
    # the gaps are larger than the batch_size.
    index = silent(max)(lpluck('block_num', results)) or (start_block + batch_size)
    indexer.set_checkpoint('comments', index)

    log.info(f'Checkpoint: {index} {log_output}')
github Netherdrake / conductor / conductor / markets.py View on Github external
def steem_btc_ticker():
        prices = {}
        urls = [
            "https://poloniex.com/public?command=returnTicker",
            "https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-STEEM",
            "https://api.binance.com/api/v1/ticker/24hr",
        ]
        responses = list(silent(requests.get)(u, timeout=30) for u in urls)

        for r in [x for x in responses
                  if hasattr(x, "status_code") and x.status_code == 200 and x.json()]:
            if "poloniex" in r.url:
                with suppress(KeyError):
                    data = r.json()["BTC_STEEM"]
                    prices['poloniex'] = {
                        'price': float(data['last']),
                        'volume': float(data['baseVolume'])}
            elif "bittrex" in r.url:
                with suppress(KeyError):
                    data = r.json()["result"][0]
                    price = (data['Bid'] + data['Ask']) / 2
                    prices['bittrex'] = {'price': price, 'volume': data['BaseVolume']}
            elif "binance" in r.url:
                with suppress(KeyError):
github idrdex / star-django / analysis / views.py View on Github external
def log(request, analysis_id):
    analysis = get_object_or_404(Analysis, pk=analysis_id)
    offset = silent(int)(request.GET.get('offset')) or 0

    log_lines = redis_client.lrange('analysis:%s:log' % analysis_id, offset, -1)
    log_lines = [l.decode() for l in log_lines]
    if request.is_ajax():
        return JsonResponse(log_lines, safe=False)
    else:
        return {'analysis': analysis, 'log_lines': log_lines}
github Netherdrake / conductor / conductor / markets.py View on Github external
def btc_usd_ticker(verbose=False):
        prices = {}
        urls = [
            "https://api.bitfinex.com/v1/pubticker/BTCUSD",
            "https://api.gdax.com/products/BTC-USD/ticker",
            "https://api.kraken.com/0/public/Ticker?pair=XBTUSD",
            "https://www.okcoin.com/api/v1/ticker.do?symbol=btc_usd",
            "https://www.bitstamp.net/api/v2/ticker/btcusd/",
        ]
        responses = list(silent(requests.get)(u, timeout=30) for u in urls)

        for r in [x for x in responses
                  if hasattr(x, "status_code") and x.status_code == 200 and x.json()]:
            if "bitfinex" in r.url:
                with suppress(KeyError):
                    data = r.json()
                    prices['bitfinex'] = {
                        'price': float(data['last_price']),
                        'volume': float(data['volume'])}
            elif "gdax" in r.url:
                with suppress(KeyError):
                    data = r.json()
                    prices['gdax'] = {
                        'price': float(data['price']),
                        'volume': float(data['volume'])}
            elif "kraken" in r.url:
github Netherdrake / conductor / conductor / cli.py View on Github external
echo('Imported a witness %s from its existing settings.' % account)

    else:
        click.confirm('Witness %s does not exist. Would you like to create it?' % account, abort=True)

        c = new_config()
        c['witness']['name'] = account
        c['witness']['url'] = click.prompt(
            'What should be your witness URL?',
            default=c['witness']['url'],
        )
        creation_fee = click.prompt(
            'How much do you want the account creation fee to be (STEEM)?',
            default=c['props']['account_creation_fee'],
        )
        if silent(float)(creation_fee):
            creation_fee = "%s STEEM" % float(creation_fee)
        c['props']['account_creation_fee'] = str(Amount(creation_fee))

        c['props']['maximum_block_size'] = click.prompt(
            'What should be the maximum block size?',
            default=c['props']['maximum_block_size'],
        )
        c['props']['sbd_interest_rate'] = click.prompt(
            'What should be the SBD interest rate?',
            default=c['props']['sbd_interest_rate'],
        )
        set_config(c)
        witness_create(c)
        echo('Witness %s created!' % account)