Esempio n. 1
0
def confirm_friend():
    user = current_user._get_current_object()
    form = request.get_json()
    schema = {
        'id':{'type':'integer','empty':False}
    }
    v = Validator(schema)
    if v.validate(form) is False:
        return api_validation_error(v.errors)

    friend_request = FriendRequests.query.filter(FriendRequests.id == form['id']).first()
    if friend_request:

        #we are confirming this, so create friendships that last both ways.
        my_friend = Friends(user_id = user.id,friend_id = friend_request.friend_id)
        their_friend = Friends(user_id = friend_request.friend_id,friend_id = user.id)

        meeple.db.session.add(my_friend)
        meeple.db.session.add(their_friend)
        meeple.db.session.delete(friend_request) #remove this friend request
        meeple.db.session.commit()

        #now return who this friend is back to them.
        return api_package(data=my_friend.as_dict())
    else:
        return api_error("This request does not exist")
Esempio n. 2
0
    def __init__(self, client):
        self.client = client
        self.state = 'main'
        # state main
        self.title_main = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'SocketGame', font=Font.f100)

        self.button_login = Button(DIM_MAIN_B, C.LIGHT_BLUE,
                                POS_BLOG,'Log in')


        self.button_signup = Button(DIM_MAIN_B, C.LIGHT_BLUE,
                                POS_BSIGN,'Sign up') 

        self.button_credits = Button(DIM_LI_MAIN_B, C.LIGHT_BLUE, (LMARGE, LMARGE),'Credits',font=Font.f30)

        # state login
        self.title_login = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Log in', font=Font.f100)

        self.text_logusername = TextBox(DIM_TEXTBL,C.WHITE,
                                (X_POS_TEXTBL, Y_POS_TEXTBL), 'Username:'******'Password:'******'Done', font=Font.f30)
        self.button_back = Button(DIM_NB, C.LIGHT_BLUE, POS_BBACK,'Back', font=Font.f30)
        # state signup
        self.title_signup = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Sign up', font=Font.f100) 
        # state fail log
        self.text_faillog = TextBox(DIM_FAILT, C.WHITE, (X_POS_TEXTBL2, Y_POS_FAILT),
                                'Invalid username or password', font=Font.f25, TEXT_COLOR=C.RED)  
        # state fail sign
        self.text_failsign = TextBox(DIM_FAILT, C.WHITE, (X_POS_TEXTBL2, Y_POS_FAILT),
                                'Username already taken', font=Font.f25, TEXT_COLOR=C.RED)  
        # state logged
        self.title_logged = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Welcome', font=Font.f100)
        self.text_username = TextBox(DIM_LOGINP, C.WHITE, (LMARGE, LMARGE),'',marge=True)
        self.button_play = Button(DIM_MAIN_B, C.LIGHT_BLUE, 
                    POS_BPLAY, 'Play') 
        self.chat_logged = Chat(DIM_CHAT, (MARGE,dim.y-DIM_CHAT[1]-MARGE), self.client)
        self.friends = Friends(DIM_FR, (dim.x-DIM_FR[0]-MARGE, E(250)), self.client)
        self.button_disconn = Button(DIM_LI_MAIN_B, C.LIGHT_BLUE, (LMARGE + E(250), MARGE+DIM_LOGINP[1])
                        ,'Disconnect',font=Font.f30)
        self.button_account = Button(DIM_LI_MAIN_B, C.LIGHT_BLUE, (LMARGE, MARGE+DIM_LOGINP[1]),'Account',font=Font.f30)
        # state env
        self.title_env = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Env', font=Font.f100)
        self.text_wating = TextBox(DIM_TWAIT,C.WHITE, POS_TWAIT,
                             'Waiting for the other players...', font=Font.f30)
        self.button_exit = Button(DIM_BEXIT, C.LIGHT_BLUE, POS_BEXIT, 'Exit', font=Font.f30)
        self.teams = Teams
        self.teams.init(POS_TEAMS,DIM_TEAMS, client)
        # state account
        self.title_account = TextBox(DIM_TITLE, C.WHITE, (POS_TITLE[0], POS_TITLE[1] + E(100)),'', font=Font.f100)
        Stats.init(client, POS_STATSY)
        self.Stats = Stats
