def parse_cmd(cmd): print("cmd: {}".format(cmd)) if cmd[0] == "add user": users.add_user() elif cmd[0] == "show_all": try: users.list_employe(cmd[1], cmd[2]) except IndexError: try: users.list_employe(cmd[1], False) except IndexError: users.list_employe("code", False) elif cmd[0] == "del_all": users.delete_all_employe() elif cmd[0] == "find": try: users.find_user(cmd[1], cmd[2].capitalize()) except IndexError: print(UI_String.COMMAND_NOT_VALIDE.format(2)) elif cmd[0] == 'x': exit(0) else: print(UI_String.CMD_NOT_AVAILABLE)
def add_payment_method_endpoint(): content = request.form payment = content.get("payment") username, is_primary = content.get("username"), content.get("isprimary") is_primary = is_primary == "yes" user = find_user(username) if not user: dev = find_dev(username) if not dev: return "<h1> Error! </h1> <p> No account found with that username. </p>" if not username: return "<h1> Error! </h1> <p> You need to specify a username, and let us know if this is your primary method of payment. </p>" if not payment: return "<h1> Error ! </h1> <p> You need to specify a payment method. </p>" if payment == "CreditCard": cardnumber, cvc, expirydate = content.get("cardnumber"), content.get( "cvc"), content.get("expirydate") if not cardnumber or not cvc or not expirydate: return "<h1> Error! </h1> <p> You need to specify a card number, CVC and expiry date. </p>" return add_cc(username, is_primary, cardnumber, cvc, expirydate) elif payment == "Riseup": riseup_public_key = content.get('publickey') if not riseup_public_key: return "<h1> Error! </h1> <p> You need to specify a Riseup Public Key. </p>" return add_riseup(username, is_primary, riseup_public_key) elif payment == "Paypal": ppuser, pppass = content.get("ppusername"), content.get("pppassword") if not ppuser or not pppass: return "<h1> Error! </h1> <p> You need to specify a Paypal username and password. </p>" return add_paypal(username, is_primary, ppuser, pppass) else: return "<h1> Error! </h1> <p> You need to input a payment type. We support Riseup Wallet, Credit Card and Paypal.</p> " return add_payment_method()
def add_user_endpoint(): content = request.form if not content: return "<h1> Error! </h1><p>You need some form content</p>" username, password = content.get("username"), content.get("password") email, fullname = content.get("email"), content.get("name") user_from_db = find_user(username) if user_from_db: return "<h1> Error! </h1> Your username already has an account!" return add_user(username, password, email, fullname)
def user_page(name): """ Returns the user about page, with a larger user avatar and username along with the posts made by the user """ db = PsstDb() userpage = interface.post_list(db, name, 50) av = users.find_user(db, name) user = { 'login': has_visited(), 'usernamed': users.session_user(db), 'title': name, 'avatar': av[0][2], 'username': name, 'posts': userpage, 'follows': users.does_follow(db, users.session_user(db), name), 'following': users.get_following(db, users.session_user(db)) } return template('userPosts', user)
def main(): load() current_id = None while True: try: updates = bot.get_updates(offset=current_id).wait() or [] for update in updates: current_id = update.update_id + 1 msg = update.message _user = User( msg.sender.id, '%s %s' % (msg.sender.first_name, msg.sender.last_name)) add(_user) print('"%s" from %s' % (msg.text, _user.name)) handle(find_user(_user.id), msg) if not len(updates): time.sleep(0.1) except Exception as e: print(e)
def account(): if request.method == 'POST': return redirect('/') else: # User has to be read here to supply proper user data to be displayed. user_id = users.find_user(session['user']) user = users.read_user(user_id) # Here the function is looking for offers that this particular user has # published. published_offers_numbers = searching.find_all_published( session['user']) published_offers = [] for x in published_offers_numbers: try: published_offers.append(data.read_offer(x)) except: print x return render_template('account.html', user=user, published_offers=published_offers)
def main(): session = users.connect_db() id = int(input("Введите id пользователя (целое число):")) user = users.find_user(id, session) if user != None: find_athelete(user, session)
def botHook(): bot = telegram.Bot(TOKEN) update = telegram.update.Update.de_json(request.json, bot) if update.inline_query is not None and update.inline_query.query: # We've got an inline query tlkz = tsr.search_talkz(update.inline_query.query, 50) results = [] for t in tlkz: txt = '' if t[0] != -500: txt = t[1] # results.append(InlineQueryResultArticle(id = uuid4(), title = '(' + str(t[0]) + ') ' + t[2], input_message_content = InputTextMessageContent(txt), description = t[1])) results.append( InlineQueryResultArticle( id=uuid4(), title=txt, input_message_content=InputTextMessageContent(txt))) bot.answerInlineQuery(update.inline_query.id, results) return 'OK' if update.message is not None: # We've got a message global mAdd global command_message # global tstconf # logger.info('message: ' + update.message.text) if users.add_user(update.message.from_user.id, update.message.from_user.username, 'U', dt.date(1901, 1, 1), 'Added ' + dt.datetime.now().isoformat()): bot.sendMessage(chat_id=PAPAID, text='добавил копа. ' + update.message.from_user.username + ' (' + str(update.message.from_user.id) + ')') if update.message.location is not None: locz.add_loc(update.message) #logger.info('location %s, %s', update.message.location.longitude, update.message.location.latitude) return 'OK' if update.message.text == '/listusers': command_message = update.message if not users.usertype_is(update.message.from_user.id, 'O'): bot.sendMessage(chat_id=update.message.chat_id, text='Иди нухай, коп') return 'Access denied' bot.sendMessage(chat_id=update.message.chat_id, text=users.list_userz()) return 'OK' if isinstance(update.message.text, str): mtext = update.message.text command = mtext.split()[0] user_name = "" if len(mtext.split()) > 1: user_name = mtext.split()[1] if command == '/makeowner': if not (update.message.from_user.id == PAPAID): bot.sendMessage(chat_id=update.message.chat_id, text='иди нухай, коп. ты непапа') return 'Access denied' if users.change_attr(user_name, 'utype', 'O'): bot.sendMessage(chat_id=update.message.chat_id, text=users.str_user( users.find_user('uname', user_name))) return 'OK' else: bot.sendMessage(chat_id=update.message.chat_id, text='нету такого копа') return 'OK' if command == '/makemoder': if not (users.usertype_is(update.message.from_user.id, 'O') or update.message.from_user.id == PAPAID): bot.sendMessage(chat_id=update.message.chat_id, text='иди нухай, коп') return 'Access denied' if users.change_attr(user_name, 'utype', 'M'): bot.sendMessage(chat_id=update.message.chat_id, text=users.str_user( users.find_user('uname', user_name))) return 'OK' else: bot.sendMessage(chat_id=update.message.chat_id, text='нету такого копа') return 'OK' if command == '/makeuser': if not (users.usertype_is(update.message.from_user.id, 'O') or update.message.from_user.id == PAPAID): bot.sendMessage(chat_id=update.message.chat_id, text='иди нухай, коп') return 'Access denied' if users.change_attr(user_name, 'utype', 'U'): bot.sendMessage(chat_id=update.message.chat_id, text=users.str_user( users.find_user('uname', user_name))) return 'OK' else: bot.sendMessage(chat_id=update.message.chat_id, text='нету такого копа') return 'OK' if command == '/set': user_attr = mtext.split()[2] user_value = mtext[len(mtext.split()[0]) + len(mtext.split()[1]) + len(mtext.split()[2]) + 3:] if not (users.usertype_is(update.message.from_user.id, 'O') or update.message.from_user.id == PAPAID): bot.sendMessage(chat_id=update.message.chat_id, text='иди нухай, коп') return 'Access denied' if users.find_user('uname', user_name) is None: bot.sendMessage(chat_id=update.message.chat_id, text='нету такого копа') return 'Not found' if users.change_attr(user_name, user_attr, user_value): bot.sendMessage(chat_id=update.message.chat_id, text=users.str_user( users.find_user('uname', user_name))) return 'OK' else: bot.sendMessage(chat_id=update.message.chat_id, text='хуйню сказал, папаша') return 'Error' if update.message.text == '/add': command_message = update.message u = users.find_user('uid', update.message.from_user.id) if u is None or not (u['utype'] == 'O' or u['utype'] == 'M'): bot.sendMessage(chat_id=update.message.chat_id, text='иди нухай, коп') return 'Access denied' bot.sendMessage( chat_id=update.message.chat_id, text='Пезди давай. Но токо больше 10 букв и ченть новенькое') mAdd = True return 'OK' if update.message.text == '/del': command_message = update.message u = users.find_user('uid', update.message.from_user.id) if u is None or not (u['utype'] == 'O' or u['utype'] == 'M'): bot.sendMessage(chat_id=update.message.chat_id, text='иди нухай, коп') return 'Access denied' if tsr.last_message[0] == -1: bot.sendMessage(chat_id=update.message.chat_id, text='нехуя удалять') return 'OK' keyboard = [[ InlineKeyboardButton('удалить впезду "' + tsr.last_message[1] + '"', callback_data=tsr.last_message[0]) ], [InlineKeyboardButton("или нуево нахуй", callback_data=-1)]] reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text('Ну чо, ', reply_markup=reply_markup) return 'OK' if mAdd: mAdd = False res = tsr.add_talk(update.message.text) if res[0]: bot.sendMessage(chat_id=update.message.chat_id, text='зопомнел') logger.info('ADDTALK. User:%s in chat:%s added talk:%s', update.message.from_user, update.message.chat, update.message.text) else: if res[1]: txt = 'уже есть такая хуета: ' + res[1] else: txt = 'хуйню сказал, папаша' bot.sendMessage(chat_id=update.message.chat_id, text=txt) return 'OK' bot_called = False if update.message.text is not None: bot_called = (update.message.text.partition(' ')[0] in bot_aliases) if bot_called: message_text = update.message.text.partition(' ')[2] if message_text == 'локи': logger.info('локи') logger.debug('локи') lres = locz.select_locz(update.message.chat_id, update.message.from_user.id) if lres[0] == '|': bot.sendMessage( chat_id=update.message.chat_id, text= "http://maps.googleapis.com/maps/api/staticmap?size=800x800&path={0}" .format(lres[1:])) else: bot.sendMessage(chat_id=update.message.chat_id, text=lres) return 'OK' else: message_text = update.message.text if update.message.chat.type == 'private' or tsr.can_talk( update.message.chat.id) or (tsr.can_answer( update.message.chat.id) and bot_called): if message_text == '': bot.sendMessage(chat_id=update.message.chat_id, text='чево?') else: bot.sendMessage(chat_id=update.message.chat_id, text=tsr.search_talk(message_text)) return 'OK' if update.callback_query is not None: # We've got a callback query query = update.callback_query ndx = int(query.data) if ndx == -1: bot.edit_message_text(text='ну ок', chat_id=query.message.chat_id, message_id=query.message.message_id) else: tsr.last_message = (-1, '') res = tsr.del_talk(ndx) bot.edit_message_text(text='удалил "' + res + '"', chat_id=query.message.chat_id, message_id=query.message.message_id) logger.info( 'DELTALK. User:%s in chat:%s deleted talkid:%s talk:%s', command_message.from_user, query.message.chat, ndx, res) return 'OK'