Exemplo n.º 1
0
def render_page_content():
	content = dict()
	db = MyDB()
	
	content['login'] = tools.get_user_info()
	content['movies'] = db.get_movies()
	
	return render_template('homepage.html', content=content)
Exemplo n.º 2
0
def compute_following(neo4j_connector, twitter_connector, min_followers,
                      min_tweets, max_twitter_users):
    """
    Compute interactions
    :param neo4j_connector:
    :param twitter_connector:
    :param min_followers:
    :param min_tweets:
    :param max_twitter_users:
    :return:
    """
    # Current list of users
    current_nodes = list(neo4j_connector.users)
    shuffle(current_nodes)

    # For each root user
    for index, user in enumerate(current_nodes):
        # Log
        print(u"On {}".format(user.get('screen_name')))

        # Try
        try:
            # Get twitter user
            twitter_user = twitter_connector.get_user(user.get('screen_name'))

            # Each follower
            for page in twitter_connector.get_followers(twitter_user):
                for follower in page:
                    # Properties
                    author_name, n_followers, n_tweets, author_url, author_country = tools.get_user_info(
                        follower)

                    # Add if not exists
                    if n_followers >= min_followers and n_tweets >= min_tweets:
                        follower_node = neo4j_connector.add_user_node(
                            screen_name=author_name,
                            followers_count=n_followers,
                            statuses_count=n_tweets,
                            url=author_url,
                            localisation=author_country)

                        # Relationship
                        neo4j_connector.follow_relationship(
                            user, follower_node)
                    # end if
                # end for
            # end for
        except tweepy.error.TweepError as e:
            print(e)
            pass
        # end try

        # Log
        print(u"Done with {}".format(user.get('screen_name')))
Exemplo n.º 3
0
def render_page_content(movie_id):
	content = dict()
	db = MyDB()

	content['login'] = tools.get_user_info()	
	content['id'] = movie_id
	
	movie = db.get_movie_by_id( movie_id )

	content['title'] = movie['title']
	content['actors'] = movie['actors']
	content['description'] = movie['description']
	content['price'] = str(movie['price'])[:-2] + '.' + str(movie['price'])[-2:]
	content['reviews'] = db.get_reviews_by_id( movie_id )

	return render_template('movie.html', content=content)
Exemplo n.º 4
0
def render_page_content():
	content = dict()
	db = MyDB()

	content['login'] = tools.get_user_info()
	content['records'] = list()
	content['username'] = content['login']['username']

	users = db.get_users()
	if users == None:
		users = []

	for entry in users:
		item = dict()
		item['id'] = entry['user_id']
		item['username'] = entry['username']
		item['password'] = entry['password']
		item['isAdmin'] = "Yes" if entry['isAdmin'] else "No"
		content['records'].append(item)


	return render_template('admin.html', content=content)
Exemplo n.º 5
0
def render_page_content(cart_id, confirm):
	content = dict()
	db = MyDB()

	content['login'] = tools.get_user_info()
	content['confirm'] = confirm
	content['records'] = list()
	
	total = 0

	cart = db.get_cart(cart_id)
	if cart == None:
		cart = []

	for entry in cart:
		item = dict()
		item['id'] = entry['movie_id']
		item['title'] = entry['title']
		item['actors'] = entry['actors']
		item['quantity'] = entry['quantity']

		price = entry['price']
		subtotal = price * entry['quantity']

		item['price'] = str(price)[:-2] + '.' + str(price)[-2:]
		item['subtotal'] = str(subtotal)[:-2] + '.' + str(subtotal)[-2:]

		total = total + subtotal
		content['records'].append(item)

	total = str(total)
	content['total'] = str(total)[:-2] + '.' + str(total)[-2:]

	content['username'] = db.get_username_by_id(cart_id)

	return render_template('cart.html', content=content)
