本文整理汇总了Python中models.Feed.select方法的典型用法代码示例。如果您正苦于以下问题:Python Feed.select方法的具体用法?Python Feed.select怎么用?Python Feed.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Feed
的用法示例。
在下文中一共展示了Feed.select方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_feeds
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
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
示例2: get_feeds_for_user
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def get_feeds_for_user(self, user):
q = Feed.select(Feed).join(Subscription).join(User).where(User.id == user.id).distinct().naive()
result = []
for f in q:
# TODO: Change the model defaults in order to clean this up
try:
result.append({
'id' : f.id,
'favicon_id' : f.favicon.id,
'title' : f.title,
'url' : f.url,
'site_url' : f.site_url,
'is_spark' : 0, # TODO: implement this field in the model
'last_updated_on_time': f.last_checked
})
except Favicon.DoesNotExist:
result.append({
'id' : f.id,
'favicon_id' : 0,
'title' : f.title,
'url' : f.url,
'site_url' : f.site_url,
'is_spark' : 0, # TODO: implement this field in the model
'last_updated_on_time': f.last_checked
})
return result
示例3: initialise
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def initialise():
print("initialising...", end=' ')
# Check for existence of SQLite3 database, creating if necessary
if not os.path.exists(DB_FILE):
create_db()
# If feed table is empty, load the default feed set:
if Feed.select().count() == 0:
load_defaults()
示例4: get_feeds_with_counts
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def get_feeds_with_counts(self, enabled = True):
"""Return feeds - defaults to returning enabled feeds only"""
def _merge(i):
r = i.fields()
r.update({'item_count': i.item_count})
return r
result = [i for i in Feed.select().annotate(Item,fn.Count(Item.id).alias('item_count')).where(Feed.enabled == enabled)]
result = map(_merge, result)
return result
示例5: add_feed
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
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)
示例6: loadTree
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def loadTree():
# Declare empty dict of feeds (emulate sparse list)
feeds = {}
# Get categories, number of posts by category
categories = Category.select(Category, fn.Count(Post.id).alias('count')).join(Feed).join(Post).group_by(Category)
# Loop over categories
for c in categories:
# Get feeds by category
f = Feed.select().where(Feed.category == c.id).annotate(Post)
feeds[c.id] = f
return (categories, feeds)
示例7: loadJsonTree
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def loadJsonTree():
# Use collection to build nested list for tree
feeds = defaultdict(list)
# Get categories, number of posts by category
categories = Category.select(Category, fn.Count(Post.id).alias('count')).join(Feed).join(Post).group_by(Category)
# Loop over categories
all_feeds = []
for c in categories:
feeds[c.id] = {'name': c.name, 'id' : c.id, 'count': c.count, 'children' : []}
# Get feeds by category
category_feeds = Feed.select().where(Feed.category == c.id).annotate(Post)
for f in category_feeds:
feeds[c.id]['children'].append({'id': f.id, 'name': f.name, 'count' : f.count, 'url': f.url})
all_feeds.append(feeds[c.id])
return Response(json.dumps(all_feeds), mimetype='application/json')
示例8: rss_spawn
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def rss_spawn(tick=1):
# Connect to database
db.connect()
# Set limit of MAX_REQUESTS simultaneous RSS requests
pool = Pool(MAX_REQUESTS)
# Get list of active Feed ids from database
feed_query = Feed.select().where(Feed.inactive == 0)
# Filter feed_query result list to feeds valid for current tick
feed_query = [f for f in feed_query if (tick/f.refresh) == int(tick/f.refresh)]
# loop over feeds found, spawn rss_worker(feed)
for f in feed_query:
pool.spawn(rss_worker, f)
pool.join()
# Disconnect from database
db.close()
示例9: managefeeds
# 需要导入模块: from models import Feed [as 别名]
# 或者: from models.Feed import select [as 别名]
def managefeeds():
# Get feeds from database along with post numbers
feedlist = Feed.select().order_by('name').annotate(Post)
datestamps = {}
# Set reference timestamp to one week ago
weekago = arrow.utcnow().replace(days=-7)
for f in feedlist:
updated = arrow.get(f.last_checked)
# if feed newer than one week, print date in human format
if updated > weekago:
datestamps[f.id] = updated.humanize()
else:
datestamps[f.id] = updated.format('YYYY-MM-DD HH:mm')
return render_template("managefeeds.html",
datestamps=datestamps,
feedlist=feedlist)