Example #1
0
async def main():
    asks.init("curio")
    autoupdater.initialize()

    if len(sys.argv) > 1 and sys.argv[1] == "debug":
        await bot.connect("pyhtonbot2", "chat.freenode.net")
        await bot.join_channel("#8banana-bottest")
    else:
        await bot.connect("pyhtonbot", "chat.freenode.net")
        await bot.join_channel("#8banana")
        await bot.join_channel("##learnpython")
        await bot.join_channel("#lpmc")
        await bot.join_channel("#learnprogramming")

    # this only sent to #8banana
    info = (await
            subprocess.check_output(['git', 'log', '-1',
                                     '--pretty=%ai\t%B'])).decode('utf-8')
    update_time, commit_message = info.split("\t", 1)
    commit_summary = commit_message.splitlines()[0]

    await bot.send_privmsg("#8banana",
                           f"Updated at {update_time}: {commit_summary!r}")

    while True:
        try:
            await bot.mainloop()
        except OSError:
            autoupdater.restart()
Example #2
0
 def __init__(self, concurrency=None, overwrite=False, force_scrape=False):
     self.overwrite = overwrite
     self.force_scrape = force_scrape
     if not concurrency:
         concurrency = config.SPIDER_DEFAULT_CONCURRENCY
     asks.init('trio')
     self.session_pool = trio.Queue(concurrency)
     for i in range(concurrency):
         self.session_pool.put_nowait(AsyncSession())
Example #3
0
    def test__request(self, token):
        asks.init('curio')

        async def test_function():
            session = asks.Session()
            client = SlackAPICurio(session=session, token=token)
            response = await client._request('POST', 'https://slack.com/api//api.test', {}, {'token': token})
            return response[0], response[1]
        assert curio.run(test_function) == (200, b'{"ok":false,"error":"invalid_auth"}')
Example #4
0
async def main():
    asks.init("curio")
    autoupdater.initialize()

    await bot.connect("factoid_bot8", "chat.freenode.net")
    await bot.join_channel("#8banana-bottest")

    while True:
        try:
            await bot.mainloop()
        except OSError:
            traceback.print_exc()
            autoupdater.restart()
Example #5
0
    def test_sleep(self, token):
        asks.init('curio')

        async def test_function():
            delay = 1
            start = datetime.datetime.now()
            session = asks.Session()
            client = SlackAPICurio(session=session, token=token)
            await client.sleep(delay)
            stop = datetime.datetime.now()
            return datetime.timedelta(seconds=delay + 1) > (stop - start) > datetime.timedelta(seconds=delay)

        assert curio.run(test_function)
Example #6
0
    def test__request(self, token):
        asks.init("trio")

        async def test_function():
            session = asks.Session()
            client = SlackAPITrio(session=session, token=token)
            response = await client._request(
                "POST", "https://slack.com/api//api.test", {},
                {"token": token})
            return response[0], response[1]

        assert trio.run(test_function) == (
            200, b'{"ok":false,"error":"invalid_auth"}')
