Beispiel #1
0
def get_feedlist_for_user(user_id):
  subs = Subscription.get_by_user(user_id)

  feedlist = [Feed.get_by_id(sub.feed_id) for sub in subs]
  state = 'ok'

  return { 'state': state, 'feedlist': feedlist }
Beispiel #2
0
def send_feed(uid: int, top: bool, content: str) -> int:
    """
    发送feed,返回feed_id
    """
    feed = Feed(uid=uid, content=content, top=top)
    db.session.add(feed)
    db.session.commit()
    return feed.id
Beispiel #3
0
def add_message():
    ref = request.referrer
    form = FeedPostForm()

    formModalMessage = PrivateMessageForm()

    if form.validate_on_submit():

        fromUser = User.objects.get(username=session.get('username'))
        fetchNotifications(fromUser)
        toUser = User.objects.get(username=request.values.get('toUser'))

        image = None

        if request.files.get('image'):
            filename = secure_filename(form.image.data.filename)
            file_path = "images/posts/" + str(uuid.uuid4()) + filename
            file_pathB = "static/" + file_path
            form.image.data.save(file_pathB)
            image = str(file_path)
            print(image)
            print("Image gotten")

        print("AfterImage")
        print(image)
        post = form.post.data

        if toUser == fromUser:
            toUser = None

        message = Message(
            fromUser=fromUser,
            toUser=toUser,
            text=post,
            messageType=POST,
        ).save()

        feed = Feed(user=fromUser, message=message).save()

        if image:
            message.image = image
            message.save()

        process_message(message)

        if ref:
            return redirect(ref)
        else:
            return redirect(url_for('home_app.home'))

    else:
        return 'Error!'
Beispiel #4
0
def process_message(message):

    fromUser = message.fromUser
    friends = Relationship.objects.filter(fromUser=fromUser,
                                          rel_type=Relationship.FRIENDS,
                                          status=Relationship.APPROVED)

    for friend in friends:

        rel = Relationship.get_relationship(friend.toUser, message.toUser)
        if rel != "BLOCKED":
            feed = Feed(user=friend.toUser, message=message).save()

    return True
Beispiel #5
0
def subscribe_imported_feeds(user_id, items):
  """
  [item${i}: {
    'title': ${title},
    'url': ${url}
    'link': ${link}
    'category': []
  }]
  return: [newly subscribed feeds]
  """
  state = 'ok'
  feedlist = []
  for item in items:
    feed, feed_exist = Feed.get_or_create(item['url'], item['title'], item['link'])
    sub, sub_exist = Subscription.get_or_create(user_id, feed.feed_id)
    if not sub_exist: feedlist.append(feed)
  return { 'state': state, 'feedlist': feedlist }
  def fetch_feed(self, feed_id):
    feed = Feed.get_by_id(feed_id)
    if not feed: return

    url = ('https://www.google.com/reader/public/atom/feed/%s?n=%d' % 
        (feed.feed_address, self.max_n))
    try:
      fetched_feed = feedparser.parse(url)
  
      FetchedFeed(feed_id).save()
      
      pfeed = ProcessFeed(feed, fetched_feed, {});

      ret, feed = pfeed.process()

      jug.publish('import:google-reader-history', {'state':'ok', 'feed_id': feed_id })
    except Exception, e:
      print e
      jug.publish('import:google-reader-history', {'state':'error', 'feed_id':feed_id})
Beispiel #7
0
def subscribe(user_id, url):
  """
  subscribe a feed with address: url

  return: @state 'ok'/'network error'/'duplication'
          @feed feed information
          @articles latested articles
  """
  state = 'ok'
  url = urlnorm.normalize(url)
  if not feedfinder.isFeed(url):
    return {'state': 'invalid feed url'}

  feed, feed_exist = Feed.get_or_create(url)
  
  sub, sub_exist = Subscription.get_or_create(user_id, feed.feed_id)

  if sub_exist:
    state = 'duplication'
    return {'state': state}

  return { 'state': state, 'feed': feed, 'stories': get_stories_for_feed(feed.feed_id) }
Beispiel #8
0
    url = urlnorm.normalize(url)
    if True or feedfinder.isFeed(url):
      fetch(url, n, output_path, options)
    else:
      print '%s is not a feed url' % url

if __name__ == '__main__':
  from optparse import OptionParser
  parser = OptionParser()
  parser.add_option('-f', '--file', dest='filename', default='db', help='the file contains feed urls, or [db] to get feed urls from database', metavar='FILE')
  parser.add_option('-n', dest='n', help='number of stories to fetch', type='int', default=99999)
  parser.add_option('-o', '--output-path', dest='output_path', default='feed_data', help='output path', metavar='FILE')
  parser.add_option('-q', '--quite', dest='quite', action='store_true', default=False, help='turn off log')

  (options, args) = parser.parse_args()

  if os.path.exists(options.output_path):
    if options.filename == 'db':
      from models.feed import Feed
      urls = [feed.feed_address for feed in  Feed.get_all_feeds()]
    else: 
      try:
        urls = open(options.filename).readlines()
      except Exception, e:
        print e
        urls = []
    fetch_feeds(urls, options.n, options.output_path, {'quite':options.quite})
  else:
    print 'output path not exists'

Beispiel #9
0
def refresh_feeds(options):
  from models.feed import Feed
  feeds = Feed.get_all()
  for feed in feeds: feed.update(force=True) 
Beispiel #10
0
def main():
    result = Feed(fetch_feed())

    db = Sqlite3()
    db.create_table()
    db.insert_records([item.get_as_record() for item in result.get_entries()])
Beispiel #11
0
 def _create_feed_from_config(self, feed_config):
     """
 Private: create a Feed from a dictionary of values
 """
     return Feed.build(feed_config)
Beispiel #12
0
 def _create_feed_from_config(self, feed_config):
     '''
 Private: create a Feed from a dictionary of values
 '''
     return Feed.build(feed_config)