def service_ticket(): # M5 = [{ID_C + (T_A ou T_R) + S_R + N3}K_c_s + T_c_s] if 'K_c_s' not in variables: input('Error: K_c_s not defined.') return request = { 'ID_C': variables['ID_C'], 'T_A': variables['T_A'], 'S_R': variables['ID_S'], 'N3': ha.random(16) } request = json.dumps(request) print('------------------------------------------') print('Message:') print(request) encrypted_message, nonce, tag = ha.aes_encrypt(request, variables['K_c_s']) request = { 'encrypted_message': encrypted_message, 'nonce': nonce, 'tag': tag, } request = {'message': request, 'T_c_s': variables['T_c_s']} print('------------------------------------------') print('Saving M5 Service Ticket...') print(request) print('------------------------------------------') db.save_database('service_ticket', request) input('Press enter to return to the main menu.')
def run_main_reddit_loop(): global praw,database,upload_timer #Main loop the listens to new comments on some subreddit for c in praw.helpers.comment_stream(r, subreddit): if check_condition(c): if not database.is_in_db(c.id): submission = r.get_submission(submission_id=c.permalink) flat_comments = praw.helpers.flatten_tree(submission.comments) already_commented = False for comment in flat_comments: if str(comment.author) == secret_keys.reddit_username: database.add_to_database(c.id) database.save_database() already_commented = True break if not already_commented: bot_action(c) if (time.time() - upload_timer) > upload_timeout : upload_timer = time.time() print "Trying to send a comment" try: reddit_comment,msg = upload_queue[0] print reddit_comment.permalink,msg reddit_comment.reply(msg) upload_queue.pop() except: pass
def bot_action(c, verbose=True, respond=False): if verbose: img_url = c.link_url img_path = image_downloader.download_image(img_url) print 'link is : ', img_url, 'img_path is ',img_path #didn't mange to download photo if len(img_path) == 0: return img = cv2.imread(img_path) if img is not None: h,w = (img.shape[0],img.shape[1]) if h > MAX_IMAGE_HEIGHT or w > MAX_IMAGE_WIDTH: print '-----Resizing image!!------' ratio = float(w)/float(h) if h > MAX_IMAGE_HEIGHT: factor = float(h)/float(MAX_IMAGE_HEIGHT) else: factor = float(w)/float(MAX_IMAGE_WIDTH) img = cv2.resize(img,None,fx=1/factor, fy=1/factor, interpolation = cv2.INTER_CUBIC) print '---- after resize image shape is ----',img.shape cv2.imwrite(img_path,img,[cv2.IMWRITE_JPEG_QUALITY,40]) #if h > 1080 or w > 1920: # try: # c.reply("Sorry image is too big! we currently only support images as big as 1920x1080") # database.add_to_database(c.id) # database.save_database() # except: # return # return #1)Run DNN on the b&w image print 'Image downloaded and is ok' if useDNN: coloredImage = colorize.runDNN(img_path) else: coloredImage = img print 'after DNN' image_name = 'colorized_'+img_path cv2.imwrite(image_name,coloredImage) #2)Upload image print 'Uploading image' if args.replicate: uploaded_image_link = img_url else: uploaded_image_link = image_uploader.upload_image(image_name) #3)Reply to the one who summned the bot if uploaded_image_link is not None: msg = 'Hi I\'m colorizebot. I was trained to color b&w photos (not comics or rgb photos! Please do not abuse me :{}).\n\n This is my attempt to color your image, here you go : %s \n\n This is still a **beta-bot**. If you called the bot and didn\'t get a response, pm us and help us make it better. \n\n [For full explanation about this bot\'s procedure](http://whatimade.today/our-frst-reddit-bot-coloring-b-2/) | [code](https://github.com/dannyvai/reddit_crawlers/tree/master/redditBotColorize)'%(uploaded_image_link) try: res = c.reply(msg) database.add_to_database(c.id) database.save_database() except: upload_queue.append((c,msg)) traceback.print_exc()
if len(args) == 2: username = args[0] seed_password = args[1] if username not in database: print('Cadastrando novo usuario...') salt = ha.salt_generator() hashed_seed = ha.hash_password(seed_password) content = { 'senha_semente': ha.hash_password(hashed_seed + salt), 'salt': salt } db.insert(database, username, content) print('Usuario cadastrado com sucesso.') print('Salt: ' + (database[username])['salt']) print('Salvando base...') db.save_database(DATABASE, database) print('Base salva com sucesso.') else: print('Usuario ja cadastrado.') sys.exit() if len(args) == 1: username = args[0] if username not in database: print('Usuario nao cadastrado.') else: tokens = ha.generate_tokens((database[username])['senha_semente']) old_time = datetime.now().strftime('%H:%M') while (True): token = input('Digite o token: ') new_time = datetime.now().strftime('%H:%M')
if city_text == 'Не выбран' or city_text == 'любой': city = None else: city = city_text write_msg( event.user_id, f"Выполняем поиск с параметрами: Возраст - {age_text}, Пол - {gender_text}, Город - {city_text}, Семейное положение - {status_text}" ) new_search = VkSearch(age, gender, city, status) new_search.user_search() profile_user = show_profile() elif 'Нравится' in query: save_database(profile_user, 1) profile_user = show_profile() elif 'Не нравится' in query: save_database(profile_user, 0) profile_user = show_profile() elif 'Пропустить' in query: new_search.download_list_skipped(profile_user) profile_user = show_profile() elif 'Новые параметры' in query: write_msg( event.user_id, f"Измените ваши предпочтения. Просто введите новые параметры: возраст, город, пол, статус. Например: возраст 23, город Москва и т.п. Как только параметры будут заданы напишите Ок." ) else: write_msg(
sel = selectors.DefaultSelector() print('Starting TGS server at ' + HOST + ' port ' + str(PORT)) TGS_db = db.load_database('TGS_db') # Adds a new service via CLI params (add [service_name] [key]) try: if sys.argv[1] == 'add': service_name = str(sys.argv[2]) key = ha.hash(str(sys.argv[3])).decode('utf-8') print('Adding service - name: ' + service_name + ' key: ' + key[:4] + '***' + key[len(key) - 4:]) db.insert(TGS_db, service_name, key) db.save_database('TGS_db', TGS_db) except IndexError: print('No new service added.') def accept(sock, mask): os.system('clear') conn, addr = sock.accept() print('Client connected ' + str(addr)) conn.setblocking(False) conn.sendall(b'--- Welcome to the TGS Server. ---') sel.register(conn, selectors.EVENT_READ, worker)
sel = selectors.DefaultSelector() print('Starting AS server at ' + HOST + ' port ' + str(PORT)) AS_db = db.load_database('AS_db') # Adds a new client via CLI params (add [name] [password]) try: if sys.argv[1] == 'add': name = str(sys.argv[2]) password = ha.hash(str(sys.argv[3])).decode('utf-8') print('Adding client - name: ' + name + ' password: '******'***' + password[len(password) - 4:]) db.insert(AS_db, name, password) db.save_database('AS_db', AS_db) except IndexError: print('No new clients added.') def accept(sock, mask): os.system('clear') conn, addr = sock.accept() print('Client connected ' + str(addr)) conn.setblocking(False) conn.sendall(b'--- Welcome to the AS Server. ---') sel.register(conn, selectors.EVENT_READ, worker)