当前位置: 首页>>代码示例>>Python>>正文


Python config.USER_AGENT属性代码示例

本文整理汇总了Python中config.USER_AGENT属性的典型用法代码示例。如果您正苦于以下问题:Python config.USER_AGENT属性的具体用法?Python config.USER_AGENT怎么用?Python config.USER_AGENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在config的用法示例。


在下文中一共展示了config.USER_AGENT属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def main():
    match_text = "INSERT TEXT HERE"

    r = praw.Reddit(
        user_agent=config.USER_AGENT,
        client_id=config.R_CLIENT_ID,
        client_secret=config.R_CLIENT_SECRET,
        username=config.R_USERNAME,
        password=config.R_PASSWORD,
    )

    user = r.redditor(config.R_USERNAME)
    comments = list(user.comments.new())

    count = 0
    for c in comments:
        if match_text in c.body:
            c.delete()
            count += 1
    print "Comments deleted: {}".format(count) 
开发者ID:renfredxh,项目名称:compilebot,代码行数:22,代码来源:delete_comments.py

示例2: log

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def log(message, alert=False):
    """Log messages along with a timestamp in a log file. If the alert
    option is set to true, send a message to the admin's reddit inbox.
    """
    t = time.strftime('%y-%m-%d %H:%M:%S', time.localtime())
    message = "{}: {}\n".format(t, message)
    message = message.encode('utf8', 'replace')
    if config.LOG_FILE:
        with open(config.LOG_FILE, 'a') as f:
            f.write(message)
    else:
        print(message, end='')
    if alert and config.ADMIN:
        r = praw.Reddit(config.USER_AGENT)
        r.login(config.R_USERNAME, config.R_PASSWORD)
        admin_alert = message
        subject = "CompileBot Alert"
        r.redditor(config.ADMIN).message(subject, admin_alert) 
开发者ID:renfredxh,项目名称:compilebot,代码行数:20,代码来源:compilebot.py

示例3: main

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def main():
    r = praw.Reddit(
        user_agent=config.USER_AGENT,
        client_id=config.R_CLIENT_ID,
        client_secret=config.R_CLIENT_SECRET,
        username=config.R_USERNAME,
        password=config.R_PASSWORD,
    )
    if config.SUBREDDIT:
        config.BANNED_USERS
        config.BANNED_USERS = get_banned(r)
    # Iterate though each new comment/message in the inbox and
    # process it appropriately.
    inbox = r.inbox.unread()
    for new in inbox:
        try:
            process_unread(new, r)
        except:
            tb = traceback.format_exc()
            # Notify admin of any errors
            log("Error processing comment {c.id}\n"
                "{traceback}".format(c=new, traceback=code_block(tb)), alert=True)
        finally:
            new.mark_read() 
开发者ID:renfredxh,项目名称:compilebot,代码行数:26,代码来源:compilebot.py

示例4: start

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def start():
    """Start the sneakpeek application."""
    logging.info("Starting application")
    logging.info("Instantiating Reddit instance")
    reddit = praw.Reddit(
        client_id=config.CLIENT["ID"],
        client_secret=config.CLIENT["SECRET"],
        user_agent=config.USER_AGENT,
        username=config.USERNAME,
        password=config.PASSWORD)

    try:
        scan(reddit.subreddit(config.SUBREDDIT))
    except Exception as exception:
        # This should never happen,
        # because it breaks the infinite subreddit monitoring
        # provided by subreddit.stream.submissions()
        logging.critical("Exception occurred while scanning. This should never happen.")
        logging.critical(exception) 
开发者ID:fterh,项目名称:sneakpeek,代码行数:21,代码来源:main.py

