def sms_received(self, sender, msg): logger.debug("New sms from: %s" % sender) self.number_list = [friend.number for friend in self.friend_list] if not sender in self.number_list: # Create a new friend logger.debug("This is a new friend: %s" % sender) fullname = search_contact_by_number(str(sender)) number = str(sender) # Save it ! bonjour_auth_username = str(self.parent.bonjour_auth_user) auth_user = {bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username]} new_friend = Friend(fullname, number, auth_user) # Add to friend list in table model self.parent.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to friend list self.friend_list.append(new_friend) # Register it on bonjour new_friend.start() friend = new_friend else: i = self.number_list.index(sender) friend = self.friend_list[i] logger.debug("This is an old friend: %s" % sender) # SMS to bonjour logger.debug("Forward sms to bonjour") try: ret = friend.sms_to_bonjour(msg) logger.debug("sms_to_bonjour return: %s" % str(ret)) return ret except Exception, e: logger.debug("sms_to_bonjour error: %s" % str(e)) return False
def __process_add(self, command): list_ = command.args[0] ver = int(command.args[1]) passport_id = command.args[2] display_name = url_codec.decode(command.args[3]) group = None if list_ == Lists.FORWARD: group = self.friend_list.groups[int(command.args[4])] self.friend_list.ver = ver friend = self.friend_list.get_friend(passport_id, list_) if friend != None: friend.add_to_group(group) else: if group != None: friend = Friend(passport_id, passport_id, (group)) else: friend = Friend(passport_id, passport_id) self.friend_list.lists[list_][passport_id] = friend self.__friend_list_updated() if group != None: self.callbacks.friend_added(list_, passport_id, display_name, group.get_id()) else: self.callbacks.friend_added(list_, passport_id, display_name)
def function_add(self, id): """ Active a contact in HeySms """ if self.add_contact_dict is None: self.sms_to_bonjour(self.tr("Please use `search' command before")) else: try: id = int(id) except: self.sms_to_bonjour(self.tr("Bad ID: %s" % id)) return if not id in self.add_contact_dict: self.sms_to_bonjour(self.tr("ID not found: %s" % id)) return else: name, number = self.add_contact_dict[id] names = [friend.fullname for friend in self.active_contact_dict.values()] if name in names: self.sms_to_bonjour(self.tr("\r\nContact `%s' already activated\r\n" % name)) return new_friend = Friend(name, number, self.auth_user) # Add to friend list in table model self.parent.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to scheduler friend list self.parent.scheduler.friend_list.append(new_friend) new_friend.start() self.sms_to_bonjour(self.tr("\r\nContact `%s' activated\r\n" % name)) self.function_show()
def function_add(self, id): """ Active a contact in HeySms """ if self.add_contact_dict is None: self.sms_to_bonjour("Please use `search' command before") else: try: id = int(id) except: self.sms_to_bonjour("Bad ID: %s" % id) return if not id in self.add_contact_dict: self.sms_to_bonjour("ID not found: %s" % id) return else: name, number = self.add_contact_dict[id] names = [friend.fullname for friend in self.active_contact_dict.values()] if name in names: self.sms_to_bonjour("\r\nContact `%s' already activated\r\n" % name) return new_friend = Friend(name, number, self.auth_user) # Add to friend list in table model self.parent.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to scheduler friend list self.parent.scheduler.friend_list.append(new_friend) new_friend.start() self.sms_to_bonjour("\r\nContact `%s' activated\r\n" % name) self.function_show()
def create_friend(): data = { "fname": request.form['fname'], "lname": request.form['lname'], "occ": request.form['occ'] } Friend.save(data) return redirect('/')
def new_friend(self, friend_id: int): from friend import Friend friend = Friend(user_id=self.id, friend_id=friend_id) with session_manager() as session: if Friend.query_both(user_id=self.id, friend_id=friend_id, session=session): return self.friends.append(friend) friend.write(session)
def delFriendRequestHandle(self, sender, msgList): friendID = msgList[2] # 获取要删除的好友的ID friend_name = User.id_to_name(friendID) friend = Friend(sender.id, friend_name) friend.del_friend() # 如果被删除方也在线的话就给被删除方更新好友列表 for clientThread in self.threadPool: if clientThread.id == int(friendID): self.friendListRequestHandle(clientThread, "FriendListRequest".split(' '))
def setFriendNameRequestHandle(self, sender, msgList): friend_name = msgList[2] # 好友用户名 friend_mark_name = msgList[3] # 好友备注 friend = Friend(sender.id, friend_name, friend_mark_name) result = friend.set_remark_name(friend_mark_name) if result: print("setFriendNameSuccess") # 给请求方更新好友列表 self.friendListRequestHandle(sender, "FriendListRequest".split(' ')) else: print("setFriendNameFail")
def get_list_friends(self): list_raw_data = self.api.GetFriends() for info in list_raw_data: info_dict = info.AsDict() friend = Friend(friend_id=info_dict['id_str'], name=info_dict['name'], screen_name=info_dict['screen_name']) self.friends.append(friend) list_info = [friend.get_friend_info() for friend in self.friends] # for info in list_info: # print(info) return list_info
def read_file(file_in): friends = [] with open(file_in, newline='') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='|') for row in reader: if len(row) == 4: f = Friend(row[0], row[1], row[2], row[3]) friends.append(f) else: f = Friend(row[0], row[1], row[2], row[3], row[4]) friends.append(f) return friends
def delete_blacklist(uid, friend_uid): appid = APPID Blacklist.delete_blacklist(db, appid, uid, friend_uid) content = { "app_id":appid, "uid": uid, "friend_uid":friend_uid, "blacklist":0, "name":Friend.RELATIONSHIP_EVENT_BLACKLIST } Friend.publish_message(rds, content)
def get_user_friends(self, usr_id=None): """ returns list of 'Friend' objects, of a given user with 'usr_id' """ all_friends = [] with open("friends.txt", "r") as self.__friends_in: for line in self.__friends_in: usr_friends = Friend() lst_friends = [] sent_requests = [] id = int(line[:line.find(' ')]) if any([id == usr_id, usr_id is None]): usr_friends.set_id(id) line = line[line.find('['):] while line.find(']') != -1: temp = line[line.find('[') + 1:line.find(']')] temp = temp.split() temp = [int(temp[idx]) for idx in range(len(temp))] if 0 in temp[1:]: sent_requests.append(temp) elif 1 in temp[1:]: lst_friends.append(temp) line = line[line.find(']') + 2:] usr_friends.set_list(lst_friends) usr_friends.set_sent(sent_requests) all_friends.append(usr_friends) return all_friends
def friendListRequestHandle(self, sender, msgList): # 查询请求方好友列表 friend_list = eval(Friend.get_friend_list(sender.id)) # 查询请求方群列表 group_list = GroupUser.get_group_list(sender.id) group_info_list = [] for group_id in group_list: group_info = eval(GroupUser.get_group_info(group_id)) group_info_list.append("Group~`~{}~`~{}~`~{}".format( group_info[0], group_info[1], group_info[2])) # 整理格式并发送 sendMsg = "FriendList" for friend in friend_list: sendMsg += "~~~~~~" sendMsg += str(friend[0]) sendMsg += "~`~" sendMsg += friend[1] sendMsg += "~`~" sendMsg += friend[2] sendMsg += "~`~" sendMsg += User.get_user_info(friend[0]) for group_info in group_info_list: sendMsg += "~~~~~~" sendMsg += group_info sender.sendMsgToClientSignal.emit(sendMsg) print(sendMsg)
def returnOne(self, idd): cql_command = "select * from friend_information where id = " + idd info_list = [] newDatabase = Database() row = newDatabase.executeSelect(cql_command) newDatabase.close() if row: for x in row: info_list.append(x) else: print("An error occurred.") one = Friend( name=info_list[0].name, birthdate=datetime.strptime(info_list[0].birthdate, '%Y/%m/%d'), allergies=info_list[0].allergies, pronouns=info_list[0].pronouns, phone_number=info_list[0].phone_number, optional1={info_list[0].col1_name: info_list[0].col1_info}, optional2={info_list[0].col2_name: info_list[0].col2_info}, optional3={info_list[0].col3_name: info_list[0].col3_info}, optional4={info_list[0].col4_name: info_list[0].col4_info}) return (one)
def add_friend(): if request.method == 'POST': #When the add friend button is pressed r = request.form birthday = r.get('date') birthday_s = birthday.split('/') ##[mm,dd,yyyy] friend = Friend( name=str(r.get('first_name')) + " " + str(r.get('last_name')), pronouns=str(r.get('pronouns')), birthdate=datetime.date( int(birthday_s[2]), int(birthday_s[0]), int(birthday_s[1])), #datetime.date takes (yyyy,mm,dd) phone=str(r.get('phone_number')), allergies=str(r.get('allergies')), optional1={ str(r.get('optional1-name')): str(r.get('optional1-text')) }, optional2={ str(r.get('optional2-name')): str(r.get('optional2-text')) }, optional3={ str(r.get('optional3-name')): str(r.get('optional3-text')) }, optional4={ str(r.get('optional4-name')): str(r.get('optional4-text')) }) f = addFriend() f.add(friend) return redirect(url_for("load_dashboard"), code=303) if request.method == 'GET': #load page that has the form to add friend return render_template('add_friend.html')
def getFriends(db): conn = sqlite3.connect(db) cursor = conn.cursor() people = cursor.execute('SELECT * FROM friend;').fetchall() cursor.close() conn.close() return [Friend.fromTuple(f) for f in people]
def addFriendRequestHandle(self, sender, msgList): friend_name = msgList[2] # 获取要添加的好友用户名 # 检测是否存在这个ID friend = Friend(sender.id, friend_name) result = friend.add_friend() # 存在 if result: # 给请求方更新好友列表 sender.sendMsgToClientSignal.emit("NoThisUser 0") self.friendListRequestHandle(sender, "FriendListRequest".split(' ')) # 如果被请求方在线的话,给被请求方更新好友列表 for clientThread in self.threadPool: if clientThread.id == User.name_to_id(friend_name): self.friendListRequestHandle( clientThread, "FriendListRequest".split(' ')) # 如果不存在 else: sender.sendMsgToClientSignal.emit("NoThisUser 1")
async def deny_friend(request: Request, friend_form: FriendForm) -> JSONResponse: with session_manager() as session: friend = Friend.query_both( user_id=User.find(username=friend_form.username).id, friend_id=request.user.id, session=session, ) friend.delete(session=session) return renew(JSONResponse({"success": True}))
def Transform(self, client, user, callback): from friend import Friend friend = Friend.CreateFromKeywords(user_id=user.user_id, friend_id=user.user_id) logging.info('Creating friend for user %d', user.user_id) if Version._mutate_items: yield gen.Task(friend.Update, client) callback(user)
def _update_friends_list(self, json_update): """ Updates the friends list using a dict representing the JSON object that was returned by the Snapchat API. @json_update Dictionary representing the JSON update returned by the Snapchat API. """ friends = [Friend(friend[NAME], friend[DISPLAY], friend[TYPE] , friend[CAN_SEE_CUSTOM_STORIES]) for friend in json_update[FRIENDS]] self.friends = friends
def add_starting_friends(self): friend_numbers = config.startup_friends for number in friend_numbers: logger.debug("This is a starting friend: %s" % number) fullname = search_contact_by_number(number) # Save it ! while self.parent.bonjour_auth_user == '': logger.debug("Waiting selection of an authorized bonjour contact") sleep(1) bonjour_auth_username = str(self.parent.bonjour_auth_user) auth_user = {bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username]} new_friend = Friend(fullname, number, auth_user) new_friend.favorite = True # Add to friend list in table model self.parent.central_widget.friends_list.emit(QtCore.SIGNAL("add_friend"), new_friend) # append to friend list self.friend_list.append(new_friend) # Register it on bonjour new_friend.start()
def getFriend(self, userId, maxFriendId): sql = "select * from `friend` where user_id=%d and id>%d and add_flag=22 order by id desc" % ( userId, maxFriendId) with self.db.cursor() as cursor: cursor.execute(sql) results = cursor.fetchall() count = 0 friends = [] for res in results: friends.append(Friend(res[0], res[1], res[2], res[3], res[4])) count += 1 return friends, count
def init_game(): pygame.init() game_settings = Settings() screen = pygame.display.set_mode( (game_settings.screen_width, game_settings.screen_height), pygame.FULLSCREEN) # screen = pygame.display.set_mode((game_settings.screen_width, game_settings.screen_height)) ship = Ship(screen) stats = GameStats(game_settings) friend = Friend(screen) enemy = Enemy(screen) enemy_2 = Enemy_2(screen) enemy_3 = Enemy_3(screen) enemy_4 = Enemy_4(screen) enemy_5 = Enemy_5(screen) enemy_6 = Enemy_6(screen) enemy_7 = Enemy_7(screen) enemy_8 = Enemy_8(screen) enemy_9 = Enemy_9(screen) hook = Hook(screen) background = Background(screen) pygame.display.set_caption("Peter Pan") bullets = Group() enemies = Group() enemies.add(enemy, enemy_2, enemy_3, enemy_4, enemy_5, enemy_6, enemy_7, enemy_8, enemy_9, hook) friends = Group() friends.add(friend) ships = Group() ships.add(ship) #g_f.create_fleet(game_settings, screen, ship) button = Button(screen, game_settings, "Play") sb = Scoreboard(game_settings, screen, stats) while True: g_f.chek_events(game_settings, ship, screen, bullets, button, stats, enemies, sb) g_f.update_screen(background, ships, bullets, enemies, screen, button, friends, stats, sb) if stats.game_active: g_f.update_bullets(bullets, enemies, ships, friends, hook, stats, sb, screen) g_f.aliens_move(enemies, screen, friends, ships, bullets, ship) ship.update() ship.blitme()
async def add_friend(request: Request, friend_form: FriendForm) -> JSONResponse: id = User.find(username=friend_form.username).id with session_manager() as session: friend = Friend.query_both( user_id=User.find(username=friend_form.username).id, friend_id=request.user.id, session=session, ) if friend: return renew(JSONResponse({"success": False}), request.user.token) request.user.new_friend(id) return renew(JSONResponse({"success": True}), request.user.token)
def run_friend_tests(self): # think friend needs named params now. friend = Friend(name="Jaoh Smith", email="*****@*****.**", phone="1234-555-1234", street="some st.", city="Some City") print("friend.name: ", friend.name) print("friend.email: ", friend.email) print("friend.phone: ", friend.phone) print("friend.street: ", friend.street) print("friend.city: ", friend.city) print("friend.state: ", friend.state) print("friend.code: ", friend.code)
def __process_lst(self, command): from protocol import list_flags passport_id = command.args[0] display_name = url_codec.decode(command.args[1]) list_ = int(command.args[2]) group_id = [] if list_ & list_flags[Lists.FORWARD]: group_id = [int(i) for i in split(command.args[3], ',')] groups = None if len(group_id): groups = [self.friend_list.groups[g_id] for g_id in group_id] friend = Friend(passport_id, display_name, groups=groups) for f in list_flags.keys(): if list_ & list_flags[f]: self.friend_list.lists[f][passport_id] = friend if self.friend_list.temp_iln.has_key(passport_id): friend.state = self.friend_list.temp_iln[passport_id] self.__friend_list_updated()
def sms_received(self, sender, msg): logger.debug("New sms from: %s" % sender) self.number_list = [friend.number for friend in self.friend_list] if not sender in self.number_list: # Create a new friend logger.debug("This is a new friend: %s" % sender) fullname = search_contact_by_number(str(sender)) number = str(sender) # Save it ! bonjour_auth_username = str(self.parent.bonjour_auth_user) auth_user = { bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username] } new_friend = Friend(fullname, number, auth_user) # Add to friend list in table model self.parent.central_widget.friends_list.emit( QtCore.SIGNAL("add_friend"), new_friend) # append to friend list self.friend_list.append(new_friend) # Register it on bonjour new_friend.start() friend = new_friend else: i = self.number_list.index(sender) friend = self.friend_list[i] logger.debug("This is an old friend: %s" % sender) # SMS to bonjour logger.debug("Forward sms to bonjour") try: ret = friend.sms_to_bonjour(msg) logger.debug("sms_to_bonjour return: %s" % str(ret)) return ret except Exception, e: logger.debug("sms_to_bonjour error: %s" % str(e)) return False
def __process_lst(self, command): from protocol import list_flags passport_id = command.args[0] display_name = url_codec.decode(command.args[1]) list_ = int(command.args[2]) group_id = [] if list_ & list_flags[Lists.FORWARD]: group_id = [int(i) for i in split(command.args[3], ',')] groups = None if len(group_id): groups = [self.friend_list.groups[g_id] for g_id in group_id] friend = Friend(passport_id, display_name, groups = groups) for f in list_flags.keys(): if list_ & list_flags[f]: self.friend_list.lists[f][passport_id] = friend if self.friend_list.temp_iln.has_key(passport_id): friend.state = self.friend_list.temp_iln[passport_id] self.__friend_list_updated()
def add_starting_friends(self): friend_numbers = config.startup_friends for number in friend_numbers: logger.debug("This is a starting friend: %s" % number) fullname = search_contact_by_number(number) # Save it ! while self.parent.bonjour_auth_user == '': logger.debug( "Waiting selection of an authorized bonjour contact") sleep(1) bonjour_auth_username = str(self.parent.bonjour_auth_user) auth_user = { bonjour_auth_username: self.parent.bonjour_users[bonjour_auth_username] } new_friend = Friend(fullname, number, auth_user) new_friend.favorite = True # Add to friend list in table model self.parent.central_widget.friends_list.emit( QtCore.SIGNAL("add_friend"), new_friend) # append to friend list self.friend_list.append(new_friend) # Register it on bonjour new_friend.start()
def getFriends(myUserId): url = "http://glassdoor-api.azurewebsites.net/Home/GetFriends/" + myUserId jsonResp = urllib.request.urlopen(url).read() data = json.loads(jsonResp) friends = [] for friend in data: createFriendPhoto(friend['imageBase64'], friend['friendId'], friend['imageExtension']) friends.append( Friend(friend['friendName'], '%s.%s' % (friend['friendId'], friend['imageExtension']), friend['friendId'])) print(friend['friendName']) return friends
def setMyInfoRequestHandle(self, sender, msg): user_id = sender.id user_info_dict = eval(msg.split("~`~")[2]) friend_id_list = eval(Friend.get_friend_id_list(sender.id)) result = User.set_user_info(user_id, user_info_dict) if result or result == 0: self.myInfoRequestHandle(sender, msg) # 如果好友在线的话就给这些成员更新好友列表 for clientThread in self.threadPool: if clientThread.id in friend_id_list: self.friendListRequestHandle( clientThread, "FriendListRequest".split(' ')) sender.sendMsgToClientSignal.emit("UpdateMyInfo 0") print("UpdateSuccess") else: sender.sendMsgToClientSignal.emit("UpdateMyInfo 1") print("UpdateFail")
def get_friends(self, user_id): self.connect() statement = "SELECT * FROM FRIENDS WHERE USER1_ID = %s" data = [user_id] query = statement, data self.query_database(query) friends = [] for row in self.cursor: (user1_id, user2_id, date_befriended, is_blocked, is_following, num_of_shared_games, is_favourite) = row friend = Friend(user1_id, user2_id, date_befriended, is_blocked, is_following, num_of_shared_games, is_favourite) friends.append(friend) self.disconnect() return friends
def __init__(self, id=None, log=None, name=None, surname=None, password=None, friends=Friend(), access=[Enum(3)]): """ 'access' - privacy settings 'access[0]' - true by default, access to view a wall """ self.__id = id self.__log = log self.__name = name self.__surname = surname self.__pass = password self.__friends = friends self.__access = access
async def friends_list(request: Request) -> JSONResponse: friends = Friend.find(id=request.user.id) or [] friends_list = [] for friend in friends: # if not accepted, don't show on requester's side if friend.user_id == request.user.id and not friend.confirmed: continue if friend.user_id == request.user.id: if not friend.confirmed: continue friend_id = friend.friend_id else: friend_id = friend.user_id user = User.find(id=friend_id) friends_list.append({ "id": friend_id, "name": user.username, "confirmed": friend.confirmed, "avatar": user.avatar, }) return renew(JSONResponse({ "success": True, "friends": friends_list }), request.user.token)
friends = pygame.sprite.Group() players = pygame.sprite.Group() backgrounds = pygame.sprite.Group() all = pygame.sprite.OrderedUpdates() Friend.containers = (all, friends) BackGround.containers = (all, backgrounds) Browser.containers = (all, players) BackGround("rsc/bgorg.jpg") run = True while True: player = Browser((200,200)) friends = Friend ((300,300)) while run: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_w: player.go("up") if event.key == pygame.K_d: player.go("right") if event.key == pygame.K_s: player.go("down") if event.key == pygame.K_a: player.go("left") if event.key == pygame.K_UP: friends.go("up") if event.key == pygame.K_RIGHT: