def update_association(user_id, client_id, refresh_token_str): client = get_client(client_id) user = get_user(user_id) logging.warn('update_associations 1: ' + str(refresh_token_str)) refresh_token = get_token(client_id, client.secret, refresh_token_str) #always check to see if it is confidential or not. #it shouldn't be if it's using update_association, but you never know #and it's good to have a log message to possible alert the admin that #this is going on. if client.type.lower() != 'confidential': raise ConfidentailError('Client ' + client_id + \ ' is not a confidentail client') db = DB() try: key = 'client_association_' + str(user.id) if db.contains(key): association = db.get(key) if client.id in association.clients: logging.warn('update_associations 2: ' + str(association.clients[client.id])) old_refresh = get_token(client.id, client.secret, association.clients[client.id]) delete_token(old_refresh.access_token) delete_token(old_refresh.code) association.clients[client.id] = refresh_token.code logging.warn('update_associations 3: ' + str(refresh_token.code) + ', ' + str(association.clients[client.id])) db.update(key, association) db.commit() #except Exception, e: # logging.error('update_associations: ' + str(e)) # db.abort() finally: db.close() return False
def query(method, args={}, lana=False, timeout=None, verify_ssl=True, bot=None): pars = args pars['access_token'] = unicode(get_token(bot)) pars['v'] = args.get('v', '5.14') if lana == True: pars['access_token'] = unicode(get_token(bot)) prefix = 'https://api.vk.com/method/' if timeout is None: if method in ['messages.get']: timeout = 0.5 else: timeout = 2 try: r = requests.get(unicode(prefix + method), params=pars, timeout=timeout, verify=verify_ssl) except Exception as e: logger.error(str(e)) return None try: r = r.json() except: logger.error(u'Не получилось раскодировать json из ответа ВК.\n' + r.text) return None if r.get('error') is not None: return r elif r.get('response') is not None: return r else: print r.text logger.error(u'Непонятный ответ от ВК:\n' + r.text) return None
def tokenize(string, line_number=1, file_name=None, valid_tokens=BaseToken, keywords=KEYWORD_LOOKUP): tokens = [] start = 0 while start < len(string): match, token = get_token(string, start, valid_tokens) if match: # get the string value of the token end = match.end() value = string[start:end] if len(value) == 0: # somthing went wrong with getting the current token tokenizing_error(line_number, string, start, tokens) # if the token is an identifier, check if it's a keyword if token == BaseToken.IDENTIFIER: new_token = keywords.get(value.lower(), None) # if it's a keyword set the identifier to it if new_token: token = new_token tokens.append(Token(value, token, line_number, start, file_name)) start = end else: tokenizing_error(line_number, string, start, tokens) return tokens
def identify(self, user: UserOrId, **kwargs): """ Identify a single customer by their unique id, and optionally add attributes. """ data = user.to_csv() data.update( email=user.email, telegram=user.telegram, created_at=int(user.created_at.strftime('%s')), dob=int(user.dob.strftime('%s')) if user.dob else None, token=get_token(user.id), ) data.update(kwargs) return self.request('PUT', user, **data)
def load_token(self): """ load the bot's token """ # loads the token used by this specific bot try: assert self.name != "" self.token = get_token(self.name) except AssertionError: # if this is being raised, no name was given raise BotNotNamed() except FileNotFoundError: # if this is being raised, no token file was found raise NoTokenFound(self.name) return
def associate_client_with_user(user_id, client_id, refresh_token_str): """ Adds client to list of authorised clients who can access the users resources on a long term basis """ client = get_client(client_id) user = get_user(user_id) refresh_token = get_token(client.id, client.secret, refresh_token_str) ## before going further, see if client is confidential or not. ## If confidential then it is assumed to be able to keep the ## username and password secret from itself. If this is the ## case then it's allowed to continue, else throw a ## ConfindentialError. if client.type.lower() != 'confidential': client_id = refresh_token.client raise ConfidentailError('Client ' + client_id + \ ' is not a confidentail client') db = DB() try: key = 'client_association_' + str(user.id) if db.contains(key): association = db.get(key) if client.id not in association.clients: association.clients[client.id] = refresh_token.code db.update(key, association) else: raise AssociationExistsWarning(''.join(['Client ', str(client.id), ' is already associated with ', str(user.id)])) else: association = Association(user.id) association.clients[client.id] = refresh_token.code db.put(key, association) db.commit() except Exception, e: logging.error(''.join(['associate_client_with_user: ', str(e)])) raise e db.abort()
def to_json(self): return { 'address': self.address, 'city': self.city, 'state_code': self.state_code, 'zip_code': self.zip_code, 'country_code': self.country_code, 'dob': int(self.dob.strftime('%s')) if self.dob else None, 'email': self.email, # 'telegram': self.telegram, 'confirmed_location': self.confirmed_location, 'eth_address': self.eth_address, 'eth_amount': self.eth_amount, 'state': self.state, 'eth_cap': self.eth_cap, 'decline_reason': self.decline_reason, 'id': str(self.id), 'first_name': self.first_name, 'last_name': self.last_name, 'phone': self.phone, 'token': get_token(self.id), }
def test_valid_token_auth(service, user): res = service.get('/v1/user', auth=get_token(user.id)) assert res.status_code == 200
def start_scrapping(conn): x = conn.cursor() x.execute("TRUNCATE TABLE ico_links") x.execute("TRUNCATE TABLE icos") x.execute("TRUNCATE TABLE token_links") x.execute("TRUNCATE TABLE token_prices") x.execute("TRUNCATE TABLE tokens") x.execute("TRUNCATE TABLE twitter") x.execute("TRUNCATE TABLE facebook") ico_id = 0 for ico_url in ico_url_array: response = requests.get(ico_url) html = response.content content = BeautifulSoup(html, 'html.parser') table = content.find('div', attrs={ 'class': 'container-wrp container-fluid block-indent' }).findAll('div', attrs={'class': 'row'})[1] cnt = 0 # for ta in table: for row in table.find_all('div', attrs={'class': 'col-12 col-lg-6 col-xl-4'}): ico_id = ico_id + 1 ico_name = row.find( 'div', attrs={ 'class': 'flex-first cp-col-sm col-9 col-sm-9 cp-prj' }).find('h2').get_text() #insert token table token_name = re.sub(r"[\s]", r'-', ico_name) tokens.get_token(token_name) #end # insert ico_link social = row.find('div', attrs={'class': 'cp-social'}) for social_a in social.findAll('a'): ico_link = social_a['href'] social_name = social_a['title'] ico_links(conn, ico_id, ico_link, social_name) # end ico_link if (row.find('div', attrs={ 'class': 'cp-col col-9 col-sm-9 cp-info' }).find('div', attrs={'class': 'alert alert-danger'})): scam = "True" else: scam = "False" ico_desc = row.find('div', attrs={ 'class': 'cp-row-sm row cp-prj-descr' }).find('div', attrs={ 'class': 'cp-col-sm col-12' }).get_text() footer_part = row.find( 'div', attrs={ 'class': 'cp-row row cp-body' }).find('div', attrs={'class': 'cp-col col-9 col-sm-9 cp-info'}) # left part of bottome of title footer_part_left = footer_part.find( 'div', attrs={ 'class': 'cp-info-i' }).find('div', attrs={ 'class': 'cp-col-sm col-12 col-sm cp-what' }).findAll('div', attrs={'class': 'cp-line'}) base = footer_part_left[0].find('span', attrs={'class', 'text-black'}).get_text() if (footer_part_left[1].find('a', attrs={ 'target': '_blank', 'href': True })): whitepaper_url = footer_part_left[1].find('a', attrs={ 'target': '_blank', 'href': True })['href'] if (footer_part_left[2].find('i', attrs={'class', 'fa fa-close'})): escrow = "False" elif (footer_part_left[2].find( 'i', attrs={'class', 'fa fa-check text-warning'})): escrow = "True" footer_part_right = footer_part.find( 'div', attrs={ 'class': 'cp-info-i' }).find('div', attrs={ 'class': 'cp-col-sm col-12 col-sm cp-who' }).findAll('div', attrs={'class': 'cp-line'}) # getting homepage url homepage = footer_part_right[1].find('a', attrs={ 'target': '_blank', 'href': True })['href'] # getting ceo_name if (footer_part_right[2].find('span')): ceo_name = footer_part_right[2].find('span').get_text() else: ceo_name = '' # geeting ceo_link if (footer_part_right[2].find('a')): ceo_link = footer_part_right[2].find('a', attrs={ 'target': '_blank', 'href': True })['href'] else: ceo_link = '' if (scam == "False"): # getting ico_link if (footer_part.find('div', attrs={ 'class': 'cp-ico-o' }).find('a', attrs={ 'target': '_blank', 'href': True })): ico_link = footer_part.find('div', attrs={ 'class': 'cp-ico-o' }).find('a', attrs={ 'target': '_blank', 'href': True })['href'] else: ico_link = '' # getting amount and total aaa = footer_part.find('div', attrs={ 'class': 'cp-ico-o' }).find('span', attrs={ 'class': 'text-black' }).get_text() aaa = re.sub('[,]', '', aaa) ss = re.sub('[\d]', '', aaa) token = re.split(r"[\s]", aaa)[2] if (aaa == ss): amount = '' total = '' else: am = re.split(r"[\s]", aaa)[1] if (am == '~'): amount = '' total = re.split(r"[\s]", aaa)[4] else: amount = re.split(r"[\s]", aaa)[1] if (re.split(r"[\s]", aaa)[3] == '~'): total = '' else: total = re.split(r"[\s]", aaa)[4] # getting lauch, end, bonus, bitcoin if (footer_part.findAll('div', attrs={'class': 'cp-row-sm row'})): temp = footer_part.findAll( 'div', attrs={'class': 'cp-row-sm row'}) launch_end = temp[1].find('span', attrs={ 'class': 'text-black' }).get_text() if (bool(re.search(r'\d', launch_end))): launch = re.split(" UTC - ", launch_end)[0] ico_end = re.split(" UTC - ", launch_end)[1] else: launch = '' ico_end = '' bonus = temp[2].find('div', attrs={ 'class': 'cp-line' }).findAll('span', attrs={'class': 'text-black'})[0].get_text() # removing <text>B</text> temp[2].find('div', attrs={ 'class': 'cp-line' }).findAll('span', attrs={'class': 'text-black' })[1].find('text').decompose() bitcoin = temp[2].find('div', attrs={ 'class': 'cp-line' }).findAll('span', attrs={'class': 'text-black'})[1].get_text() else: launch = '' ico_end = '' bonus = '' bitcoin = '' if (row.find('div', attrs={ 'class': 'cp-row row cp-body' }).find('div', attrs={'class': 'cp-chart-digs font-alt'})): cp = row.find('div', attrs={ 'class': 'cp-row row cp-body' }).find('div', attrs={ 'class': 'cp-chart-digs font-alt' }).find('strong').get_text() if (bool(re.search(r'\d', cp)) == False): cp = '' else: cp = '' else: ico_link = '' amount = '' total = '' # Insert new employee x.execute( "INSERT INTO icos(id,ico_name,scam,ico_desc,base,whitepaper_url,escrow,homepage,ceo_name,ceo_link,ico_link,amount,total,launch,ico_end,bonus,bitcoin,cp,token) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (ico_id, ico_name, scam, ico_desc, base, whitepaper_url, escrow, homepage, ceo_name, ceo_link, ico_link, amount, total, launch, ico_end, bonus, bitcoin, cp, token)) conn.commit() cnt = cnt + 1 print("-------------------- ") if cnt >= 20: # db.close() break x.close()
def test_user_token(service): res = service.post('/v1/user', new_user()) assert res.status_code == 201, res.json user = User.objects.get() assert res.json['token'] == get_token(user.id)
def inner(user: User = None) -> str: return get_token(user.id if user else ObjectId())
get_val = "SELECT @val := password FROM password_vault WHERE pass_id = %s;" cursor.execute(get_val, view_id) encrypted_pass = cursor.fetchone() # decrypt password and print to console get_pass = "******" cursor.execute(get_pass, encrypted_pass) output = ''.join(cursor.fetchone()) sg.popup(output) if __name__ == "__main__": mydb = sql.connect( host='localhost', user='******', password=get_token(), database='password_manager' ) cursor = mydb.cursor() cursor.execute("SELECT * FROM password_vault") result = cursor.fetchall() sg.theme('Dark') app = [ [sg.Text("Password Manager", justification='center')], [sg.Table( values=result, headings=['pass_id', 'pass', 'app', 'url'], justification='center', def_col_width=100,
from telegram.ext import Updater, CommandHandler, MessageHandler, MessageFilter from tokens import get_token from message_filter import * from botActions import GolfilloActions as Gactions import logging logging.basicConfig( format='\n%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) updater = Updater(get_token()) dispatcher = updater.dispatcher dispatcher.add_handler(CommandHandler("tblop", Gactions.tblop)) dispatcher.add_handler(CommandHandler("list", Gactions.tblop)) dispatcher.add_handler(CommandHandler("oc", Gactions.oc)) dispatcher.add_handler(CommandHandler("ping", Gactions.ping)) dispatcher.add_handler(CommandHandler("gracies", Gactions.gracies)) dispatcher.add_handler(CommandHandler("f", Gactions.f)) dispatcher.add_handler(CommandHandler("papopepo", Gactions.papopepo)) dispatcher.add_handler(CommandHandler("pr", Gactions.pr)) dispatcher.add_handler(CommandHandler("flauta", Gactions.flauta)) dispatcher.add_handler(CommandHandler("hola", Gactions.hola)) dispatcher.add_handler(CommandHandler('scatman', Gactions.scatman)) dispatcher.add_handler(CommandHandler('viejotruco', Gactions.viejotruco)) dispatcher.add_handler(CommandHandler('lajungla', Gactions.lajungla)) dispatcher.add_handler(MessageHandler(porno(), Gactions.porno)) if __name__ == '__main__': updater.start_polling()
await join_money(bot, ctx.message.author) @money.command(name='pay', pass_context=True) async def _pay_money(ctx, user: discord.Member, amount: int): """Allows users to exchange money""" if amount < 0: await bot.reply("You can't pay someone a negative amount!") elif user == ctx.message.author: await bot.reply("You can't pay yourself!") else: await transfer(bot, ctx.message.author, user, amount) @money.command(name='claim', pass_context=True) async def _claim_daily_coins(ctx): """Collect a daily coin bonus""" await daily_coins(bot, ctx.message.author.id) # ===== COGS ===== # fun.setup(bot) music.setup(bot) useful.setup(bot) # ===== RUNTIME ===== # bot.run(get_token()) print("bot terminated...")
@money.command(name='join', pass_context=True) async def _join_money(ctx): """Allows a user to join the money system""" await join_money(bot, ctx.message.author) @money.command(name='pay', pass_context=True) async def _pay_money(ctx, user : discord.Member, amount : int): """Allows users to exchange money""" if amount<0: await bot.reply("You can't pay someone a negative amount!") elif user==ctx.message.author: await bot.reply("You can't pay yourself!") else: await transfer(bot, ctx.message.author, user, amount) @money.command(name='claim', pass_context=True) async def _claim_daily_coins(ctx): """Collect a daily coin bonus""" await daily_coins(bot, ctx.message.author.id) # ===== COGS ===== # fun.setup(bot) music.setup(bot) useful.setup(bot) # ===== RUNTIME ===== # bot.run(get_token()) print("bot terminated...")