Example #7
0
def run(targetlist, sleeptime):
    """
    set up trio and chrome then run

    Parameters
    ----------

    targetlist: list of tuples
       (url, pngfile) pairs for snapshots
       
    sleeptime: int
       amount of time to sleep while waiting for webpage rendering

    """
    print(targetlist)
    asks.init("trio")
    the_port = get_free_port()
    print(f"using free port {the_port}")
    the_remote = f"--remote-debugging-port={the_port}"
    CHROME_PATH = str(chromium_executable())
    options = dict(
        stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    chrome_args = [
        CHROME_PATH,
        "--headless",
        "--disable-gpu",
        the_remote,
        r"about:blank",
    ]
    the_command = " ".join(chrome_args)
    logger.info(f"command sent to chrome:\n{the_command}\n\n")
    logger.info(f"command args: \n{chrome_args}\n\n")
    url = f"http://localhost:{the_port}"
    print(url)
    logger.info(f"first try: {url}")
    headless_ft = ft.partial(headless_chrome, chrome_args=chrome_args, options=options)
    trio.run(
        main,
        headless_ft,
        get_addr,
        url,
        make_request,
        targetlist,
        sleeptime,
        restrict_keyboard_interrupt_to_checkpoints=True,
    )
Example #8
0
 def __init__(self, index_url, target_dir):
   asks.init("trio")
   self.index_url = index_url
   if "@" in index_url:
     from asks import BasicAuth, DigestAuth
     index_url = index_url[8:]
     parts = index_url.partition("@")
     user, pw = parts[0].split(":")
     self.auth = BasicAuth((user, pw))
     # TODO: use the original protocol instead of hardcoded https
     self.index_url = "https://" + parts[2]
   else:
     self.auth = None
   self.target_dir = trio.Path(target_dir)
   self.session = asks.Session(connections=8)
   self.session.base_location = self.index_url
   self.log.debug(f"Base URL: {self.session.base_location}")
   self.api = LegacyApi(self.session, self.auth)
from collections import namedtuple
import time
import trio
import asks

asks.init('trio')

Service = namedtuple('Service', ('name', 'url', 'ip_attr'))

SERVICES = (
    Service('ipify', 'https://api.ipify.org?format=json', 'ip'),
    Service('ip-api', 'http://ip-api.com/json', 'this-is-not-an-attr'),
    Service('borken', 'http://no-way-this-is-going-to-work.com/json', 'ip')
)


async def fetch_ip(service):
    start = time.time()
    print('Fetching IP from {}'.format(service.name))

    try:
        response = await asks.get(service.url)
        json_response = response.json()
    except:
        print('{} is unresponsive'.format(service.name))
    else:
        ip = json_response[service.ip_attr]
        print('{} finished with result: {}, took: {:.2f} seconds'.format(
            service.name, ip, time.time() - start))

Example #10
0
 def setup_class(cls):
     asks.init('trio')
Example #11
0
def awat():
    asks.init('trio')
Example #12
0
import asks
import curio
from tools import *
from tenacity import *  #retry mothed

asks.init('curio')

maxRetryTime = 2
requestTimeout = 5


class Task():
    def __init__(self, tasks, sessionConnections=10):
        '''
        :param taskList:  taskList dict,
        {'public':{
        mothed:get|post
        cookies:cookies字典
        headers:headers字典
        responseType:text|json|stream  仅在为stream时result保存的是stream的临时文件,否则保存返回的text
                     json可以为用来标示结果是否为json
        }
        'taskList':[{
        url:'http://www.qq.com',必填
        params:get参数字典
        data:post数据,字典或是str
        #结果数据
        responseType:text|json|stream  仅在为stream时result保存的是stream的临时文件,否则保存返回的text
                     json可以为用来标示结果是否为json
        requestOk:1或0,返回的状态码为200即成功。
        callbackOk:1,0,如果callback函数成功执行即为1
#!/usr/bin/python3

import serverboards_aio as serverboards
import curio
import asks
import re
from serverboards import print
asks.init('curio')


@serverboards.rpc_method
def serverboards_extractor(config, table, quals, columns):
    if table == "service":
        return service_extractor(quals, columns)
    if table == "user":
        return user_extractor(quals, columns)
    if table == "rules":
        return rules_extractor(quals, columns)
    return {
        "columns": columns,
        "rows": []
    }


def service_extractor(quals, columns):
    services = serverboards.service.list()

    rows = []
    for s in services:
        rows.append([
            s["uuid"],
Example #14
0
__all__ = ["CurioAsksSession"]

import curio
import asks
from asks import Session

from .abc import AbstractSession
from ..models import Response

asks.init("curio")


class CurioAsksSession(Session, AbstractSession):
    def __init__(self, *args, **kwargs):
        if kwargs.get("timeout"):
            del kwargs["timeout"]
            kwargs.pop("timeout", None)
        super().__init__(*args, **kwargs)

    async def send(self,
                   *requests,
                   timeout=None,
                   full_res=False,
                   raise_for_status=True,
                   session_factory=None,
                   backoff_decorator=lambda x: x):
        async def resolve_response(request, response):
            data = None
            json = None
            download_file = None
            upload_file = None
Example #15
0
import os
import sys
import pprint
import logging

import asks
import trio
import slack
from slack.io.curio import SlackAPI

logging.basicConfig(level=logging.INFO)
LOG = logging.getLogger(__name__)

asks.init("trio")


async def iterate(client):

    async for channel in client.iter(slack.methods.CHANNELS_LIST, limit=4):
        pprint.pprint(channel)


if __name__ == "__main__":

    if len(sys.argv) > 1:
        TOKEN = sys.argv[1]
    else:
        TOKEN = os.environ.get("SLACK_TOKEN")

    if not TOKEN:
        raise ValueError("No slack token provided !")
Example #16
0
"""
The core of Curious.

This package contains the bulk of the network interface with Discord, including parsing data that is incoming and 
delegating it to client code.

.. currentmodule:: curious.core

.. autosummary::
    :toctree: core
    
    client
    event
    gateway
    httpclient
    state
"""
import asks
import multio

if asks.init != multio.init:
    _init = multio.init
    multio.init = lambda lib: (asks.init(lib), _init(lib))

multio.init("curio")
Example #17
0
 def __init__(self):
     self.results_list = []
     asks.init(trio)
Example #18
0
def awat():
    asks.init('curio')
Example #19
0
#!/usr/bin/env python
"""Bot module"""

import json
import asks
import trio
import trio_websocket

asks.init(trio)


def get_cookie_from_response(response, cookie_name):
    """Returns cookie value of cookie_name"""
    return next((c.value for c in response.cookies if c.name == cookie_name),
                None)


AUTH_COOKIE = 'QUART_AUTH'
DEBUG = False


class User:
    """User class"""
    def __init__(self, name: str = "") -> None:
        self.name = name
        self.world = 0
        self.x = 0.0
        self.y = 0.0
        self.z = 0.0
        self.roll = 0.0
        self.yaw = 0.0
Example #20
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
ref1: https://github.com/AppSign/douyin  抖音通信协议 2.9.1版本协议签名
ref2: https://github.com/hacksman/spider_world 抖音爬虫例子
'''

import trio, asks, logging, json, time, os, arrow, socket, random
asks.init('trio')

logging.basicConfig(
    level=logging.INFO,
    format=
    '%(asctime)s %(filename)s:%(lineno)d %(threadName)s:%(funcName)s %(levelname)s] %(message)s'
)
IPHONE_HEADER = {"User-Agent": "Aweme/2.8.0 (iPhone; iOS 11.0; Scale/2.00)"}
CURL_TIMEOUT = 60
DOWNLOAD_TIMEOUT = 600
RETRIES_TIMES = 5

# 基本配置
_API = "https://api.appsign.vip:2688"
APPINFO = {
    "version_code": "2.7.0",
    "app_version": "2.7.0",
    "channel": "App%20Stroe",
    "app_name": "aweme",
    "build_number": "27014",
    "aid": "1128",
}
'''
 def __init__(self, settings_path, alg='RS256', timeout=30, user_id=None):
     super().__init__(settings_path)
     asks.init('trio')
     self.session = asks.Session()
     payload = self.make_payload(alg=alg, timeout=timeout, user_id=user_id)
     trio.run(self.authorize, AUTH_URL, AUTH_HEADERS, payload)