Esempio n. 3
0
    def crawl_followers(self, **mongo_conn_kw):
        # Resolve the ID for screen_name and start working with IDs for consistency
        # in storage

        self.seed_id = str(
            self.twitter_api.users.show(
                screen_name=self.screen_name)['id'])  # get the twitter id

        # gets friends and followers for specified user_id-> unpacks into _, next_queue
        friends, self.next_queue = Friends(
            twitter_api=self.twitter_api,
            user_id=self.seed_id).get_friends_followers_ids()
        self.next_queue = self.get_reciprocal_friends(
            friends, self.next_queue)  # add to the queue
        self.node_count += len(self.next_queue) + 1
        self.node_list = self.next_queue  # initialize with initial queue
        self.write_to_disk(
            self.seed_id, 'reciprocal',
            self.next_queue)  # write the root and reciprocal friends

        while self.node_count <= self.node_max:
            # set queue to next_queue and next_queue to empty list in preparation for another call to
            # get_friends_followers_ids()
            (self.queue, self.next_queue) = (self.next_queue, [])
            print(self.queue)
            for fid in self.queue:  # get the friends and followers for each id in the queue
                # variables returned from call to Friends.get_friends_followers_ids
                friend_ids, follower_ids = Friends(
                    twitter_api=self.twitter_api,
                    user_id=fid).get_friends_followers_ids()
                if len(friend_ids) == 0 or len(follower_ids) == 0:
                    continue
                reciprocal_friends = self.get_reciprocal_friends(
                    friend_ids,
                    follower_ids)  # returns top 5 sorted by followers_count
                if len(reciprocal_friends) == 0:
                    self.write_to_disk(fid, 'reciprocal', reciprocal_friends)
                    continue
                nodes_no_root = [
                    node for node in reciprocal_friends
                    if node != int(self.seed_id)
                ]  # removes the root node if present to prevent recursion
                self.node_count += len([
                    node for node in nodes_no_root
                    if node not in self.node_list
                ])  # increment count of nodes
                self.next_queue.extend(nodes_no_root)  # add to the queue
                self.node_list.extend(nodes_no_root)  # add to node list
                print("{} nodes added to the queue".format(len(nodes_no_root)))
                print(f"{self.node_count} total nodes")
                self.write_to_disk(
                    fid, 'reciprocal', reciprocal_friends
                )  # writes all reciprocal friends--including root--if present
                if self.node_count > self.node_max:
                    break
Esempio n. 4
0
    def get_all_friends_and_register_as_friend(self, start):
        maxtime = datetime.datetime.now() - datetime.timedelta(minutes=30)
        maxtime = int(time.mktime(maxtime.timetuple()))
        user_pages_count = int(
            self.db_object.get_count(
                self.table_name, {
                    'join_time': {
                        '$gt': start
                    },
                    'join_time': {
                        '$lt': maxtime
                    },
                    'email_registration': {
                        '$ne': 1
                    },
                    'is_unknown_profile': 'false',
                    'followers_pulled': {
                        '$exists': False
                    }
                }))
        for i in range(0, user_pages_count, 1):
            pag_users = self.db_object.get_paginated_values(
                self.table_name, {
                    'join_time': {
                        '$gt': start
                    },
                    'join_time': {
                        '$lt': maxtime
                    },
                    'email_registration': {
                        '$ne': 1
                    },
                    'followers_pulled': {
                        '$exists': False
                    },
                    'is_unknown_profile': 'false'
                },
                pageNumber=int(i + 1))
            from friends import Friends
            for eachUser in pag_users:
                friend_obj = Friends()
                # friend_obj.process_friends_or_followers(eachUser, 'friends')
                friend_obj.process_friends_or_followers(eachUser, 'followers')
                self.update_profile_fields(
                    {
                        'username': eachUser['username'],
                        'screen_name': eachUser['screen_name']
                    }, {'followers_pulled': True})

        return {'status': 1}
