Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
2,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. from Instagram.classes import accounts
  2. from Instagram.classes.engagement_tools.followliker import Followliker
  3.  
  4. from flask import Flask, render_template, request
  5.  
  6. command_dictionary = {"get account info": lambda username: accounts.get_account_info(username),
  7.  
  8.                       "add account": lambda username, password: accounts.add_account(username, password),
  9.                       "add": lambda: print('Available commands: \n'.join(["> {0}\n".format(command) for command in command_dictionary if "add" in command])),
  10.  
  11.                       "remove account": lambda username, password: accounts.remove_account(username, password),
  12.                       "remove": lambda: print('Available commands: \n'.join(["> {0}\n".format(command) for command in command_dictionary if "remove" in command])),
  13.                       }
  14.  
  15.  
  16. def execute(usr_input):
  17.     """ Finds and executes the appropriate command from the command dictionary based on user input """
  18.  
  19.     for entry in sorted(command_dictionary, key=len, reverse=True):
  20.  
  21.         split_entry = entry.split()
  22.         split_input = usr_input.split()
  23.  
  24.         usr_commands = split_input[:len(split_entry)]
  25.  
  26.         if usr_commands == split_entry:
  27.             """ user input has the correct operators for the entry function """
  28.  
  29.             entry_function_args = command_dictionary[entry].__code__.co_varnames
  30.             usr_function_args = split_input[len(split_entry):]
  31.  
  32.             if len(usr_function_args) == len(entry_function_args):
  33.                 """ user input has the correct number of arguments for the entry function """
  34.  
  35.                 command_dictionary[entry](*usr_function_args)
  36.                 break
  37.             else:
  38.                 print("Incorrect arg format, function '", entry, "' takes args:", entry_function_args)
  39.                 break
  40.     else:
  41.         print("No command could be extracted from:", split_input)
  42.  
  43.  
  44. account = accounts.Account("SquatCatalog", "Kek666420")
  45. fl = Followliker(account)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement