Esempio n. 1
0
def _fetch_podcast_data(url):
    utils.validate_url(url, allow_hash=False)
    try:
        error_code = error_store.get_error(url)
        if error_code:
            logging.info("Won't fetch %s, since we got a %s response recently." % (url, error_code))
            return

        headers = {"User-Agent": current_app.config["USER_AGENT"]}
        logging.info("fetching %s" % url)
        resp, body = http.request(url, headers=headers)

        if resp.status != 200:
            logging.info("Received an error (%s) when trying to fetch %s" % (url, resp.status))
            _handle_error_response(resp)
            return
        parsed = feedparser.parse(body)
    except Exception as e:
        logging.exception("Exception raised trying to fetch %s" % url)
        return
    return _handle_feed(parsed, resp)
Esempio n. 2
0
    def update_profile(self, username=None, email=None, avatar_url=None):
        errors = []
        if username and username != user.username:
            username = utils.strip_control_chars(username)
            if self.is_username_available(username):
                self.username = username
            else:
                errors.append("The username you entered is taken.")

        if email:
            if "@" in email:
                self.primary_email = email
            else:
                errors.append("That email address is invalid.")

        if avatar_url:
            try:
                utils.validate_url(avatar_url)
                self.avatar_url = avatar_url
            except ValueError:
                errors.append("The avatar url is invalid.")

        return errors
Esempio n. 3
0
    def update_profile(self, username=None, email=None, avatar_url=None):
        errors = []
        if username and username != user.username:
            username = utils.strip_control_chars(username)
            if self.is_username_available(username):
                self.username = username
            else:
                errors.append("The username you entered is taken.")

        if email:
            if "@" in email:
                self.primary_email = email
            else:
                errors.append("That email address is invalid.")

        if avatar_url:
            try:
                utils.validate_url(avatar_url)
                self.avatar_url = avatar_url
            except ValueError:
                errors.append("The avatar url is invalid.")

        return errors
Esempio n. 4
0
def _fetch_podcast_data(url):
    utils.validate_url(url, allow_hash=False)
    try:
        error_code = error_store.get_error(url)
        if error_code:
            logging.info(
                "Won't fetch %s, since we got a %s response recently." %
                (url, error_code))
            return

        headers = {"User-Agent": current_app.config["USER_AGENT"]}
        logging.info("fetching %s" % url)
        resp, body = http.request(url, headers=headers)

        if resp.status != 200:
            logging.info("Received an error (%s) when trying to fetch %s" %
                         (url, resp.status))
            _handle_error_response(resp)
            return
        parsed = feedparser.parse(body)
    except Exception as e:
        logging.exception("Exception raised trying to fetch %s" % url)
        return
    return _handle_feed(parsed, resp)