Example #1
0
 def read(subsubscription, nb=0):
     """
     Parse recursively through the categories and sub-categories.
     """
     for subscription in subsubscription:
         if len(subscription) != 0:
             nb = read(subscription, nb)
         else:
             try:
                 title = subscription.text
             except:
                 title = ""
             try:
                 description = subscription.description
             except:
                 description = ""
             try:
                 link = subscription.xmlUrl
             except:
                 continue
             if None != Feed.query.filter(Feed.user_id == user.id, Feed.link
                                          == link).first():
                 continue
             try:
                 site_link = subscription.htmlUrl
             except:
                 site_link = ""
             new_feed = Feed(title=title,
                             description=description,
                             link=link,
                             site_link=site_link,
                             enabled=True)
             user.feeds.append(new_feed)
             nb += 1
     return nb
Example #2
0
def populate_db(db):
    role_admin, role_user = db_create(db)
    user1, user2 = [
        User(nickname=name,
             email="*****@*****.**" % name,
             pwdhash=name,
             roles=[role_user],
             activation_key="") for name in ["user1", "user2"]
    ]
    db.session.add(user1)
    db.session.add(user2)
    db.session.commit()

    for user in (user1, user2):
        for feed_name in ['feed1', 'feed2', 'feed3']:
            feed = Feed(link=feed_name,
                        user_id=user.id,
                        title="%r %r" % (user.nickname, feed_name))
            db.session.add(feed)
            db.session.commit()
            for article in ['article1', 'article2', 'article3']:
                entry = "%s %s %s" % (user.nickname, feed.title, article)
                article = Article(entry_id=entry,
                                  link=article,
                                  feed_id=feed.id,
                                  user_id=user.id,
                                  title=entry,
                                  content=article)
                db.session.add(article)
            db.session.commit()

    db.session.commit()
Example #3
0
def add_feed(title, description, link, language, set_id):
    """Add a new feed.
    """
    new_feed = Feed(title=title,
                    description=description,
                    link=link,
                    language=language,
                    set_id=int(set_id))
    db.session.add(new_feed)
    db.session.commit()
Example #4
0
def import_json(nickname, json_content):
    """
    Import an account from a JSON file.
    """
    user = User.query.filter(User.nickname == nickname).first()
    json_account = json.loads(json_content.decode("utf-8"))
    nb_feeds, nb_articles = 0, 0
    # Create feeds:
    for feed in json_account:
        if (None != Feed.query.filter(Feed.user_id == user.id, Feed.link
                                      == feed["link"]).first()):
            continue
        new_feed = Feed(
            title=feed["title"],
            description="",
            link=feed["link"],
            site_link=feed["site_link"],
            created_date=datetime.datetime.fromtimestamp(
                int(feed["created_date"])),
            enabled=feed["enabled"],
        )
        user.feeds.append(new_feed)
        nb_feeds += 1
    db.session.commit()
    # Create articles:
    for feed in json_account:
        user_feed = Feed.query.filter(Feed.user_id == user.id,
                                      Feed.link == feed["link"]).first()
        if None != user_feed:
            for article in feed["articles"]:
                if (None == Article.query.filter(
                        Article.user_id == user.id,
                        Article.feed_id == user_feed.id,
                        Article.link == article["link"],
                ).first()):
                    new_article = Article(
                        entry_id=article["link"],
                        link=article["link"],
                        title=article["title"],
                        content=article["content"],
                        readed=article["readed"],
                        like=article["like"],
                        retrieved_date=datetime.datetime.fromtimestamp(
                            int(article["retrieved_date"])),
                        date=datetime.datetime.fromtimestamp(
                            int(article["date"])),
                        user_id=user.id,
                        feed_id=user_feed.id,
                    )
                    user_feed.articles.append(new_article)
                    nb_articles += 1
    db.session.commit()
    return nb_feeds, nb_articles
Example #5
0
        def on_message(ident, chan, payload):
            global databaseQueue, socketQueue
            if [i for i in payload[:20] if i not in string.printable]:
                # TODO: Can be improved?
                pass
            else:
                payload = "{0}".format(payload)
                data = json.loads(payload)
                del payload
                newFeed = Feed(url=data['url'],
                               daddr=data['daddr'],
                               saddr=data['saddr'],
                               sport=data['sport'],
                               dport=data['dport'],
                               sha512=data['sha512'],
                               md5=data['md5'],
                               longitude=-1,
                               latitude=-1,
                               city=u'',
                               country=u'')

                socketQueue.put(newFeed)
Example #6
0
 def setUp(self):
     Experiment.objects.get_or_create(name="Control", description="1")
     Experiment.objects.get_or_create(name="Exp 2", description="2")
     Experiment.objects.get_or_create(name="Exp 3", description="3")
     Experiment.objects.get_or_create(name="Exp 4", description="4")
     
     self.niwen, created = OTNUser.objects.get_or_create(username="******", email="*****@*****.**", my_email="*****@*****.**")
     self.kwan, created = OTNUser.objects.get_or_create(username="******", email="*****@*****.**", my_email="*****@*****.**")
     self.eunice, created = OTNUser.objects.get_or_create(username="******", email="*****@*****.**", my_email="*****@*****.**")
     
     
     
     f1 = Feed(actor=self.niwen, action=Feed.PAID, params="Bertuccis")
     f1.save()
     f2 = Feed(actor=self.niwen, action=Feed.VISITED, params="Bank of America")
     f2.save()
     f3 = Feed(actor=self.kwan, action=Feed.FEE, params="Anna's")
     f3.save()
     f4 = Feed(actor=self.eunice, action=Feed.PAID, params="Starbucks")
     f4.save()
     f5 = Feed(actor=self.eunice, action=Feed.VISITED, params="Cosi")
     f5.save()