Exemplo n.º 6
0
def compute_interactions(neo4j_connector,
                         twitter_connector,
                         min_followers,
                         min_tweets,
                         depth=-1,
                         retweets=False,
                         tweets=False,
                         quotes=False,
                         hashtags=False,
                         root_users=None):
    """
    Compute interactions
    :param neo4j_connector:
    :param twitter_connector:
    :param min_followers:
    :param min_tweets:
    :param depth:
    :param retweets:
    :param tweets:
    :param quotes:
    :param hashtags:
    :param root_users:
    :return:
    """
    # Current list of users
    if root_users is None:
        current_nodes = list(neo4j_connector.users)
        shuffle(current_nodes)
    else:
        current_nodes = root_users
    # end if

    # For each user
    for index, user in enumerate(current_nodes):
        try:
            # Log
            print(u"On {}".format(user.get('screen_name')))

            # Last tweet id
            last_tweet_id = 0

            # Author node
            author_node = neo4j_connector.get_user_node(
                user.get('screen_name'))

            # For each page
            for page_index, page in enumerate(
                    twitter_connector.get_user_timeline(
                        screen_name=user.get('screen_name'))):
                stop = False
                # For each tweet
                for tweet in page:
                    # Stop if already computed
                    if tweet.id <= user.get('last_tweet_id'):
                        stop = True
                        break
                    # end if

                    # Only retweet
                    if hasattr(tweet, 'retweeted_status') and retweets:
                        # Target user
                        target_twitter_user = tweet.retweeted_status.author

                        # Properties
                        author_name, n_followers, n_tweets, author_url, author_country = tools.get_user_info(
                            target_twitter_user)

                        # Add if not exists
                        if n_followers >= min_followers and n_tweets >= min_tweets and author_name != user.get(
                                'screen_name'):
                            target_user = neo4j_connector.add_user_node(
                                screen_name=author_name,
                                followers_count=n_followers,
                                statuses_count=n_tweets,
                                url=author_url,
                                localisation=author_country)

                            # Relationship
                            if target_user is not None:
                                neo4j_connector.retweet_relationship(
                                    author_node, target_user)
                            # end if
                        # end if
                    else:
                        # For each retweets
                        if retweets:
                            # Get retweets
                            tweet_retweets = twitter_connector.get_retweets(
                                tweet)

                            # If there is retweets
                            if len(tweet_retweets) > 0:
                                # For each retweets
                                for retweet in tweet_retweets:
                                    # Target user
                                    target_twitter_user = retweet.author

                                    # Properties
                                    author_name, n_followers, n_tweets, author_url, author_country = tools.get_user_info(
                                        target_twitter_user)

                                    # Add if not exists
                                    if n_followers >= min_followers and n_tweets >= min_tweets and author_name != user.get(
                                            'screen_name'):
                                        target_user = neo4j_connector.add_user_node(
                                            screen_name=author_name,
                                            followers_count=n_followers,
                                            statuses_count=n_tweets,
                                            url=author_url,
                                            localisation=author_country)

                                        # Relationship
                                        if target_user is not None:
                                            neo4j_connector.retweet_relationship(
                                                target_user, author_node)
                                        # end if
                                    # end if
                                # end for
                            # end if
                        # end if

                        # For each quoted URL
                        if tweets:
                            for url in tweet.entities['urls']:
                                # Add web site
                                website_node = neo4j_connector.add_web_site(
                                    url['expanded_url'])

                                # Add TWEETED relationship
                                if website_node is not None:
                                    neo4j_connector.tweeted_relationship(
                                        author_node, website_node)
                                # end if
                            # end for
                        # end if

                        # For each quoted users
                        if quotes:
                            for quoted_user_info in tweet.entities[
                                    'user_mentions']:
                                # Twitter user
                                quoted_twitter_user = twitter_connector.get_user(
                                    quoted_user_info['screen_name'])

                                # Properties
                                author_name, n_followers, n_tweets, author_url, author_country = tools.get_user_info(
                                    quoted_twitter_user)

                                # Add if not exists
                                if n_followers >= min_followers and n_tweets >= min_tweets and author_name != user.get(
                                        'screen_name'):
                                    quoted_user_node = neo4j_connector.add_user_node(
                                        screen_name=author_name,
                                        followers_count=n_followers,
                                        statuses_count=n_tweets,
                                        url=author_url,
                                        localisation=author_country)

                                    # Relationship
                                    if quoted_user_node is not None:
                                        neo4j_connector.quoted_relationship(
                                            author_node, quoted_user_node)
                                    # end if
                                # end if
                            # end for
                        # end if

                        # For each quoted hashtags
                        if hashtags:
                            for quoted_hashtag_info in tweet.entities[
                                    'hashtags']:
                                # Hashtag text
                                hashtag_text = '#' + quoted_hashtag_info['text']

                                # Add if not exists
                                quoted_hashtag_node = neo4j_connector.add_hashtag_node(
                                    hashtag_text=hashtag_text)

                                # Relationship
                                neo4j_connector.hashtaged_relationship(
                                    author_node, quoted_hashtag_node)
                            # end for

                            # Links between hashtags
                            for hashtag1_info in tweet.entities['hashtags']:
                                # Other hashtag text
                                hashtag1_text = '#' + hashtag1_info['text']

                                # Add if not exists
                                hashtag1_node = neo4j_connector.add_hashtag_node(
                                    hashtag_text=hashtag1_text)

                                # Other hashtag
                                for hashtag2_info in tweet.entities[
                                        'hashtags']:
                                    # Other hashtag text
                                    hashtag2_text = '#' + hashtag2_info['text']

                                    # Add if not exists
                                    hashtag2_node = neo4j_connector.add_hashtag_node(
                                        hashtag_text=hashtag2_text)

                                    # Different
                                    if hashtag1_text != hashtag2_text:
                                        # Linked
                                        neo4j_connector.linked_relationship(
                                            hashtag1_node, hashtag2_node)
                                    # end if
                                # end for
                            # end for
                        # end if
                    # end if

                    # Remember limit
                    if tweet.id > last_tweet_id:
                        last_tweet_id = tweet.id
                    # end if
                # end for

                # Depth
                if depth != -1 and page_index >= depth:
                    stop = True
                # end if

                # Stop?
                if stop:
                    break
                # end if
            # end for

            # Log
            print(u"Done with {}".format(user.get('screen_name')))

            # Remember limit
            if last_tweet_id != 0:
                user.set('last_tweet_id', last_tweet_id)
            # end if
        except tweepy.error.TweepError as e:
            print(u"Tweepy error {}".format(e))
            pass
        except neo4jrestclient.exceptions as e:
            print(u"Neo4j error {}".format(e))
            pass
        except neo4jrestclient.exceptions.NotFoundError as e:
            print(u"Neo4j error {}".format(e))
            pass
Exemplo n.º 7
0
    # Load roots
    root_user_nodes = None
    if args.root_users != "":
        root_users = tools.root_file(args.root_users)
    else:
        root_users = None
    # end if

    # Add all root users
    if root_users is not None:
        root_user_nodes = list()
        for root_user in root_users:
            try:
                user = twitter_connector.get_user(screen_name=root_user)
                root_name, root_followers, root_tweets, root_url, author_localisation = tools.get_user_info(
                    user)
                user_node = neo4j_connector.add_user_node(
                    screen_name=root_name,
                    followers_count=root_followers,
                    statuses_count=root_tweets,
                    url=root_url,
                    localisation=author_localisation,
                    classe=args.classe,
                )
                root_user_nodes.append(user_node)
            except tweepy.error.TweepError as e:
                print(u"Tweepy error {}".format(e))
            # end try
        # end for
    # end if