Пример #1
0
 async def initYummyPicture(self):
     ymConfig.reload()
     self.ratings = {}
     self.ym = ymConfig.getConfig('setting').get('ripper')
     logger.debug('reload configs')
     pkg = importlib.import_module('application.YummyPicture.yummy.' + self.ym)
     self.dataClass = getattr(pkg, f'{self.ym.capitalize()}Data')
     self.ripperClass = getattr(pkg, f'{self.ym.capitalize()}Ripper')
     self.databaseClass = getattr(pkg, f'{self.ym.capitalize()}Database')
     self.db = self.databaseClass()
Пример #2
0
 async def get(self) -> 'list':
     # params = {}
     self.__build()
     connector: ProxyConnector = ProxyConnector()
     proxy = ymConfig.getConfig('setting').get('proxy')
     if proxy:
         connector = ProxyConnector.from_url(proxy)
     data: list = []
     for k, t in self.rips.items():
         async with aiohttp.request('GET', k, connector=connector) as response:
             raw = await response.read()
         logger.debug(k + f"\n[{t[0]}, {t[1]}]")
         data = data + json.loads(raw)[t[0]:t[1]]
     result: list = self._formatData(data)
     await connector.close()
     self.hasParm = 0
     self.hasAction = ''
     self.rips.clear()
     return result
Пример #3
0
class YandeRipper(Ripper):
    def __init__(self):
        super(YandeRipper, self).__init__()
        self.actions = dict(new='post',
                            search='post',
                            random='post',
                            popular='post/popular_recent')
        self.periods = {'1d': '1d', '1w': '1w', '1m': '1m', '1y': '1y'}
        self.rip = 'https://yande.re/'
        self.per_page = 40

    def __build(self):
        # build action
        self.parse(self.actions[self.has_action.value] + '.json?')
        # build option
        # bind popular
        if self.has_action == RipperConst.POPULAR:
            self.parm('period', self.has_period)
        # build random
        if self.has_action == RipperConst.RANDOM:
            self.has_tags.append('order:random')
            self.has_tags.append('rating:e')
        # build search
        if self.has_action in [RipperConst.SEARCH, RipperConst.RANDOM]:
            self.parm('tags', self.tags2str())
        # '''others'''

        # build rating
        if self.has_action == self.actions[RipperConst.NEW.value]:  # post
            self.__buildRating()
        # build page and variant
        self._buildVariant(offset=1)

    async def get(self) -> 'list':
        # params = {}
        self.__build()
        connector: ProxyConnector = ProxyConnector()
        if proxy := ymConfig.getConfig('setting').get('proxy'):
            connector = ProxyConnector.from_url(proxy)
        data: list = []
        for k, t in self.rips.items():
            async with aiohttp.request('GET', k,
                                       connector=connector) as response:
                raw = await response.read()
            logger.debug(k + f"\n[{t[0]}, {t[1]}]")
            data = data + json.loads(raw)[t[0]:t[1]]
        result: list = self._formatData(data)
        await connector.close()
        return result
Пример #4
0
 async def reCallYms(app: Slave, mid: int, t: int):
     await asyncio.sleep(t)
     try:
         await app.revokeMessage(mid)
     except ClientResponseError:
         logger.debug('recall fail, message may recalled by other admin')