Exemplo n.º 1
0
    def __init__(self, token: str, session: Optional[Session] = None):
        self.session = session or Session(headers={
            'Authorization': f'Bot {token}',
            'User-Agent': r'yu1za1 (N/A, sun.0)'
        })

        self.ratelimits = {'': Ratelimit(), 'global': Ratelimit(50, 1)}
Exemplo n.º 2
0
 async def getSingal(self):
     session = Session()
     async with trio.open_nursery() as nursery:
         send_channel, receive_channel = trio.open_memory_channel(0)
         for alfaEngine in self.alfaEngines:
             nursery.start_soon(alfaEngine.singal, send_channel)
         nursery.start_soon(self.executionEngine.receive, receive_channel,
                            session)
Exemplo n.º 3
0
 def __init__(self, genesis_time: int, beacon_node_endpoint: str,
              slots_per_epoch: Slot) -> None:
     self._genesis_time = genesis_time
     self._beacon_node_endpoint = beacon_node_endpoint
     self._slots_per_epoch = slots_per_epoch
     self._session = Session()
     self._connection_lock = trio.Lock()
     self._is_connected = False
Exemplo n.º 4
0
 def __init__(self, genesis_time: int, beacon_node_endpoint: str,
              seconds_per_slot: int) -> None:
     self._genesis_time = genesis_time
     self._beacon_node_endpoint = _normalize_url(beacon_node_endpoint)
     self._seconds_per_slot = seconds_per_slot
     self._ticks_per_slot = TICKS_PER_SLOT
     self._session = Session()
     self._connection_lock = trio.Lock()
     self._is_connected = False
Exemplo n.º 5
0
    async def getMarketData(self):
        session = Session()
        async with trio.open_nursery() as nursery:
            send_channel, receive_channel = trio.open_memory_channel(0)
            for markeDataEngine in self.marketDataEngines:
                nursery.start_soon(self.grabberData, markeDataEngine,
                                   send_channel, session)

            for name, alfaEngine in self.alfaEngines.items():
                log.info("Engine %s start", name)
                nursery.start_soon(alfaEngine.dataReceiver, receive_channel)
Exemplo n.º 6
0
 def __init__(self, genesis_time: int, beacon_node_endpoint: str,
              seconds_per_slot: int) -> None:
     self._genesis_time = genesis_time
     self._beacon_node_endpoint = _normalize_url(beacon_node_endpoint)
     self._seconds_per_slot = seconds_per_slot
     self._ticks_per_slot = TICKS_PER_SLOT
     self._session = Session()
     self._connection_lock = trio.Lock()
     self._is_connected = False
     self.client_version: Optional[str] = None
     # NOTE: this facilitates testing, may remove in the future...
     self._broadcast_operations: Set[Root] = set()
Exemplo n.º 7
0
def main():
    global session

    parser = argparse.ArgumentParser()
    parser.add_argument("index", help="URL to index page")
    args = parser.parse_args()

    url: str = args.index
    if url.endswith("index.htm"):
        url = url[:-9]

    assert len(url) > 0 and url.endswith('/')
    session = Session()
    trio.run(process, url)
Exemplo n.º 8
0
async def main():
	global w
	w = getenv('COLUMNS', get_terminal_size(stderr.fileno()).columns)
	params = {
#		'start': Date(2003,1,1),
#		'end': Date(2004,1,1),
#		'scope': Scope.COUNTRY,
	}
	filename = 'elections.jsonseq'

	async with Session(connections=100) as session:
		if not exists(filename):
			with open(filename, 'w', encoding='utf-8') as fp:
				async for e in Election.search(session, **params):
					dump([e.tojson()], fp, flush=True, ensure_ascii=False, indent=2)

		with open(filename, 'r') as fp:
			els = list(Election.fromjson(obj) for obj in load(fp))

		seed(57)
		shuffle(els)

		await collect_types(session, els)
Exemplo n.º 9
0
    def __init__(
        self,
        url: str,
        user_agent: str = None,
        maxlag: int = 5,
    ) -> None:
        """Initialize API object.

        :param url: the api's url, e.g.
            https://en.wikipedia.org/w/api.php
        :param maxlag: see:
            https://www.mediawiki.org/wiki/Manual:Maxlag_parameter
        :param user_agent: A string to be used as the User-Agent header value.
            If not provided a default value of f'mwpy/v{__version__}'} will be
            used, however that's not enough most of the time. see:
            https://meta.wikimedia.org/wiki/User-Agent_policy and
            https://www.mediawiki.org/wiki/API:Etiquette#The_User-Agent_header
        """
        self.url = url
        self.session = Session(
            connections=1,
            persist_cookies=True,
            headers={'User-Agent': user_agent or f'mwpy/v{__version__}'})
        self.maxlag = maxlag
Exemplo n.º 10
0
 def session(self) -> Session:
     url = self._get_post_url()
     auth_header = self._generate_auth_header()
     return Session(url, headers=auth_header)
Exemplo n.º 11
0
 async def start_executor(self):
     self._limiter = trio.Lock()
     self._session = Session(connections=1)
Exemplo n.º 12
0
import json
import os

import asks
from asks import Session
from quart import request, Response
from quart_trio import QuartTrio

ENABLE_DEBUG = bool(os.environ.get('ROCKETCHAT_WEBHOOK_PROXY_DEBUG', False))
TARGET_URL = os.environ.get("ROCKETCHAT_WEBHOOK_PROXY_TARGET")
if not TARGET_URL:
    raise RuntimeError(
        "Required env variable ROCKETCHAT_WEBHOOK_PROXY_TARGET is missing.")

asks.init("trio")
session = Session(connections=8)
app = QuartTrio(__name__)


@app.route("/<token_a>/<token_b>", methods=["POST"])
async def webhook(token_a, token_b):
    request_data = await request.get_json(force=True)
    if ENABLE_DEBUG:
        print(f"Request data:\n{json.dumps(request_data, indent=2)}")
    target_url = f"{TARGET_URL}/{token_a}/{token_b}"
    response = await session.post(target_url, json=request_data)
    return Response(response.text,
                    content_type=response.headers["content-type"])


if __name__ == "__main__":