示例5: populate_heroes

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def populate_heroes():
    """Method to update heroes in the Heroes table with hero names and proper css classes names as
    taken from the DotA2 subreddit and hero flair images from the reddit directory.

    Uses rapidfuzz for fuzzy matching of hero names to name found in `.flair-name` property in css.
    """
    hero_names = db_api.get_all_hero_names()

    response = requests.get(STYLESHEET_URL, headers={'User-Agent': USER_AGENT})
    r = json.loads(response.text)
    stylesheet = r['data']['stylesheet']

    r = re.compile(FLAIR_REGEX)
    for flair in r.finditer(stylesheet):
        flair_css = flair['css_class']
        img_path = flair['img_path']
        flair_hero = img_path[6:]

        match, confidence = process.extractOne(flair_hero, hero_names)
        if confidence >= 90:
            db_api.update_hero(hero_name=match, img_path=img_path, flair_css=flair_css) 
开发者ID:Jonarzz,项目名称:DotaResponsesRedditBot,代码行数:23,代码来源:css_parser.py

示例6: task_fetch_og_meta

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def task_fetch_og_meta() -> _Response:
    task = p.parse(flask.request)
    app.logger.info(f"task={task!r}")
    iri = task.payload
    try:
        activity = ap.fetch_remote_activity(iri)
        app.logger.info(f"activity={activity!r}")
        if activity.has_type(ap.ActivityType.CREATE):
            note = activity.get_object()
            links = opengraph.links_from_note(note.to_dict())
            og_metadata = opengraph.fetch_og_metadata(config.USER_AGENT, links)
            for og in og_metadata:
                if not og.get("image"):
                    continue
                config.MEDIA_CACHE.cache_og_image(og["image"], iri)

            app.logger.debug(f"OG metadata {og_metadata!r}")
            DB.activities.update_one(
                {"remote_id": iri}, {"$set": {"meta.og_metadata": og_metadata}}
            )

        app.logger.info(f"OG metadata fetched for {iri}: {og_metadata}")
    except (ActivityGoneError, ActivityNotFoundError):
        app.logger.exception(f"dropping activity {iri}, skip OG metedata")
        return ""
    except requests.exceptions.HTTPError as http_err:
        if 400 <= http_err.response.status_code < 500:
            app.logger.exception("bad request, no retry")
            return ""
        app.logger.exception("failed to fetch OG metadata")
        raise TaskError() from http_err
    except Exception as err:
        app.logger.exception(f"failed to fetch OG metadata for {iri}")
        raise TaskError() from err

    return "" 
开发者ID:tsileo,项目名称:microblog.pub,代码行数:38,代码来源:tasks.py

示例7: task_send_webmention

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def task_send_webmention() -> _Response:
    task = p.parse(flask.request)
    app.logger.info(f"task={task!r}")
    note_url = task.payload["note_url"]
    link = task.payload["link"]
    remote_id = task.payload["remote_id"]
    try:
        app.logger.info(f"trying to send webmention source={note_url} target={link}")
        webmention_endpoint = discover_webmention_endpoint(link)
        if not webmention_endpoint:
            app.logger.info("no webmention endpoint")
            return ""

        resp = requests.post(
            webmention_endpoint,
            data={"source": note_url, "target": link},
            headers={"User-Agent": config.USER_AGENT},
        )
        app.logger.info(f"webmention endpoint resp={resp}/{resp.text}")
        resp.raise_for_status()
    except HTTPError as err:
        app.logger.exception("request failed")
        if 400 <= err.response.status_code <= 499:
            app.logger.info("client error, no retry")
            return ""

        raise TaskError() from err
    except Exception as err:
        app.logger.exception(f"failed to cache actor for {link}/{remote_id}/{note_url}")
        raise TaskError() from err

    return "" 
开发者ID:tsileo,项目名称:microblog.pub,代码行数:34,代码来源:tasks.py

示例8: get_account

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def get_account():
    """Method that provides the connection to Reddit API using OAuth.
        :return: Reddit instance.
    """
    return praw.Reddit(client_id=config.CLIENT_ID,
                       client_secret=config.CLIENT_SECRET,
                       user_agent=config.USER_AGENT,
                       username=config.USERNAME,
                       password=config.PASSWORD) 
