async def show_pokemon(): for pokemon in pokemons: div.src, caption_top.text, caption_bottom.text = pokemon div.delete_components() or all( map(lambda it: div.add_component(it), [caption_top, caption_bottom])) jp.run_task(page.update()) or await asyncio.sleep(2)
async def startup(): async def updater(): while True: await update_page() await asyncio.sleep(20) jp.run_task(updater())
async def voltages(): while True: the_time.text = time.strftime("%a, %d %b %Y, %H:%M:%S", time.localtime()) all_readings = [] tn = lv_connect(controller_ip) for i in range(nslots): voltages = lv_readv(tn, i + 1) # print('Voltages Slot: ',i+1,voltages) voltages.insert(0, 'V' + str(i + 1)) all_readings.append(voltages) currents = lv_readi(tn, i + 1) # print('Currents Slot: ',i+1,currents) currents.insert(0, 'I' + str(i + 1)) all_readings.append(currents) lv_disconnect(tn) dfreadings = pd.DataFrame(all_readings, columns=chnames) gridv.load_pandas_frame(dfreadings) jp.run_task(wp.update()) await asyncio.sleep(1)
import justpy as jp import asyncio import requests as r pokemons, page = ( (r.get(it["url"]).json()["sprites"]["front_default"], f"{it['name'].title()} pomaga!", "A ty?") for it in r.get(f"https://pokeapi.co/api/v2/pokemon?limit=2000").json() ["results"]), jp.QuasarPage() div = jp.QImg(classes='absolute-center', style="width: 50vw; height: 90vh", a=page) caption_top, caption_bottom = [ jp.QDiv(classes=f"absolute-{pos} text-center text-h3") for pos in ["top", "bottom"] ] async def show_pokemon(): for pokemon in pokemons: div.src, caption_top.text, caption_bottom.text = pokemon div.delete_components() or all( map(lambda it: div.add_component(it), [caption_top, caption_bottom])) jp.run_task(page.update()) or await asyncio.sleep(2) jp.justpy(lambda: page, startup=lambda: jp.run_task(show_pokemon()))
async def clock_init(): jp.run_task(clock_counter())
async def clock_counter(): while True: clock_div.text = time.strftime("%a, %d %b %Y, %H:%M:%S", time.localtime()) jp.run_task(wp.update()) await asyncio.sleep(1)
async def voltages_init(): jp.run_task(voltages())
async def update_page(): nonlocal rbtc_balance try: rbtc_balance_wei = web3.eth.get_balance(config.account.address) rbtc_balance = from_wei(rbtc_balance_wei, 'ether') except Exception: pass with Session.begin() as dbsession: # TODO: the DB/Web3 calls should be async last_processed_block = dbsession.query( BlockInfo.block_number).filter_by( key='last_processed_block').scalar() latest_rewards = dbsession.query(Reward).order_by( Reward.created_at.desc()).limit(50).all() meta_info.delete_components() column1 = jp.parse_html(f""" <div class="column"> <div class="item"> <div class="key">Last processed block</div> <div class="value">{last_processed_block}</div> </div> <div class="item"> <div class="key">Rewarder account</div> <div class="value"> <a href="{config.explorer_url}/address/{str(config.account.address).lower()}" target="_blank"> {str(config.account.address).lower()} </a> </div> </div> <div class="item"> <div class="key">Rewarder balance</div> <div class="value"> {rbtc_balance} RBTC </div> </div> <div class="item"> <div class="key">RPC Url</div> <div class="value"> {config.rpc_url} </div> </div> </div> """, a=meta_info) for bridge_key, bridge_address in config.bridge_addresses.items(): jp.parse_html(f""" <div class="item"> <div class="key">Bridge address ({bridge_key})</div> <div class="value"> <a href="{config.explorer_url}/address/{bridge_address}" target="_blank"> {bridge_address} </a> </div> </div> """, a=column1) column2 = jp.Div(classes="column", a=meta_info) for symbol, threshold in config.reward_thresholds.items(): item = jp.Div(classes="item", a=column2) jp.Div(text=f'{symbol} threshold', classes="key", a=item) jp.Div(text=str(threshold), classes="value", a=item) reward_tbody.delete_components() for reward in latest_rewards: rbtc_decimal = from_wei(reward.reward_rbtc_wei, 'ether') # TODO: store this in the model (without fees) deposit_amount_decimal = from_wei( reward.deposit_amount_minus_fees_wei, 'ether') status_html = str(reward.status) if reward.reward_transaction_hash: status_html = ( f'<a target="_blank" href="{config.explorer_url}/tx/{reward.reward_transaction_hash}">' f'{status_html}</a>') user_address_html = ( f'<a target="_blank" href="{config.explorer_url}/address/{reward.user_address}">' f'{reward.user_address}</a>') jp.parse_html(f""" <tr> <td>{reward.id}</td> <td>{reward.created_at}</td> <td>{user_address_html}</td> <td>{str(deposit_amount_decimal)} {reward.deposit_side_token_symbol}</td> <td>{str(rbtc_decimal)} RBTC</td> <td>{status_html}</td> </tr> """, a=reward_tbody) jp.run_task(page.update())