Esempio n. 1
0
def new_user():
    form = NewUserForm()

    if form.validate_on_submit():
        for user in form.username.data.split(","):
            username = user.strip()
            db_user = User.add_user(username)
            Tweet.add_user_tweets(db_user)
            train()
            print(f"done with {user.strip()}")
            print("\n")
        return redirect(f'/user/{db_user.username}')
    return render_template('user/add.html', form=form)
def handle_tweets():
    '''Returns all tweets as JSON objects in an array with a GET
    request.
    '''
    if request.method == 'GET':
        arr = []
        for tweet in Tweet.select():
            arr.append(tweet.to_hash())
        return jsonify(arr), 200

    elif request.method == 'POST':
        params = request.values
        tweet = Tweet()

        for key in params:
            setattr(tweet, key, params.get(key))
        tweet.save()
        return jsonify(tweet.to_hash()), 200
Esempio n. 3
0
 def _to_json(self, object_record: dict) -> Tweet:
     tweet_model = Tweet(object_record['name'])
     return tweet_model
Esempio n. 4
0
 def find_by_id(self, tweet_id):
     json = self._mongo_database.get(self.collection, tweet_id)
     tweet_model = Tweet('')
     tweet_model.from_json(json)
     return tweet_model
Esempio n. 5
0
    max = db.session.query(func.max(Tweet.id)).scalar()

    for line in f:
        line = line[:-1]  # remove \n
        parts = line.split('\t')

        if int(parts[0]) <= max:
            continue

        t = Tweet(id=int(parts[0]),
                  sentiment=parts[1],
                  topic_id=(None if parts[2] == 'None' else int(parts[2])),
                  country=parts[3],
                  gender=parts[4],
                  urls=parts[5],
                  text=parts[6],
                  user_id=(int(parts[7]) if parts[7] != '' else None),
                  user_name=parts[8],
                  date=(parser.parse(parts[9]) if parts[9] != '' else None),
                  hashtags=parts[10],
                  indication=parts[11],
                  cleaned_text=parts[12],
                  vector=[float(x) for x in parts[13][1:-1].split(', ')])
        db.session.add(t)

        if i % 1000 == 0:
            db.session.commit()
    f.close()
    db.session.commit()
Esempio n. 6
0
 def on_status(self, status):
     print(status.text)
     tweet = Tweet(status.text)
     db.session.add(tweet)
     db.session.commit()