Esempio n. 5
0
 def __init__(self, access_token=''):
     self.Account = Account(access_token=access_token)
     self.Apps = Apps(access_token=access_token)
     self.Audio = Audio(access_token=access_token)
     self.Auth = Auth(access_token=access_token)
     self.Board = Board(access_token=access_token)
     self.Database = Database(access_token=access_token)
     self.Docs = Docs(access_token=access_token)
     self.Other = Other(access_token=access_token)
     self.Fave = Fave(access_token=access_token)
     self.Friends = Friends(access_token=access_token)
     self.Gifts = Gifts(access_token=access_token)
     self.Groups = Groups(access_token=access_token)
     self.Likes = Likes(access_token=access_token)
     self.Market = Market(access_token=access_token)
     self.Messages = Messages(access_token=access_token)
     self.Newsfeed = Newsfeed(access_token=access_token)
     self.Notes = Notes(access_token=access_token)
     self.Notifications = Notifications(access_token=access_token)
     self.Pages = Pages(access_token=access_token)
     self.Photos = Photos(access_token=access_token)
     self.Places = Places(access_token=access_token)
     self.Polls = Polls(access_token=access_token)
     self.Search = Search(access_token=access_token)
     self.Stats = Stats(access_token=access_token)
     self.Status = Status(access_token=access_token)
     self.Storage = Storage(access_token=access_token)
     self.Users = Users(access_token=access_token)
     self.Utils = Utils(access_token=access_token)
     self.Video = Video(access_token=access_token)
     self.Wall = Wall(access_token=access_token)
     self.Widgets = Widgets(access_token=access_token)
Esempio n. 6
0
def main():
    username = input()

    try:
        uid = User(username).execute()
    except User.UserNotFound as e:
        e.msg()
        return

    try:
        ages = Friends(uid).execute()
    except Friends.FriendsNotFound as e:
        e.msg()
        return

    draw_graph(ages)
    #gen_random(1, 50, 50)
    #gen_random(1, 60, 70)
    fig, ax = plt.subplots()
    # add a 'best fit' line

    plt.bar(Age, Val, align='center')
    ax.set_xlabel('Age')
    ax.set_ylabel('value')
    ax.set_title('Histogram of ages of friends')
    plt.show()

    return
Esempio n. 7
0
    def send_secret_message(self):
        self.time = datetime.now()
        #calling method to get friend
        friend = Friends.select_a_friend()

        if friend is None:
            return
        self.sendto = friend.name

        #getting message in any cost
        while len(self._message) == 0:
            self._message = raw_input("Enter the message\n")
        #checking length
        if len(self._message) > 100:
            print "You talk to much .Message must be of max 100 letters"
        else:
            #message for specific words
            if self._message.upper() == "SOS":
                print "I will save you"
            elif self._message.upper() == "SAVE ME":
                print "You will be saved"
            Friends.no +=1
            self.output_file = "C:\Users\Garg\PycharmProjects\FirstProject\spychat\Encryptedimage" + str(Friends.no) + ".jpg"

            #encrypting the message
            Steganography.encode("C:\Users\Garg\PycharmProjects\FirstProject\spychat\image\python.jpg", self.output_file, self._message)
            #adding to message list
            friend.messages.append(self)
Esempio n. 8
0
def start_chat():
    while True:
        print """What do you want to do?
        1. Add a status update
        2. Add a friend
        3. Send a secret message
        4. Read a secret message 
        5. Read Chats from a user 
        6. Close Application \n"""

        choice = None
        # getting choice of user
        try:
            choice = int(raw_input())
        except:
            print "Enter a digit"
        # setting status
        if choice == 1:
            Add_message.add_status()

        # making friends
        elif choice == 2:
            Friends.add_friend(Friends())

        #sending secret message
        elif choice == 3:
            Message().send_secret_message()

        #reading secret message
        elif choice == 4:
            Message.read_secret_message()

        #printing metadata of message
        elif choice == 5:
            Message.get_history()

        # exiting app
        elif choice == 6:
           exit(0)

        else:
            print "Wrong choice"
Esempio n. 9
0
 def get_history():
     friend = Friends.select_a_friend()
     if friend is None:
         return
     if len(friend.messages) <= 0:
         print "No message"
         return
     for data in friend.messages:
         print colored(data.sendto, "red")
         print colored(data.time, "blue")
         print data._message