开发者ID:Jonarzz,项目名称:DotaResponsesRedditBot,代码行数:11,代码来源:account.py

示例9: do_request

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def do_request(url):
    """ A method which loads a page """

    global data_meter
    global good_requests
    global bad_requests

    debug_print("  Requesting page...".format(url))

    headers = {'user-agent': config.USER_AGENT}

    try:
        r = requests.get(url, headers=headers, timeout=5)
    except:
        # Prevent 100% CPU loop in a net down situation
        time.sleep(30)
        return False

    page_size = len(r.content)
    data_meter += page_size

    debug_print("  Page size: {}".format(hr_bytes(page_size)))
    debug_print("  Data meter: {}".format(hr_bytes(data_meter)))

    status = r.status_code

    if (status != 200):
        bad_requests += 1
        debug_print("  Response status: {}".format(r.status_code), Colors.RED)
        if (status == 429):
            debug_print(
                "  We're making requests too frequently... sleeping longer...")
            config.MIN_WAIT += 10
            config.MAX_WAIT += 10
    else:
        good_requests += 1

    debug_print("  Good requests: {}".format(good_requests))
    debug_print("  Bad reqeusts: {}".format(bad_requests))

    return r 
开发者ID:ReconInfoSec,项目名称:web-traffic-generator,代码行数:43,代码来源:gen.py

示例10: get_headers

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def get_headers():
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
        'User-Agent': random.choice(USER_AGENT),
        'Accept-Language': 'en-US,en;q=0.5',
        'Connection': 'keep-alive',
        'Accept-Encoding': 'gzip, deflate',
        'Upgrade-Insecure-Requests': '1'
    }
    return headers 
开发者ID:Eeyhan,项目名称:get_jobs,代码行数:12,代码来源:headers.py

示例11: __init__

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def __init__(self):
        self.header = None
        self.proxy_list = []  # 代理IP列表
        self.user_agent = USER_AGENT  # 请求的UA
        self.user_agent_66ip = random.choice(USER_AGENT)  # 66ip代理使用
        self.header = self.get_header  # 请求头

        # 节省创建对象的资源
        self.test_proxy_urls = self.get_test_site  # 测试代理IP的网址
        self.proxy_urls = self.get_proxy_site  # 免费代理网址 
开发者ID:Eeyhan,项目名称:get_jobs,代码行数:12,代码来源:proxy.py

示例12: task_post_to_remote_inbox

# 需要导入模块: import config [as 别名]
# 或者: from config import USER_AGENT [as 别名]
def task_post_to_remote_inbox() -> _Response:
    """Post an activity to a remote inbox."""
    task = p.parse(flask.request)
    app.logger.info(f"task={task!r}")
    payload, to = task.payload["payload"], task.payload["to"]
    try:
        app.logger.info("payload=%s", payload)
        app.logger.info("generating sig")
        signed_payload = json.loads(payload)

        app.logger.info("to=%s", to)
        resp = requests.post(
            to,
            data=json.dumps(signed_payload),
            auth=SIG_AUTH,
            headers={
                "Content-Type": config.HEADERS[1],
                "Accept": config.HEADERS[1],
                "User-Agent": config.USER_AGENT,
            },
        )
        app.logger.info("resp=%s", resp)
        app.logger.info("resp_body=%s", resp.text)
        resp.raise_for_status()
    except HTTPError as err:
        track_failed_send(to)

        app.logger.exception("request failed")
        if 400 <= err.response.status_code <= 499:
            app.logger.info("client error, no retry")
            return ""

        raise TaskError() from err
    except requests.RequestException:
        track_failed_send(to)

        app.logger.exception("request failed")

    except Exception as err:
        app.logger.exception("task failed")
        raise TaskError() from err

    track_successful_send(to)

    return "" 
开发者ID:tsileo,项目名称:microblog.pub,代码行数:47,代码来源:tasks.py


注:本文中的config.USER_AGENT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。