예제 #1
0
파일: site.py 프로젝트: vshauna/websight
def index():
    with open('sexycaracas.json') as f:
        providers = json.loads(f.read())
    with open('vesusd.json') as f:
        vesusd = json.loads(f.read())
    with open('chaturbate.json') as f:
        s = f.read()
        streams = json.loads(s)
    if request.args.get('cb', False) != False:
        cb = True
    else:
        cb = False
    sc = session.query(SexProviderSnapshot).filter(SexProviderSnapshot.available==True).order_by(SexProviderSnapshot.price.asc()).all()
    prices_sc = [float(p.price) for p in sc]
    stats_sc = {'mean': int(np.mean(prices_sc)), 'median': int(np.median(prices_sc)), 'min': min(prices_sc), 'max': max(prices_sc)}
    last_trades = Trade.last_trades(100, result=(Trade.date, Trade.amount, Trade.price))
    last_trades.reverse()
    last_trades = tuple((trade[0].replace(tzinfo=datetime.timezone.utc).astimezone(tz=pytz.timezone('America/Caracas')).replace(tzinfo=None),
                         locale.format('%.8f', trade[1], grouping=True),
                         locale.format('%.2f', trade[2], grouping=True),
                         locale.format('%.2f', trade[1]*trade[2], grouping=True))
                        for trade in last_trades)
    if streams['good']:
        stream = streams['good'][0]
    else:
        stream = None
    
    music_tags = ['<iframe style="border: 0; width: 100%; height: 120px;" src="https://bandcamp.com/EmbeddedPlayer/album=158016030/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/" name="{}" seamless><a href="http://galaxie500.bandcamp.com/album/on-fire">On Fire by Galaxie 500</a></iframe>'.format(int(datetime.datetime.utcnow().timestamp())),
                  '<iframe style="border: 0; width: 100%; height: 120px;" src="https://bandcamp.com/EmbeddedPlayer/album=1696464046/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/" name="{}" seamless><a href="http://pwelverumandsun.bandcamp.com/album/dont-wake-me-up">Don&#39;t Wake Me Up by the Microphones</a></iframe>'.format(int(datetime.datetime.utcnow().timestamp())),]
    return render_template('index.html', stats_sc=stats_sc, vesusd=vesusd, last_trades=last_trades, sc_urls=[sc[0].source_url, random.choice([x for x in sc if int(x.price) == stats_sc['median']]).source_url, sc[-1].source_url], stream=stream, music_tag=random.choice(music_tags), cb=cb)