Esempio n. 10
0
	def execute(command):
		if command[0].lower() == 'profile':
			try:
				print(Profile.getProfileInfo(command[1]))
			except:
				print(Profile.getcurrentProfile())
		if command[0].lower() == 'friends':
			Friends.getFriends(command[1], command[2])
		if command[0].lower() == 'help':
			try:
				Help.help_4_func(command[1])
			except:
				Help.help_4_func(func='help')

		if command[0].lower() == 'messages':
			try:
				print(Messages.Get(command[1].lower()))
			except:
				print("Ошибка запроса, попробуйте еще раз")
				pass
		if command[0].lower() == 'message':
			message = input("Write message# ")
			Messages.Send(command[1], message)
Esempio n. 11
0
    def test_Names(self):
        f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"}))
        n = f.names()
        assert n == {"nikola", "sophia", "robot", "pilot", "stephen"}

        f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"}))
        f.remove({"stephen", "robot"})
        n = f.names()
        assert n == {"nikola", "sophia", "pilot"}
Esempio n. 12
0
    def test_Remove(self):
        f = Friends([{"1", "2"}, {"3", "1"}])
        assert f.remove({"2", "4"}) is False

        f = Friends([{"1", "2"}, {"3", "1"}])
        assert f.remove({"11", "12"}) is False

        f = Friends([{"And", "Or"}, {"For", "And"}])
        assert f.remove({"And", "Or"}) is True
Esempio n. 13
0
    def test_Add(self):
        f = Friends([{"1", "2"}, {"3", "1"}])
        assert f.add({"2", "4"}) is True

        f = Friends([{"And", "Or"}, {"For", "And"}])
        assert f.add({"It", "Am"}) is True

        f = Friends([{"And", "Or"}, {"For", "And"}])
        assert f.add({"Or", "And"}) is False
Esempio n. 14
0
 def read_secret_message():
     #getting the friend
     friend = Friends.select_a_friend()
     if friend is None:
         return
     #chrcking  message
     if len(friend.messages) <= 0:
         print "No message"
         return
     for i in range(len(friend.messages)):
         print "Message {}".format(i + 1)
     no = int(raw_input("Enter the Message no. to read"))
     if no <= 0 or no > len(friend.messages):
         print "Wrong input"
         return
     message = Steganography.decode(friend.messages[no - 1].output_file)
     print "The message is : {}".format(message)
Esempio n. 15
0
#!/usr/bin/env python
# encoding: utf-8
# Create your views here.
import os
import sys

CLASS_PATH = '/srv/www/live/foodtrade-env/foodtrade/mainapp/classes'
SETTINGS_PATH = '/srv/www/live/foodtrade-env/foodtrade/foodtrade'

# CLASS_PATH = 'C:/Users/Roshan Bhandari/Desktop/foodtrade/mainapp/classes'
# SETTINGS_PATH = 'C:/Users/Roshan Bhandari/Desktop/foodtrade/foodtrade'

sys.path.insert(0, CLASS_PATH)
sys.path.insert(1, SETTINGS_PATH)

from friends import Friends

fr = Friends()
fr.register_all_friends()
Esempio n. 16
0
from id import Id
from friends import Friends

name = input('Имя пользователя: ')
client = Id(name)
uid = client.execute()

friends_client = Friends(uid)
friends = friends_client.execute()

for (age, count) in friends:
    print('{} {}'.format(int(age), '#' * count))
Esempio n. 17
0
import json
import hashlib
import requests
from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask, render_template, redirect, request
from friends import Friends

app = Flask(__name__, template_folder='templates')
sched = BackgroundScheduler()
friends = Friends()

@app.route("/")
def index():
    return render_template('index.html')

@app.route("/friends")
def get_friends():
    return json.dumps([friend.dump() for friend in friends.gold()])

@app.route("/follow", methods = ['POST'])
def follow_friends():
    secret = request.headers.get("S-AUTH", "")
    if hashlib.sha224(secret.encode('utf-8')).hexdigest() == "66de1a3afbebba2648fb742e0385e4e998d354aab823e2bcd2f6a2e0":
        follow_list = request.form.getlist('friend[]')
        friends.follow(follow_list)
        return ('', requests.codes.ok)
    else:
        return ('', requests.codes.unauthorized)

if __name__ == '__main__':
    friends.populate()
