• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Feed类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_check_feed_with_probem

    def test_check_feed_with_probem(self):
        last_checked = datetime(2000, 1, 1)
        date_of_last_entry = datetime(2000, 1, 1)
        feed_url = 'http://x.y.z'
        feed = Feed(name = "Test Feed",
                    last_checked = last_checked,
                    date_of_last_entry = date_of_last_entry,
                    url = feed_url,
                    parent = root_key())
        feed.put()

        # Replace feedparser.parse with our own version that sets the status
        # code to 500 to simulate a server side error
        def _parse(url):
            parsed_feed = FeedParserDict(status = 500, bozo = False)
            return parsed_feed
        feedparser.parse = _parse

        reported_title = [0]
        reported_message = [0]
        reported_recipient = [0]
        orig_report_error = feed_utils.report_error
        def _report_error(title, message, recipent_address):
            reported_title[0] = title
            reported_message[0] = message
            reported_recipient[0] = recipent_address
            orig_report_error(title, message, recipent_address)
        feed_utils.report_error = _report_error

        # run the method under test
        # set logging to CRITICAL so-as not to print exception generated by
        # the test
        try:
            logging.getLogger().setLevel(logging.CRITICAL)
            response = self.testapp.get('/check_feeds')
            self.assertEquals(reported_title[0], feed.name)
            self.assertTrue('returned HTTP code 500' in reported_message[0])
            self.assertEquals(reported_recipient[0], '[email protected]')
            #self.fail("Should have raised an exception as server returned 500")
        finally:
            logging.getLogger().setLevel(logging.ERROR)

        # there should be one email message describing the problem
        messages = self.mail_stub.get_sent_messages()
        self.assertEquals(1, len(messages))
        self.assertTrue("URL '%s' returned HTTP code 500" % feed_url in
            messages[0].body.payload)

        # check the feed's last_checked date was updated
        self.assertNotEqual(feed.last_checked, last_checked)
开发者ID:adrian,项目名称:feed2me,代码行数:50,代码来源:test_check_feeds_handler.py


示例17: api_feed

def api_feed(request):
    api_result = {"api": "feed", "status": "success"}

    try:
        token = request.GET["token"]
        user = get_user_from_token(token)
        group_id = 0
        try:
            group_id = request.GET["group_id"]
        except:
            pass

        page = 1
        try:
            page = int(request.GET["page"])
        except:
            pass

        page_size = 10
        try:
            page_size = int(request.GET["page_size"])
        except:
            pass

        if not user:
            api_result["status"] = "failure"
            api_result["error"] = "user not found"
        else:
            if group_id == 0:
                polls = Feed.user_feed(user, page, page_size)
            else:
                polls = Feed.group_feed(user, group_id, page, page_size)

            if page == 1 and not polls:
                # create_feed_new_user(user)
                # polls = Feed.user_feed(user, page, page_size)
                pass

            if polls:
                api_result["polls"] = json_polls(polls)
            else:
                api_result["polls"] = "None"
    except Exception as e:
        api_result["status"] = "failure"
        api_result["error"] = e.message
        pass

    return JsonResponse(api_result)
开发者ID:krdeepak,项目名称:djmysite,代码行数:48,代码来源:views.py


示例18: post_all_feeds

def post_all_feeds():
    """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'))

    feeds = Feed.query().iter()

    errors = 0
    success = 0
    num_posted = 0
    futures = []

    while (yield feeds.has_next_async()):
        feed = feeds.next()
        futures.append((feed, Entry.publish_for_feed(feed)))

    for feed, future in futures:
        try:
            num_posts = yield future
            if num_posts is not None:
                num_posted += num_posts
            success += 1
        except:
            errors += 1
            logger.exception('Failed to Publish feed:%s' % (feed.feed_url, ))

    logger.info('Post Feeds success:%s errors: %s num_posted: %s', success, errors, num_posted)

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


示例19: feed_register

def feed_register (feed_url, user_id):
    feed_new = False
    
    #app.logger.info ("RSS LINK = " + feed_url) 
    feed = dboper.get_feed_by_rsslink(feed_url) #Check if it's already in the central repository
    if not feed:      ## New feed in the repository  
        feed_new = True                
        d = Feed.parse(feed_url)
        #app.logger.info(d.feed)
        if 'image' in d.feed:
            imgurl = d.feed.image.href
        else:
            imgurl = None
            
        if 'link' in d.feed:
            sitelink = d.feed.link
        else:
            sitelink = None
            
        feed = Feed (name=d.feed.title, rsslink=feed_url, image_url=imgurl,  sitelink=sitelink)
        dboper.add_feed(feed)                           #Add new feed to the repository (if not exist)
        #app.logger.info("NEW FEED: " + feed.name)  
    
    dboper.add_user_feed_by_id(user_id, feed)   #By user_id and not g.user because g object is lost in another thread
    #app.logger.info("ADDING NEW USER FEED: " + feed.name)  
    #if feed_new:                                    #If completely new, load articles 
    app.logger.info("LOADING ARTICLES " )  
    n = dboper.load_new_user_articles(feed, user_id)
    app.logger.info("Fetched: " + str(n))
开发者ID:ifer,项目名称:conread,代码行数:29,代码来源:views.py


示例20: feed_update

def feed_update(id=None):

    # Manual update of one or all feeds now
    if request.json['action'] == 'refresh':
        
        # Call refresh routine
        # TODO: RSS worker functions in separate package
        # TODO: Need to capture return status
        if id is None:
            rss_spawn() # Update all feeds
        else:
            try:
                feed = Feed.get(Feed.id == id)
            except Feed.DoesNotExist:
                return jsonify(**FEED_NOT_FOUND)

            rss_worker(feed) # Update single feed
        
        # return JSON status OK
        return jsonify(**STATUS_OK)

    # Mark one or all feeds read
    elif request.json['action'] == 'markread':

        if id is None:
            # Mark all posts read
            query = Post.update(is_read=True)
        else:
            # Mark posts in current feed read
            query = Post.update(is_read=True).where(Feed.id == id)
            
        query.execute()
            
    # return JSON status OK
        return jsonify(**STATUS_OK)
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:35,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Feedback类代码示例发布时间:2022-05-27
下一篇:
Python models.FeaturedArtwork类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap