コード例 #1
0
def search_hashtag_by_id(hashtag):
    session = get_session()
    session = session()
    tag_query = session.query(HashTag).filter(HashTag.id == hashtag).all()
    if tag_query:
        session.close()
        return tag_query[0].name
    else:
        session.close()
        return None
コード例 #2
0
def n_tweets_hash(id_hashtag):
    session = get_session()
    session = session()
    tag_query = session.query(TagTweet).filter(
        TagTweet.id_hashtag == id_hashtag).all()
    if tag_query:
        number = len(tag_query)
        return number
    else:
        session.close()
        return 0
コード例 #3
0
def insert_hashtag(hashtag_obj):
    session = get_session()
    session = session()
    new_hashtag = HashTag()
    new_hashtag.name = hashtag_obj.get_name()
    session.add(new_hashtag)
    session.commit()
    session.refresh(new_hashtag)
    hashtag_id = new_hashtag.id
    session.close()
    return hashtag_id
コード例 #4
0
def insert_user(user_obj):
    session = get_session()
    session = session()
    new_user = User()
    new_user.username = user_obj.get_username()
    new_user.id_location = user_obj.get_location()
    session.add(new_user)
    session.commit()
    session.refresh(new_user)
    user_id = new_user.id
    session.close()
    return user_id
コード例 #5
0
def insert_feeling(name):
    session = get_session()
    session = session()
    new_feeling = Feeling()
    print("------------------------------------------", name)
    new_feeling.name = name
    session.add(new_feeling)
    session.commit()
    session.refresh(new_feeling)
    feeling_id = new_feeling.id
    session.close()
    return feeling_id
コード例 #6
0
def insert_relation_tweet_tag(id_hashtag, id_tweet):
    session = get_session()
    session = session()
    new_relation = TagTweet()
    new_relation.id_hashtag = id_hashtag
    new_relation.id_tweet = id_tweet
    session.add(new_relation)
    session.commit()
    session.refresh(new_relation)
    relation_id = new_relation.id
    session.close()
    return relation_id
コード例 #7
0
def n_tweets_feeling(id_feeling, id_hashtag):
    session = get_session()
    session = session()
    feeling_query = session.query(Tweet).filter(
        Tweet.id_feeling == id_feeling).join(TagTweet).filter(
            TagTweet.id_hashtag == id_hashtag).all()
    if feeling_query:
        number = len(feeling_query)
        print(feeling_query)
        return number
    else:
        session.close()
        return 0
コード例 #8
0
def search_user_by_id(id):
    session = get_session()
    session = session()
    user_query = session.query(User).filter(User.id == id).all()
    if user_query:
        user_query = user_query[0]
        user_obj = UserObj(user_query.username)
        user_obj.set_id(user_query.id)
        session.close()
        return user_obj
    else:
        session.close()
        return None
コード例 #9
0
def insert_font(font_obj):
    session = get_session()
    session = session()
    new_font = Font()
    new_font.id_user = font_obj.get_user()
    new_font.url = font_obj.get_url()
    new_font.trust = font_obj.is_reliable()
    session.add(new_font)
    session.commit()
    session.refresh(new_font)
    font_id = new_font.id
    session.close()
    return font_id
コード例 #10
0
def search_feeling(feeling):
    session = get_session()
    session = session()
    feeling_query = session.query(Feeling).filter(
        Feeling.name == feeling).all()
    if feeling_query:
        feeling_query = feeling_query[0]
        n_feeling = feeling_query.name, feeling_query.id
        session.close()
        return n_feeling
    else:
        session.close()
        return None
コード例 #11
0
def insert_location(location_obj):
    session = get_session()
    session = session()
    new_location = Location()
    new_location.name = location_obj.get_name()
    new_location.latitude = location_obj.get_latitude()
    new_location.longitude = location_obj.get_longitude()
    session.add(new_location)
    session.commit()
    session.refresh(new_location)
    location_id = new_location.id
    session.close()
    return location_id
コード例 #12
0
def search_hashtag(hashtag):
    session = get_session()
    session = session()
    tag_query = session.query(HashTag).filter(HashTag.name == hashtag).all()
    if tag_query:
        tag_query = tag_query[0]
        tag_obj = HashTagObj(tag_query.name)
        tag_obj.set_id(tag_query.id)
        session.close()
        return tag_obj
    else:
        session.close()
        return None
コード例 #13
0
def search_location_by_id(id):
    session = get_session()
    session = session()
    location_query = session.query(Location).filter(Location.id == id ).all()
    if location_query:
        location_query = location_query[0]
        location_obj = LocationObj(location_query.name)
        location_obj.set_id(location_query.id)
        location_obj.set_latitude(location_query.latitude)
        location_obj.set_longitude(location_query.longitude)
        session.close()
        return location_obj
    else:
        session.close()
        return None
コード例 #14
0
def search_font(font_obj):
    session = get_session()
    session = session()
    font_query = session.query(Font).filter(
        Font.url == font_obj.get_url()
        or Font.id_user == font_obj.get_user()).all()
    if font_query:
        font_query = font_query[0]
        font_obj = FontObj()
        font_obj.set_id(font_query.id)
        font_obj.set_reliability(font_query.trust)
        font_obj.set_user(font_query.id_user)
        font_obj.set_url(font_query.url)
        session.close()
        return font_obj
    else:
        session.close()
        return None
コード例 #15
0
def insert_tweet(tweet_obj):
    session = get_session()
    session = session()
    new_tweet = Tweet()
    new_tweet.text = tweet_obj.get_text()
    new_tweet.id_user = tweet_obj.get_user()
    new_tweet.id_location = tweet_obj.get_location()
    new_tweet.id_feeling = tweet_obj.get_feeling()
    new_tweet.id_font = tweet_obj.get_font()
    new_tweet.id_hashtag = tweet_obj.get_hashtag()
    new_tweet.n_likes = tweet_obj.number_likes()
    new_tweet.n_reply = tweet_obj.number_reply()
    new_tweet.n_retweets = tweet_obj.number_retweet()
    new_tweet.data = tweet_obj.get_data()
    new_tweet.fake = tweet_obj.is_reliable()
    session.add(new_tweet)
    session.commit()
    session.refresh(new_tweet)
    tweet_id = new_tweet.id
    session.close()
    return tweet_id