Esempio n. 18
0
class Menu:
    play_pushed = False
    def __init__(self, client):
        self.client = client
        self.state = 'main'
        # state main
        self.title_main = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Title', font=Font.f100)

        self.button_login = Button(DIM_MAIN_B, C.LIGHT_BLUE,
                                POS_BLOG,'Log in')


        self.button_signup = Button(DIM_MAIN_B, C.LIGHT_BLUE,
                                POS_BSIGN,'Sign up') 

        # state login
        self.title_login = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Log in', font=Font.f100)

        self.text_logusername = TextBox(DIM_TEXTBL,C.WHITE,
                                (X_POS_TEXTBL, Y_POS_TEXTBL), 'Username:'******'Password:'******'Done', font=Font.f30)
        self.button_back = Button(DIM_NB, C.LIGHT_BLUE, POS_BBACK,'Back', font=Font.f30)
        # state signup
        self.title_signup = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Sign up', font=Font.f100) 
        # state fail log
        self.text_faillog = TextBox(DIM_FAILT, C.WHITE, (X_POS_TEXTBL2, Y_POS_FAILT),
                                'Invalid username or password', font=Font.f25, TEXT_COLOR=C.RED)  
        # state fail sign
        self.text_failsign = TextBox(DIM_FAILT, C.WHITE, (X_POS_TEXTBL2, Y_POS_FAILT),
                                'Username already taken', font=Font.f25, TEXT_COLOR=C.RED)  
        # state logged
        self.title_logged = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Welcome', font=Font.f100)
        self.text_username = TextBox(DIM_LOGINP, C.WHITE, (LMARGE, LMARGE),'',marge=True)
        self.button_play = Button(DIM_MAIN_B, C.LIGHT_BLUE, 
                    POS_BPLAY, 'Play') 
        self.chat_logged = Chat(DIM_CHAT, (MARGE,dim.y-DIM_CHAT[1]-MARGE), self.client)
        self.friends = Friends(DIM_FR, (dim.x-DIM_FR[0]-MARGE, E(250)), self.client)
        self.button_disconn = Button(DIM_LI_MAIN_B, C.LIGHT_BLUE, (LMARGE, MARGE+DIM_LOGINP[1])
                        ,'Disconnect',font=Font.f30)
        # state env
        self.title_env = TextBox(DIM_TITLE, C.WHITE, POS_TITLE,'Env', font=Font.f100)
        self.text_wating = TextBox(DIM_TWAIT,C.WHITE, POS_TWAIT,
                             'Waiting for the other players...', font=Font.f30)
        self.button_exit = Button(DIM_BEXIT, C.LIGHT_BLUE, POS_BEXIT, 'Exit', font=Font.f30)
        self.teams = Teams
        self.teams.init(POS_TEAMS,DIM_TEAMS, client)

    def display_main(self):
        self.title_main.display()
        self.button_login.display()
        self.button_signup.display()
    
    def display_login(self):
        self.title_login.display()
        self.text_logusername.display()
        self.text_password.display()
        self.input_username.display()
        self.input_password.display()
        self.button_back.display()
        self.button_done.display()
    
    def display_signup(self):
        self.title_signup.display()
        self.text_logusername.display()
        self.text_password.display()
        self.input_username.display()
        self.input_password.display()
        self.button_back.display()
        self.button_done.display()

    def display_logged(self):
        self.title_logged.display()
        self.text_username.display()
        self.button_disconn.display()
        self.button_play.display()
        self.chat_logged.display()
        self.friends.display()

    def display_env(self):
        self.title_env.display()
        self.text_username.display()
        if not self.play_pushed:
            self.button_play.display()
        else:
            self.text_wating.display()
        self.button_disconn.display()
        self.button_exit.display()
        self.chat_logged.display()
        self.friends.display()
        self.teams.display()

    def display_faillog(self):
        self.display_login()
        self.text_faillog.display()
    
    def display_failsign(self):
        self.display_signup()
        self.text_failsign.display()

    def react_events_main(self, events, pressed):
        if self.button_login.pushed(events):
            self.state = 'login'
        elif self.button_signup.pushed(events):
            self.state = 'signup'
    
    def react_events_login(self, events, pressed):
        self.input_username.run(events, pressed)
        self.input_password.run(events, pressed)
        if self.button_back.pushed(events):
            self.state = 'main'
        if self.button_done.pushed(events):
            username = self.input_username.text
            password = self.input_password.text
            if self.client.log(username, password):
                self.state = 'logged'
                self.text_username.set_text(username)
                self.teams.set_username(username)
                self.chat_logged.activate()
            else:
                self.state = 'fail log'

    def react_events_signup(self, events, pressed):
        self.input_username.run(events, pressed)
        self.input_password.run(events, pressed)
        if self.button_back.pushed(events):
            self.state = 'main'
        if self.button_done.pushed(events):
            username = self.input_username.text
            password = self.input_password.text
            if self.client == 1:
                self.state = 'logged'
            else:
                if self.client.sign_up(username, password):
                    self.state = 'logged'
                    self.text_username.set_text(username)
                    self.teams.set_username(username)
                    self.chat_logged.activate()
                else:
                    self.state = 'fail sign'
                
    def react_events_logged(self, events, pressed):
        self.chat_logged.react_events(events, pressed)
        if self.button_play.pushed(events):
            print('play')
        if self.button_disconn.pushed(events):
            self.disconn()
        self.friends.react_events(events, pressed)
        # check for env 
        if self.client.in_env:
            self.teams.set_players() # must have receive players connected from server (env)
            self.state = 'env'
        
    def react_events_env(self, events, pressed):
        self.chat_logged.react_events(events, pressed)
        self.teams.react_events(events, pressed)
        if self.button_disconn.pushed(events):
            self.disconn()
        self.friends.react_events(events, pressed)
        
        if not self.play_pushed:
            if self.button_play.pushed(events):
                self.client.env_play()
                self.play_pushed = True

        if self.button_exit.pushed(events):
            self.client.quit_game_or_env()

        if self.client.in_game_session:
            start_game(self.client)
            self.state = 'in game'

    def disconn(self):
        self.client.disconn()
        self.state = 'main'
        self.input_password.text = ''
        self.input_username.text = ''
        self.chat_logged.reset()
        self.friends.reset()


    def run(self, events, pressed):
        if self.state == 'in game':
            if not self.client.in_game_session:
                if self.client.in_env:
                    self.state = 'env'
                else:
                    self.state = 'logged'
            run_game(pressed, events)
        elif self.state == 'main':
            self.display_main()
            self.react_events_main(events, pressed)
        elif self.state == 'login':
            self.display_login()
            self.react_events_login(events, pressed)
        elif self.state == 'signup':
            self.react_events_signup(events, pressed)
            self.display_signup()
        elif self.state == 'logged':
            self.display_logged()
            self.react_events_logged(events, pressed)
        elif self.state == 'env':
            self.display_env()
            self.react_events_env(events, pressed)
            if not self.client.in_env:
                self.state = 'logged'
        elif self.state == 'fail log':
            self.display_faillog()
            self.react_events_login(events, pressed)
        elif self.state == 'fail sign':
            self.display_failsign()
            self.react_events_signup(events, pressed)
