예제 #1
0
 def post(self):
     from libs.feedparser import parse
     user = users.get_current_user()
     url = self.request.get('url')
     p = parse(str(url))
     try:
         d = p['items'][0]
     except IndexError:
         pass
     if user:
         q = Feeds.query(Feeds.user == user, Feeds.url == url)
         if q.get() is None:
             feed = Feeds()
             def txn():
                 feed.blog = p.feed.title
                 feed.root = p.feed.link
                 feed.user = user
                 feed.feed = url
                 feed.url = d.link
                 feed.put()
             ndb.transaction(txn)
             deferred.defer(utils.new_bm, d, feed.key, _queue="admin")
         self.redirect(self.request.referer)
     else:
         self.redirect('/')
예제 #2
0
파일: load_data.py 프로젝트: foxmask/smcomm
def feeds_to_track():
    with open("smcomm.json") as feeds:
        for line in feeds:
            data = json.loads(line)
            print("Importing data {}".format(data))
            Feeds.create(
                site_name=data["site_name"],
                site_url=data["site_url"],
                feed_url=data["feed_url"],
                date_triggered=datetime.now(tz=None),
                active=True,
                uuid=set_uuid(),
            )
예제 #3
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     tag  = Tags.get_by_id(int(self.request.get('tag')))
     if users.get_current_user() == feed.user:
         feed.tags.remove(tag.key)
         feed.put()
     self.redirect(self.request.referer) 
예제 #4
0
def index(request):
    if request.session.session_key:
        current_user = request.user
        if current_user.is_authenticated():
            if request.method == 'POST':
                form = NewFeedForm(request.POST)
                if form.is_valid():
                    content = form.cleaned_data['content']
                    feed = Feeds(user=request.user,
                                 content=content,
                                 creat_time=datetime.datetime.now()).save()
                    return HttpResponseRedirect('/')

            else:
                form = NewFeedForm()
                return render_to_response(
                    'accounts/broadcast.html', {
                        'form': form,
                        'current_user': current_user,
                        'STATIC_URL': STATIC_URL
                    },
                    context_instance=RequestContext(request))
        # 这里应该还有个else,来处理有sessiondata但是已经注销了的情况
        else:
            if request.method == 'POST':
                if 'login' in request.POST:
                    return indexlogin(request)
                elif 'signup' in request.POST:
                    return indexsignup(request)

            else:
                form_login = AccountsLoginForm()
                form_signup = AccountsSignupForm()
                return render_to_response(
                    'index.html', {
                        'form_login': form_login,
                        'form_signup': form_signup,
                        'STATIC_URL': STATIC_URL
                    },
                    context_instance=RequestContext(request))

    else:
        if request.method == 'POST':
            if 'login' in request.POST:
                return indexlogin(request)
            elif 'signup' in request.POST:
                print 'signup'
                return indexsignup(request)

        else:
            form_login = AccountsLoginForm()
            form_signup = AccountsSignupForm()
            return render_to_response('index.html', {
                'form_login': form_login,
                'form_signup': form_signup,
                'STATIC_URL': STATIC_URL
            },
                                      context_instance=RequestContext(request))
예제 #5
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     tag  = Tags.get_by_id(int(self.request.get('tag')))
     if users.get_current_user() == feed.user:
         if tag in feed.tags:
             pass
         else:
             feed.tags.append(tag.key)
             feed.put()
     self.redirect(self.request.referer)
예제 #6
0
def create_feeds():

    try:
        if not request.json:
            abort(400)
        else:
            feeds = Feeds(request.json['title'], request.json['author'],
                          request.json['message'], request.json['lg_id'],
                          int(time.time()), request.json['type'])
            session.add(feeds)
            session.commit()

            result = feeds.serialize()

            if 'recipients' in request.json:
                session.refresh(feeds)
                recipient = Recipient(request.json['recipients'], feeds.id)
                session.add(recipient)
                session.commit()
                result.update({'recipients': recipient.recipients})

            if 'no_of_likes' in request.json:
                session.refresh(feeds)
                likes = Likes(feeds.id, request.json['no_of_likes'])
                session.add(likes)
                session.commit()
                result.update({'no_of_likes': likes.no_of_likes})

                # return jsonify({
                # 		"id": feeds.id,
                # 		"title": feeds.title,
                # 		"author": feeds.author,
                # 		"message": feeds.message,
                # 		"lg_id": feeds.lg_id,
                # 		"datetime": time.strftime('%d-%m-%Y %H:%M', time.localtime(feeds.datetime)),
                # 		"type": feeds.type,
                # 		"no_of_likes": likes.no_of_likes
                # 	})

            return jsonify(result)

    except Exception as e:
        return (str(e))
