示例#1
0
def send_message(bot: Bot, text, node, thread_id=None):

    evaluated_text = substitute_vars(
        text,
        receiver=ignore(AttributeError,
                        '')(lambda: node.get_username(bot).username)(),
        bio=node.get_bio(bot),
    )

    user_id = node.pk if node.pk else node.get_id(bot)
    urls = extract_urls(text)
    item_type = 'link' if urls else 'text'

    bot.api.send_direct_item(item_type,
                             users=[str(user_id)],
                             text=evaluated_text,
                             thread=thread_id,
                             urls=urls)
    if bot.last['status'] == 'ok':
        bot.logger.debug('texted %s' % node)
        bot.sleep('text')
        return node
    else:
        bot.logger.error("message to {} wasn't sent".format(node))
        bot.sleep('error')
        return None
示例#2
0
def do_comment(bot: Bot, text, node, thread_id=None):

    media_id = node.pk
    # print('caption', node.caption._yaml())
    evaluated_text = substitute_vars(
        text,
        author=ignore(Exception, '')(lambda: User(**node.user).username)(),
        # caption=node['caption']['text'],
        geotag=ignore(Exception,
                      '')(lambda: Geotag(**node.location).name or '')(),
        usertags=ignore(Exception, '')(
            lambda: list(map(lambda x: User(**x), node._usertags)) or [])())

    bot.api.post_comment(
        media_id=media_id,
        comment_text=evaluated_text,
    )

    bot.logger.info('commented %s' % node)
    bot.total['comments'] += 1
    bot.sleep('comment')
    return node
示例#3
0
def validation_stage(call, message):
    call = stacklog(logger.info,
                    'Ballet Validation: {message}'.format(message=message),
                    conditions=[(SkippedValidationTest, 'SKIPPED')])(call)
    call = ignore(SkippedValidationTest)(call)
    return call()
示例#4
0
    def is_ignored(self, path: "StrPath") -> bool:
        from git.exc import GitCommandError

        func = ignore(GitCommandError)(self.repo.git.check_ignore)
        return bool(func(str(path)))
示例#5
0
文件: main.py 项目: ballet/ballet
def validation_stage(call: Call, message: str):
    call = stacklog(logger.info,
                    f'Ballet Validation: {message}',
                    conditions=[(SkippedValidationTest, 'SKIPPED')])(call)
    call = ignore(SkippedValidationTest)(call)
    return call()
示例#6
0
    def is_ignored(self, path: "Union[str, os.PathLike[str]]") -> bool:
        from git.exc import GitCommandError

        func = ignore(GitCommandError)(self.repo.git.check_ignore)
        return bool(func(str(path)))
示例#7
0
import json
import logging

from tempfile import NamedTemporaryFile
from typing import Any, Dict, List

import funcy as F
from funcy.funcs import identity

from openpyxl import Workbook, load_workbook
from openpyxl.worksheet.worksheet import Worksheet
import ckan.plugins.toolkit as tk

log = logging.getLogger(__name__)

safe_loads = F.ignore((ValueError, TypeError))(json.loads)


def _make_export_doc():
    doc = Workbook()
    del doc["Sheet"]
    return doc


def _simplified_schemas() -> Dict[str, List[Dict[str, Any]]]:

    schemas = {
        name: {
            "dataset":
            _simplify_fields(options["dataset_fields"]) + [{
                "name": "id"