from friends import Friends, Friend

Friends.connection_string = 'my_friends.db'

tinkles = Friend('Tinkles', 'the Chubby Unicorn', 10)
Friends.create(tinkles)

all_friends = Friends().getAll()
for f in all_friends:
    print(f.first_name)
Esempio n. 20
0
from datetime import datetime, date
from user_id import UserId
from friends import Friends
from random import randint, normalvariate

import matplotlib.pyplot as plt

if __name__ == "__main__":
    ages_dct = dict()
    get_user_id = UserId(input())
    get_friends = Friends(get_user_id.execute())
    it_dict = get_friends.execute()
    for f in it_dict:

        if f.get('bdate') is None:
            continue

        bdate = f['bdate'].split('.')
        if len(bdate) != 3:
            continue

        age = datetime.now(tz=None).date() - date(int(bdate[2]), int(bdate[1]),
                                                  int(bdate[0]))
        age = int(age.days / 365)

        if ages_dct.get(age) is None:
            ages_dct[age] = 1
        else:
            ages_dct[age] += 1

    x_axis = []
Esempio n. 21
0
    def test_Connected(self):
        f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"}))
        n = f.connected("nikola")
        assert n == {"sophia"}

        f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"}))
        n = f.connected("sophia")
        assert n == {"nikola", "pilot"}

        f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"}))
        n = f.connected("DDD")
        assert n == set()

        f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"}))
        f.add({"sophia", "stephen"})
        f.remove({"sophia", "nikola"})
        n = f.connected("sophia")
        assert n == {"stephen", "pilot"}