예제 #7
0
    def processFeedItem(self, item):
        """
        adds news item to feeds table
        :param item:
        :return:
        """

        fdItem = Feeds(**item)
        self.processDBentry(fdItem)
        return item
예제 #8
0
def create_articles():
    """
        create one article (a file in fact) for each
        feed we get
    """
    my_date = datetime.strftime(datetime.now(), '%Y%m%d')
    my_hour = datetime.strftime(datetime.now(), '%H%M')

    for feed in Feeds.select().where(Feeds.active == True):

        # Set the date if we never grab the data before
        # date_triggered = datetime.strpftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
        date_triggered = datetime.now(tz=None)
        # if feed has aleady been read before get its date
        if feed.date_triggered != '':
            # date_triggered = arrow.get(str(feed.date_triggered), 'YYYY-MM-DD HH:mm:ss')
            date_triggered = datetime.strptime(feed.date_triggered, '%Y-%m-%d %H:%M:%S.%f')

        # get the data from the feed and get them only if the date triggered >= of the feed date
        for data in get_data(feed.feed_url):

            if to_publish(data, date_triggered):

                # set the name of the file
                feed_name = feed.site_name.replace('&', 'Et').replace(' ', '_')
                # set the path of the folder where to store the article
                feed_folder = FEEDS_FOLDER + feed_name
                # cleaning the special char
                title = data.title.replace('/', '_').replace('\\', '_').replace(' ', '_').replace(':', '_').replace('&', '').replace('?', '').replace('!', '')
                filename = "{}/{}.html".format(feed_folder, title)
                print("processing {}".format(title))
                title = get_title(data.title)
                header = get_header(feed.site_name, data)
                content = get_content(data)
                footer = get_footer(feed)
                try:
                    with open(filename, 'w') as f:
                        f.write(get_beginpage())
                        f.write(title)
                        f.write(header)
                        f.write(content)
                        f.write(footer)
                        f.write(get_endpage())
                    # update the date of the trigger at each creation of article file
                    # thus, if an error occurs, we could launch the script again
                    # and start where we failed and avoid duplicate creation of article
                    feed.date_triggered = datetime.now(tz=None)
                    feed.save()

                except Exception as e:
                    raise e
예제 #9
0
파일: submit.py 프로젝트: russomi/gaeicious
 def post(self):
     user = users.get_current_user()
     feed = self.request.get('url')
     q = Feeds.query(Feeds.user == user, Feeds.feed == feed)
     if user and q.get() == None:
         d = parse(str(feed))
         feed_k = Feeds(feed=feed,
                        title=d['channel']['title'],
                        link=d['channel']['link'],
                        user=user,
                        last_id=d['items'][0].id).put()
         deferred.defer(pop_feed, feed_k, _queue="user")
         self.redirect('/feeds')
     else:
         self.redirect('/')
예제 #10
0
파일: submit.py 프로젝트: russomi/gaeicious
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('id')))
     feed.key.delete()
     self.redirect(self.request.referer)
예제 #11
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     deferred.defer(utils.pop_feed, feed.key, _queue="admin")
예제 #12
0
 def get(self): 
     for feed in Feeds.query(): 
         if feed.notify == 'digest': 
             deferred.defer(utils.feed_digest, feed.key, _target="worker", _queue="admin")
예제 #13
0
 def get(self): 
     for feed in Feeds.query(): 
         deferred.defer(utils.pop_feed, feed.key, _target="worker", _queue="admin")
예제 #14
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     template = jinja_environment.get_template('gettagsfeed.html') 
     values = {'feed': feed} 
     other_tags = template.render(values)
     self.response.write(other_tags)
예제 #15
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     feed.notify = self.request.get('notify')
     feed.put()
예제 #16
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     feed.notify = self.request.get('notify')
     feed.put()
예제 #17
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('feed')))
     template = jinja_environment.get_template('gettagsfeed.html')
     values = {'feed': feed}
     other_tags = template.render(values)
     self.response.write(other_tags)
예제 #18
0
 def get(self):
     feed = Feeds.get_by_id(int(self.request.get('id')))
     feed.key.delete()