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


Python models.Feed类代码示例

本文整理汇总了Python中models.Feed的典型用法代码示例。如果您正苦于以下问题:Python Feed类的具体用法?Python Feed怎么用?Python Feed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: track

def track(request):
    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            user = form.cleaned_data['username']
            raw_feed = build_feed(user, 5, 2)

            f = Feed(username = user)
            f.save()

            for track in raw_feed:
                art_url = 'http://i.imgur.com/BNBFGfg.jpg'
                if track[5] != None:
                    art_url = track[5]

                t = Track(id = track[0]
                        , date = track[1]
                        , title = track[2]
                        , artist = track[3]
                        , uri = track[4]
                        , art = art_url)
                t.save()

                f.tracks.add(t)

            return HttpResponseRedirect('track.html')
    else:
        form = UserForm()

    return render(request, 'subs/track.html', { 'form': form })
开发者ID:fsxfreak,项目名称:alternative-soundcloud-stream,代码行数:31,代码来源:views.py

示例2: create_feed

def create_feed(user,board_id,title,link,description,actions,public_board,get_all,token):
    """ Creates a feed and attaches it to a user object """
    user = get_user(user)
    q = Feed.query(
        Feed.channel_title==title,
        Feed.channel_link==link,
        Feed.channel_description==description,
        Feed.feed_name==title,
        Feed.token==token,
        Feed.actions.IN(actions),
        Feed.board_id==board_id,
        Feed.public_board==public_board)
    feed = q.get()
    if feed is None:
        feed = Feed(
            channel_title=title,
            channel_link=link,
            channel_description=description,
            feed_name=title,
            token=token,
            actions=actions,
            board_id=board_id,
            public_board=public_board,
            get_all=get_all,user=user.key)
        feed.put()
    if user.feeds:
        if feed.key not in user.feeds:
            user.feeds.append(feed.key)
            user.put()
    else:
        user.feeds = [feed.key]
        user.put()
    return create_url(feed.key.id())
开发者ID:naiyt,项目名称:trellorss-gae,代码行数:33,代码来源:utils.py

示例3: create_feed_from_url

def create_feed_from_url(url):
    """ Query the given URL, parse the results and create a Feed object. If
        the response isn't RSS then throw an error """
    f = feedparser.parse(url)

    # Handle obvious errors
    if f.bozo:
        handle_bozo_exception(f.bozo_exception)

    if 'status' in f and f.status in (200, 301, 302):
        # If we received a bozo exception raise it
        if f.bozo:
            handle_bozo_exception(f.bozo_exception)

        # If the resource has permanently moved update it's URL
        feed_url = url
        if f.status == 301:
            feed_url = f.href

        feed = Feed(parent=root_key(), name=f.channel.title, url=feed_url)
        if len(f.entries) > 0:
            feed.date_of_last_entry = datetime.fromtimestamp(
                mktime(f.entries[0].updated_parsed))
        return feed
    else:
        raise Exception("Unexpected result from feedparser.parse(): %s" % f)
开发者ID:adrian,项目名称:feed2me,代码行数:26,代码来源:views.py

示例4: test_get_with_permanent_redirect

    def test_get_with_permanent_redirect(self):
        # Create a dummy feed with a last_checked date well in the past
        last_checked = datetime(2013, 9, 21, 10, 0, 0, 0)
        date_of_last_entry = datetime(2013, 9, 20, 8, 45, 0, 0)
        feed = Feed(name = "Test Feed1",
                    last_checked = last_checked,
                    date_of_last_entry = date_of_last_entry,
                    url = './test-feeds/test-rss.xml',
                    parent = root_key())
        feed.put()

        # Stub out the publish_entry function so we don't have to deal with
        # the GAE mail API
        def _publish_entry(feed_title, entry, recipent_address):
            pass
        feed_utils.publish_entry = _publish_entry

        # Create a dummy function to return the feeds to check
        def _find_feeds_to_check(working_date = datetime.now()):
            return [feed]
        feed_utils.find_feeds_to_check = _find_feeds_to_check

        # Replace feedparser.parse with our own version that sets the status
        # code to 301 and the href to a new URL
        def _parse(url):
            parsed_feed = self.orig_parse_func(url)
            parsed_feed['status'] = 301
            parsed_feed['href'] = 'http://def.com'
            return parsed_feed
        feedparser.parse = _parse

        response = self.testapp.get('/check_feeds')

        # check the feed's URL has been updated
        self.assertEquals(feed.url, 'http://def.com')
