def search(token,query_str): message_list = [] tok_uid = data.get('tok_uid') channels = data.get('channels') if token is None: print('Not logged in') else: uid = tok_uid.get(token) for i in channels: id = i.get('channel_id') #will give access error if other user tried to access try: diction = channel_details(token,id) except: continue members = diction.get('all_members') for j in members: check_id = j.get('u_id') if check_id is uid: message = i.get('messages') for j in message: if check(j.get('message'),query_str): message_list.append(j.get('message')) return message_list
def get_booking_data(): if 'email' not in session: return jsonify({"error": True, "message": "未登入系統"}), 403 if request.method == "POST": try: data = request.get_json() attractionId = data.get("attractionId") date = data.get("date") time = data.get("time") price = data.get("price") userId = session['id'] if date and time and price: new_booking = booking_tb(attractionId=attractionId, date=date, time=time, price=price, userId=userId) db.session.add(new_booking) db.session.commit() return jsonify({"ok": True}) else: return jsonify({"error": True, "message": "訂單失敗,有資料未輸入"}), 400 except: return jsonify({"error": True, "message": "伺服器內部錯誤"}), 500 if request.method == "GET": userId = session["id"] booking = f''' SELECT booking_tb.date,booking_tb.time,booking_tb.price, attraction_tb.id as attId,attraction_tb.name,attraction_tb.address,attraction_tb.images,booking_tb.id FROM booking_tb INNER JOIN attraction_tb ON booking_tb.attractionId = attraction_tb.id WHERE booking_tb.userId='{userId}' ORDER BY booking_tb.id DESC ''' booking_data = db.engine.execute(booking) for row in booking_data: data = { "attraction": { "id": row[3], "name": row[4], "address": row[5], "image": row[6].split(";")[0] }, "date": row[0], "time": row[1], "price": row[2] } return jsonify({"data": data}) return jsonify({"data": None}) if request.method == "DELETE": db.session.query(booking_tb).filter_by(userId=session['id']).delete() db.session.commit() return jsonify({"ok": True}) return jsonify({"error": True})
def send_email(text): id = data.get('id') password = data.get('password') email = f'{id}@gmail.com' smtp = smtplib.SMTP_SSL('smtp.gmail.com', 465) smtp.login(id, password) print("Login Success") msg = MIMEText(text, "html") msg['Subject'] = '오늘의 채용 공고' msg['To'] = email smtp.sendmail(email, email, msg.as_string()) print("Successfully send email") smtp.quit()
def channels_listall(token): ## tok_uid = data.get('tok_uid') channels = data.get('channels') if token is None: print('Not logged in') else: ## uid = tok_uid.get(token) channels_2 = [] for i in channels: name = i.get('name') id = i.get('channel_id') print(f'Name of channel {name} ') print(f'Id of channel {id}') diction = channel_details(token, id) user_name = diction.get('name') owners = diction.get('owner_members') members = diction.get('all_members') channels_2.append({'channel_id': id, 'name': name}) print(f'Name of the channel {user_name}') print(f'Owners of the channel {owners}') print(f'Members of the channel {members}') return {'channels': channels_2}
def create_bayes_net(): bayes_net = (BayesNet().add('IW', [], data.get('IW')).add( 'B', ['IW'], data.get('B')).add('SM', ['IW'], data.get('SM')).add( 'R', ['B'], data.get('R')).add('I', ['B'], data.get('I')).add( 'G', [], data.get('G')).add('S', ['I', 'SM', 'G'], data.get('S')).add('M', ['S'], data.get('M'))) return bayes_net
def channels_list(token): tok_uid = data.get('tok_uid') channels = data.get('channels') if token is None: print('Not logged in') else: channels_2 = [] uid = tok_uid.get(token) for i in channels: id = i.get('channel_id') #will give access error if other user tried to access try: diction = channel_details(token, id) except: continue members = diction.get('all_members') for j in members: check_id = j.get('u_id') if check_id is uid: print(f'Channel {i}') ch_name = i.get('name') #name = diction.get('name') owners = diction.get('owner_members') members = diction.get('all_members') channels_2.append({'channel_id': id, 'name': ch_name}) print(f'Name of the channel {ch_name}') print(f'Owners of the channel {owners}') print(f'Members of the channel {members}') #for tests return {'channels': channels_2}
def message_edit(token, message_id, message): u_id = data.get('tok_uid')[token] message_det = get_message_details(message_id) # AccessError: authorised user was not the sender of message # AND authorised user is not an owner of the channel or a global owner if message_det['u_id'] != u_id and not is_global_owner( u_id) and not is_channel_owner(u_id, message_det['channel_id']): raise AccessError(description='User is not authorised to edit message') for channel in data['channels']: if channel['channel_id'] == message_det['channel_id']: for m in channel['messages']: if m['message_id'] == message_id: # if edit is empty, delete message if message == '': channel['messages'].remove(m) # else, update message string else: m['message'] = message return {}
def emoji_emotions_monthly(chat: data.Chat) -> {datetime.date: {str: int}}: """Returns for each month the chat was active, the per participant emotions conveyed by emojis. {month: {emotion: count}} """ months = all_months(chat) months.append(months[len(months) - 1] + datetime.timedelta( days=33)) # add an extra date for messages after last dt messages = emoji_messages(chat) # We go through the months and while the messages's date is smaller than the current month we add it to a dict # of {emotion: count}. msg_at represents where we are in the messages list so we don't have to start # over each time. output: {datetime.date: {str: int}} = {} msg_at = 0 for month_at in range(1, len(months)): month = months[ month_at] # we are currently adding emojis till this month data: {str: int} = {} # we go through the messages while msg_at < len(messages) and messages[msg_at].date.date() < month: msg = messages[msg_at] # get emoji object f_emoji_obj: FEmoji = facebook_emojis.get_emoji( emoji_map_to_str(msg)) # add one to all emotions this emoji conveys for emotion in f_emoji_obj.emotions: data[emotion] = data.get(emotion, 0) + 1 msg_at += 1 # we reached the end of the emojis that are before the current month output[months[month_at - 1]] = data return output
import random import time from data import data MAX_ITER = 10 INFEASIBLE = -1 LOCAL_SEARCH = 0 # 1-FI OR 2-BI BUSUSED = 0 ALPHA = 0 BUSES = data.get('numBuses') DRIVERS = data.get('numDrivers') SERVICES = data.get('numServices') MAX_BUSES = data.get('maxBuses') BM = data.get('BM') CBM = data.get('CBM') CEM = data.get('CEM') STARTTIME = data.get('startTime') MINUTESDURATION = data.get('minutesDuration') KMDURATION = data.get('kmDuration') PASSANGERS = data.get('passangers') CAPACITY = data.get('capacity') EUROSMIN = data.get('eurosMin') EUROSKM = data.get('eurosKm') MAXMINUTES = data.get('maxMinutes') #if DEBUG: # import pdb