开发者ID:adrian,项目名称:feed2me,代码行数:35,代码来源:test_check_feeds_handler.py

示例5: get_feeds

 def get_feeds(self, all = False):
     """Return feeds - defaults to returning enabled feeds only"""
     if all:
         result = [f for f in Feed.select()]
     else:
         result = [f for f in Feed.select(Feed.enabled == True)]
     return result
开发者ID:SimonCoopey,项目名称:bottle-fever,代码行数:7,代码来源:feeds.py

示例6: testFindFeedsToCheckMoreHoursThanFeeds

    def testFindFeedsToCheckMoreHoursThanFeeds(self):
        feeds = [
            {
                'name': 'Test 1',
                'last_checked': datetime(2017, 5, 6, 19, 7, 33)
            },
            {
                'name': 'Test 2',
                'last_checked': datetime(2017, 5, 5, 19, 6, 9)
            },
            {
                'name': 'Test 3',
                'last_checked': datetime(2017, 5, 4, 18, 23, 56)
            }
        ]

        for feed_data in feeds:
            feed = Feed(name = feed_data['name'],
                        last_checked = feed_data['last_checked'],
                        parent = root_key())
            feed.put()

        working_date = datetime(2017, 5, 6, 19, 45, 0)
        feeds = feed_utils.find_feeds_to_check(working_date)

        # there are 4 hours left in the day so only 1 feed will be returned
        self.assertEqual(1, len(feeds))
        self.assertEqual("Test 3", feeds[0].name)
开发者ID:adrian,项目名称:feed2me,代码行数:28,代码来源:test_feed_utils.py

示例7: try_push_resub

def try_push_resub():
    """Post all new items for feeds for a specific interval"""
    if request.headers.get('X-Appengine-Cron') != 'true':
        raise ndb.Return(jsonify_error(message='Not a cron call'))

    unsubscribed_feeds = Feed.query(Feed.hub != None, Feed.subscribed_at_hub == False)  # noqa
    qit = unsubscribed_feeds.iter()

    errors = 0
    success = 0
    count = 0

    futures = []

    while (yield qit.has_next_async()):
        feed = qit.next()
        futures.append((feed, Feed.subscribe_to_hub(feed)))

    for feed, future in futures:
        count += 1
        try:
            yield future
            success += 1
        except:
            errors += 1
            logger.exception('Failed to PuSH subscribe feed:%s' % (feed.feed_url, ))

    logger.info('Tried to call hub for num_unsubscribed_feeds:%s success:%s, errors:%s', count, success, errors)

    raise ndb.Return(jsonify(status='ok'))
开发者ID:ianmintz,项目名称:pourover,代码行数:30,代码来源:views.py

示例8: post

    def post(self):
        #表单字段: url, author, title, content, allow_sendto_kindle
        f = Feed()
        f.url = self.request.get('tUrl')
        f.title = self.request.get('tTitle')
        f.put(); # save

        return self.redirect('/feed')
开发者ID:tonychi,项目名称:readLater,代码行数:8,代码来源:main.py

示例9: create_feed

 def create_feed(self, title, url, days_since_checked=0, days_since_updated=0, owner=None):
     now = timezone.now()
     feed = Feed(url=url, title=title,
                                last_checked=now + datetime.timedelta(days=days_since_checked),
                                last_updated=now + datetime.timedelta(days=days_since_checked + days_since_updated),
                                owner = owner or self.default_user)
     feed.save()
     return feed
开发者ID:kal,项目名称:pireader,代码行数:8,代码来源:tests.py

示例10: add_feed

 def add_feed(self, url, site_url = None, title = None, group = None):
     """Add a feed to the database"""
     # existing feed?
     try:
         f = Feed.get(Feed.url == url)
     except Feed.DoesNotExist:
         f = Feed.create(url = url, title=title, site_url=site_url)
     db.close()
     return f
开发者ID:matsufan,项目名称:bottle-fever,代码行数:9,代码来源:feeds.py

示例11: add_feed_github

def add_feed_github(request, user=None):
#    if user is None:
#        return 'fail'


    if request.user.is_authenticated():

        user = request.REQUEST['user']
        url = 'https://github.com/%s/' % user
        feed_url = 'https://github.com/%s.atom' % user

    #    feed, create = Feed.objects.get_or_create(title=user)

        category, created = Category.objects.get_or_create(name='github', slug='github')

        feed = Feed()
        feed.title = user
        feed.url = url
        feed.category = category
        feed.feed_url = feed_url
        feed.dt_checked = datetime.datetime(1, 1, 1, 0, 0, 0)
        feed.dt_updated = datetime.datetime(1, 1, 1, 0, 0, 0)
        feed.save()

        return HttpResponse('yay')

#        return HttpResponseRedirect('/admin/reader/feed/%d/' % (feed.id,))
    else:
        return 'h4axx0r..'
开发者ID:peppelorum,项目名称:kod100,代码行数:29,代码来源:views.py

示例12: create_photo_feed

def create_photo_feed(feed_type, photo, photowalk=1):
    user = photo.user
    feed = Feed(photo=photo, user=user, feed_type=feed_type)
    if feed_type is 'photowalk':
        feed.photowalk = photowalk
    feed.save()
    for stalker in followers(user):
        wall = UserWall.objects.get(user=stalker)
        wall.feeds.add(feed)
        wall.save()
    return
开发者ID:exeperience,项目名称:photowalkrs,代码行数:11,代码来源:functions.py

示例13: setup_database

def setup_database(db_file_path=settings.DB_FILE_PATH):
    """
        Connect the database.

        Create the database tables if they don't exists already.
    """
    # import models here to avoid circular references
    from models import BaseModel, Feed, FeedItem

    BaseModel.db.connect()

    Feed.create_table()
    FeedItem.create_table()
开发者ID:ksamuel,项目名称:RSS-Worm,代码行数:13,代码来源:__init__.py

示例14: feed_create

def feed_create():
    """List all examples"""
    form = FeedCreate(request.form)
    if not form.validate():
        return jsonify(status='error', message='The passed arguments failed validation')

    existing_feeds = Feed.for_user_and_url(user=g.user, feed_url=form.data['feed_url'])
    if existing_feeds.count():
        feed = existing_feeds.get()
    else:
        feed = Feed.create_feed_from_form(g.user, form).get_result()

    return jsonify(status='ok', data=feed.to_json())
开发者ID:berg,项目名称:pourover,代码行数:13,代码来源:views.py

示例15: add_feed

def add_feed(url=None):
  
    # Get url submitted via AJAX
    url = request.json['url']

    FEED_TYPES = ('application/rss+xml',
                  'text/xml',
                  'application/atom+xml',
                  'application/x.atom+xml',
                  'application/x-atom+xml')

    # Check if url already exists in feed DB
    dupe = Feed.select().where(Feed.url == url).count()
    if dupe > 0:
        return jsonify(**DUPLICATE_FEED)

    # Attempt to retrieve URL
    try:
        r = requests.get(url, timeout=5)
    except requests.exceptions.Timeout:
        return jsonify(**FEED_NOT_FOUND)

    # check request status code
    if r.status_code != requests.codes.ok:
        return jsonify(**FEED_NOT_FOUND)

    # Get Content-Type
    contenttype = r.headers['content-type']

    # If Content-type is RSS, add it directly
    if contenttype in FEED_TYPES:
        feed = Feed.create(url=url)
        return jsonify(**STATUS_OK)
    
    # If Content-type is HTML, pass to autodiscovery
    if contenttype == 'text/html':

        p = autodiscovery.Discover()
        p.feed(r.text)

        # check result in case of no feeds found
        if len(p.feeds) == 0:
            return jsonify(**FEED_NOT_FOUND)
        else:
            # TODO: Could loop over all available feeds found?
            fulluri = p.feeds[0]['fulluri'] # just adds first feed found
            feed = Feed.create(url=fulluri)
            return jsonify(**STATUS_OK)

    # dropped through to here, feed must be invalid
    return jsonify(**FEED_INVALID)
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:51,代码来源:views.py


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