def Preferences(self): '''A function to output the preferences of the authenticated user.''' clrscr() banner() print('Preferences:') prefs = [] for pref, option in self.preferences().items(): prefs.append([pref, option]) for i in range(len(prefs) // 4): print(prefs[i][0], ':', prefs[i][1]) choice = gp( '''Enter your choice.[Y to see more prefs, U if you want to update any pref, any other key to return to profile]''' ) if choice.lower() == 'y': for i in range(len(prefs) // 4, len(prefs) // 2): print(prefs[i][0], ':', prefs[i][1]) elif choice.lower() == 'u': print('redirecting to reddit.com to update prefs...') time.sleep(1) LinkHandler('https://reddit.com/prefs') Scraper.User.main(self) else: Scraper.User.main(self) choice = gp( 'Enter you choice.[U if you want to update a pref, any other key to return to profile.]' ) if choice.lower() == 'y': for i in range( len(prefs) // 2, len(prefs) // 2 + len(prefs) // 4): print(prefs[i][0], ':', prefs[i][1]) elif choice.lower() == 'u': print('redirecting to reddit.com to update prefs...') time.sleep(1) LinkHandler('httpe://reddit.com/prefs') Scraper.User.main(self) else: Scraper.User.main(self) choice = gp( 'Enter your choice.[Y to see more prefs, U if you want to update any pref, any other key to return to profile.]' ) if choice.lower() == 'y': for i in range(len(prefs) // 2 + len(prefs) // 4, -1): print(prefs[i][0], ':', prefs[i][1]) #choice = gp('Do you want to update any pref?[U if yes]') #if choice.lower() == 'u': #print('redirecting to reddit.com to update prefs...') #time.sleep(1) #LinkHandler('https://reddit.com/prefs') #Scraper.User.main(self) #else: #Scraper.User.main(self) elif choice.lower() == 'u': print('redirecting to reddit.com to update prefs...') time.sleep(1) LinkHandler('https://reddit.com/prefs') Scraper.User.main(self) else: Scraper.User.main(self)
def BlockedUsers(self): '''A function to output the usernames of the users blocked by the authenticated user.''' if len(self.blocked()) == 0: print('You have not blocked any user.') else: for usr in self.blocked(): print('\t' + str(usr)) gp('Enter any key to go back.') Scraper.User.main(self)
def BlockedUsers(self): """A function to output the usernames of the users blocked by the authenticated user.""" if len(self.blocked()) == 0: print("You have not blocked any user.") else: for usr in self.blocked(): print("\t" + str(usr)) gp("Enter any key to go back.") Scraper.User.main(self)
def Changepsw(f): opwd = (hashlib.sha256( gp("Entez l ancien mot de passe: ").encode('utf-8')).hexdigest()) opwd = int(opwd[0:4], 16) f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, opwd) if f.verifyPassword() == True: npassword = hashlib.sha256( gp("Entez le nouveau mot de passe: ").encode('utf-8')).hexdigest() npassword = int(npassword[0:4], 16) f.setPassword(npassword)
def Preferences(self): """A function to output the preferences of the authenticated user.""" clrscr() banner() print("Preferences:") prefs = [] for pref, option in self.preferences().items(): prefs.append([pref, option]) for i in range(len(prefs) // 4): print(prefs[i][0], ":", prefs[i][1]) choice = gp( """Enter your choice.[Y to see more prefs, U if you want to update any pref, any other key to return to profile]""" ) if choice.lower() == "y": for i in range(len(prefs) // 4, len(prefs) // 2): print(prefs[i][0], ":", prefs[i][1]) elif choice.lower() == "u": print("redirecting to reddit.com to update prefs...") time.sleep(1) LinkHandler("https://reddit.com/prefs") Scraper.User.main(self) else: Scraper.User.main(self) choice = gp( "Enter you choice.[U if you want to update a pref, any other key to return to profile.]" ) if choice.lower() == "y": for i in range(len(prefs) // 2, len(prefs) // 2 + len(prefs) // 4): print(prefs[i][0], ":", prefs[i][1]) elif choice.lower() == "u": print("redirecting to reddit.com to update prefs...") time.sleep(1) LinkHandler("httpe://reddit.com/prefs") Scraper.User.main(self) else: Scraper.User.main(self) choice = gp( "Enter your choice.[Y to see more prefs, U if you want to update any pref, any other key to return to profile.]" ) if choice.lower() == "y": for i in range(len(prefs) // 2 + len(prefs) // 4, -1): print(prefs[i][0], ":", prefs[i][1]) elif choice.lower() == "u": print("redirecting to reddit.com to update prefs...") time.sleep(1) LinkHandler("https://reddit.com/prefs") Scraper.User.main(self) else: Scraper.User.main(self)
def main(self): '''The main menu for the subreddits class.''' clrscr() banner() choice = gp('''What do you want to do? [N] to show new subreddits. [P] to show popular subreddits. [S] to search for a subreddit by name/description. [B] to search for a subreddit by name. [T] to search for a subreddit by topic. [Q] to return to main menu\n''') if choice.lower() == 'n': Scraper.Subreddits.NewSubreddits(self) elif choice.lower() == 'p': Scraper.Subreddits.PopularSubreddits(self) elif choice.lower() == 's': Scraper.Subreddits.Search(self) elif choice.lower() == 'b': Scraper.Subreddits.SearchByName(self) elif choice.lower() == 't': Scraper.Subreddits.SearchByTopic(self) elif choice.lower() == 'q': print('Returning to main menu as requested...') time.sleep(1) else: print('Invalid choice entered. Try again...') time.sleep(1) Scraper.Subreddits.main(self)
def main(self): '''The main menu for the user class.''' link_karma_count = 0 comment_karma_count = 0 for item in self.karma().values(): link_karma_count += item['link_karma'] comment_karma_count += item['comment_karma'] clrscr() banner() print('Hello /u/' + str(self.me())) print('Karma count --> link karma : %d comment karma : %d\n\n' % (link_karma_count, comment_karma_count)) choice = gp('''Enter your choice to continue: [B] to display users you have blocked. [P] to display account preferences. [S] to display subreddits you have subscribed to. [Q] to go return to main menu.''') if choice.lower() == 'b': Scraper.User.BlockedUsers(self) elif choice.lower() == 'p': Scraper.User.Preferences(self) elif choice.lower() == 's': Scraper.User.Subscribed(self) elif choice.lower() == 'q': print('Returning to main menu as requested...') time.sleep(1) else: print('Invalid choice entered. Try again...') time.sleep(1) Scraper.User.main(self)
def get_commit_history(organization=None, username=None, password=None): """Return a DataFrame containing the commit history of all repos from organization. It returns a pandas DataFrame in which the columns are the repositories and the rows are the commits indexed by time. """ if not organization: organization = raw_input("Enter the name of the organization: ") if not username: username = raw_input("Enter your username: "******"Enter you password: "******"https://api.github.com/" GH_ORG_MEMBERS = BASE_URL + "orgs/{org}/members" GH_ORG_REPOS = BASE_URL + "orgs/{org}/repos" GH_ORG_REPO_COMMITS = BASE_URL + "repos/{org}/{repo}/commits" repos = requests.get(GH_ORG_REPOS.format(org = organization), auth = (username, password)).json() data = {} for repo in repos: name = repo.get('name') commits_list = requests.get(GH_ORG_REPO_COMMITS.format(org = organization, repo = name), auth = (username, password)).json() commits_messages = [] commits_dates = [] #If the Git repository is empty, it will return a dict containing the message: #{u'message': u'Git Repository is empty.'}, so we check that the returned #value is a list. if type(commits_list) == type(list()): for commit in commits_list: commits_messages.append(commit.get('commit').get('message')) commits_dates.append(parser.parse(commit.get('commit').get('author').get('date'))) data[name] = Series(commits_messages, index=commits_dates) return DataFrame(data)
def main(): """The main menu for reddit-cli.""" clrscr() banner() reddit = authenticate() scraper = Scraper(reddit) conf.CHOICE = gp( """Welcome to reddit-cli. What action do you want to perform? [P] to display profile. [S] to search for subreddits. [B] to browse a subreddit. [I] to open inbox. [Q] to quit.\n""") while True: if conf.CHOICE.lower() == "p": scraper.user.main() elif conf.CHOICE.lower() == "s": scraper.subreddits.main() elif conf.CHOICE.lower() == "b": subreddit = Subreddit(input("Enter the name of the subreddit:"), scraper) subreddit.main() elif conf.CHOICE.lower() == "i": scraper.inbox() elif conf.CHOICE.lower() == "q": quit_app() else: print("Invalid choice entered. Try again...") time.sleep(1) print_main()
def Unread(self): '''A function to output the unread messages of the user.''' unread = [] for item in self.unread(): unread.append(item) if len(unread) == 0: print('You have no unread messages.') time.sleep(1) Scraper.Inbox.main(self) mark_read = [] for msg in unread: print('Message id: ', str(msg)) print('Sent by:', msg.author.name) print('Subject:', msg.subject) print('Body:', msg.body) choice = gp( '''Enter [Y] if you want to mark this message as read. [B] if you want to block the sender. [D] if you want to delete this message. Any other key to continue.''') if choice.lower() == 'y': mark_read.append(msg) elif choice.lower() == 'b': msg.author.block() elif choice.lower() == 'd': msg.delete() Scraper.Inbox.MarkRead(self, mark_read) Scraper.Inbox.main(self)
def gen_key(output='mykey', length=2048, withpass=False): """ Generates a couple of RSA private / public keys Keywords arguments: output -- The prefix used for naming the keys length -- The length of the key """ if int(length) < 1024: log.error("[gen_key] insecure key size") return log.debug("[gen_key] genrate RSA key size {}".format(length)) try: key = rsa.generate(int(length)) except Exception as err: log.error("[gen_key] {}".format(err)) return priv_output = "{}_priv.pem".format(output) pub_output = "{}_pub.pem".format(output) with open(priv_output, 'wb') as private_key: if withpass: private_key.write(key.exportKey('PEM', passphrase=gp("Passphrase: "))) else: private_key.write(key.exportKey('PEM')) with open(pub_output, 'wb') as public_key: public_key.write(key.publickey().exportKey("PEM"))
def main(self): """The main menu for the user class.""" link_karma_count = 0 comment_karma_count = 0 for item in self.karma().values(): link_karma_count += item["link_karma"] comment_karma_count += item["comment_karma"] clrscr() banner() print("Hello /u/" + str(self.me())) print( "Karma count --> link karma : %d comment karma : %d\n\n" % (link_karma_count, comment_karma_count) ) choice = gp( """Enter your choice to continue: [B] to display users you have blocked. [P] to display account preferences. [S] to display subreddits you have subscribed to. [Q] to go return to main menu.""" ) if choice.lower() == "b": Scraper.User.BlockedUsers(self) elif choice.lower() == "p": Scraper.User.Preferences(self) elif choice.lower() == "s": Scraper.User.Subscribed(self) elif choice.lower() == "q": print("Returning to main menu as requested...") time.sleep(1) else: print("Invalid choice entered. Try again...") time.sleep(1) Scraper.User.main(self)
def main(self): """The main menu for the subreddits class.""" clrscr() banner() choice = gp( """What do you want to do? [N] to show new subreddits. [P] to show popular subreddits. [S] to search for a subreddit by name/description. [B] to search for a subreddit by name. [T] to search for a subreddit by topic. [Q] to return to main menu\n""" ) if choice.lower() == "n": Scraper.Subreddits.NewSubreddits(self) elif choice.lower() == "p": Scraper.Subreddits.PopularSubreddits(self) elif choice.lower() == "s": Scraper.Subreddits.Search(self) elif choice.lower() == "b": Scraper.Subreddits.SearchByName(self) elif choice.lower() == "t": Scraper.Subreddits.SearchByTopic(self) elif choice.lower() == "q": print("Returning to main menu as requested...") time.sleep(1) else: print("Invalid choice entered. Try again...") time.sleep(1) Scraper.Subreddits.main(self)
def gen_key(output='mykey', length=2048, withpass=False): """ Generates a couple of RSA private / public keys Keywords arguments: output -- The prefix used for naming the keys length -- The length of the key """ if int(length) < 1024: log.error("[gen_key] insecure key size") return log.debug("[gen_key] genrate RSA key size {}".format(length)) try: key = rsa.generate(int(length)) except Exception as err: log.error("[gen_key] {}".format(err)) return priv_output = "{}_priv.pem".format(output) pub_output = "{}_pub.pem".format(output) with open(priv_output, 'wb') as private_key: if withpass: private_key.write( key.exportKey('PEM', passphrase=gp("Passphrase: "))) else: private_key.write(key.exportKey('PEM')) with open(pub_output, 'wb') as public_key: public_key.write(key.publickey().exportKey("PEM"))
def RUN(arg): arg, ret = segregate(arg, keys(['and', 'then', ',']), 'hider') pwd = gp("Password:"******"{pwd}"') subprocess.getoutput('python "hider.py" "{}"'.format(pwd)) print(ret)
def main(): """The main menu for reddit-cli.""" while True: clrscr() banner() choice = gp( """Welcome to reddit-cli. What action do you want to perform? [P] to display profile. [S] to search for subreddits. [B] to browse a subreddit. [I] to open inbox. [Q] to quit.\n""") if choice.lower() == "p": Scraper.User.main(reddit.user) elif choice.lower() == "s": Scraper.Subreddits.main(reddit.subreddits) elif choice.lower() == "b": subreddit = input("Enter the name of the subreddit:") Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) elif choice.lower() == "i": Scraper.Inbox.main(reddit.inbox) elif choice.lower() == "q": quit() else: print("Invalid choice entered. Try again...") time.sleep(1)
def main(self): """The main menu for the subreddits class.""" clrscr() banner() choice = gp("""What do you want to do? [N] to show new subreddits. [P] to show popular subreddits. [S] to search for a subreddit by name/description. [B] to search for a subreddit by name. [T] to search for a subreddit by topic. [Q] to return to main menu\n""") if choice.lower() == "n": self.new_subreddit() elif choice.lower() == "p": self.popular_subreddits() elif choice.lower() == "s": self.search() elif choice.lower() == "b": self.search_by_name() elif choice.lower() == "t": self.search_by_topic() elif choice.lower() == "q": print("Returning to main menu as requested...") print_main() else: print("Invalid choice entered. Try again...") time.sleep(1) self.main()
def main(): '''The main menu for reddit-cli.''' while True: clrscr() banner() choice = gp( '''Welcome to reddit-cli. What action do you want to perform? [P] to display profile. [S] to search for subreddits. [B] to browse a subreddit. [I] to open inbox. [Q] to quit.\n''') if choice.lower() == 'p': Scraper.User.main(reddit.user) elif choice.lower() == 's': Scraper.Subreddits.main(reddit.subreddits) elif choice.lower() == 'b': subreddit = input('Enter the name of the subreddit:') Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) elif choice.lower() == 'i': Scraper.Inbox.main(reddit.inbox) elif choice.lower() == 'q': quit() else: print('Invalid choice entered. Try again...') time.sleep(1)
def main(self): """The main menu for the subreddit class.""" clrscr() banner() print("Welcome to /r/{}".format(self.display_name)) print("Id of subreddit: ".format(self.id)) print("No. of subscribers: {}".format(self.subscribers)) if self.user_is_banned: print("You're banned from this subreddit.") if self.user_is_moderator: print("You're a moderator of this subreddit.") if self.user_is_subscriber: print("You're subscribed to this subreddit.") choice = gp( "\nWhat do you want to do here?\n" + "[h] to display hot submissions.\n" + "[n] to display new submissions.\n" + "[t] to display top submissions.\n" + "[q] to go back to main menu.\n" ).lower() sort_types = { "h": {"txt": "hot", "func": self.hot}, "t": {"txt": "top", "func": self.top}, "n": {"txt": "new", "func": self.new}, } if choice in sort_types: Scraper.Subreddit.show_posts(self, sort_types[choice]) elif choice == "q": print("Returning to main menu as requested...") time.sleep(1) else: print("Invalid choice entered. Try again...") time.sleep(1) Scraper.Subreddit.main(self)
def Unread(self): """A function to output the unread messages of the user.""" unread = [] for item in self.unread(): unread.append(item) if len(unread) == 0: print("You have no unread messages.") time.sleep(1) Scraper.Inbox.main(self) mark_read = [] for msg in unread: print("Message id: ", str(msg)) print("Sent by:", msg.author.name) print("Subject:", msg.subject) print("Body:", msg.body) choice = gp( """Enter [Y] if you want to mark this message as read. [B] if you want to block the sender. [D] if you want to delete this message. Any other key to continue.""" ) if choice.lower() == "y": mark_read.append(msg) elif choice.lower() == "b": msg.author.block() elif choice.lower() == "d": msg.delete() Scraper.Inbox.MarkRead(self, mark_read) Scraper.Inbox.main(self)
def print_main(): clrscr() banner() conf.CHOICE = gp(""" [P] to display profile. [S] to search for subreddits. [B] to browse a subreddit. [I] to open inbox. [Q] to quit.\n""")
def Subscribed(self): """A function to output the subreddits the authenticated user has subscribed to.""" for subreddit in self.subreddits(): print("\t", subreddit) choice = gp("\n\nEnter [Y] if you want to open a subreddit.") if choice.lower() == "y": subreddit = input("Enter the name of the subreddit: ") Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.User.main(self)
def change_pin(Pin, address): clear = ('cls' if os.name == 'nt' else 'clear') os.system(clear) pin_count = 0 print(":: Create Your Own Pin....::") while pin_count != 3: print(":: Entries left :", (3 - pin_count), "::") pin = str(gp("Enter 4-Digit Pin : ")) os.system(clear) if (len(pin) == 4) and (pin.isdigit() == True): if not pin == Pin: os.system(clear) confirm_pin = str(gp("Confirm Pin : ")) if pin == confirm_pin: Pin = pin os.system(clear) MSG = "You Have Successfully Changed Your Pin" msg = sendmail(address, MSG) os.system(clear) if not (msg == True): print(msg) print(':: Pin Changed Successfully! ::\n') return (Pin) else: os.system(clear) print(":: Pin Change Unsuccessful! ::") print(":: Your Pin Did Not Match! ::\n") pin_count += 1 else: pin_count += 1 os.system(clear) print(":: Pin Change Unsuccessful! ::") print(":: Please Enter A New Pin ::\n") else: pin_count += 1 os.system(clear) print(":: Pin Change Unsuccessful! ::") print(":: Invalid Pin! ::\n") return (Pin)
def Subscribed(self): '''A function to output the subreddits the authenticated user has subscribed to.''' for subreddit in self.subreddits(): print('\t', subreddit) choice = gp('\n\nEnter [Y] if you want to open a subreddit.') if choice.lower() == 'y': subreddit = input('Enter the name of the subreddit: ') Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.User.main(self)
def PopularSubreddits(self): '''A function to output 10 most popular subreddits.''' print('Most popular subreddits right now are:') for subreddit in self.popular(limit=10): print('\t', subreddit) choice = gp('\n\nEnter [Y] if you want to open a subreddit.') if choice.lower() == 'y': subreddit = input('Enter the name of the subreddit: ') Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.Subreddits.main(self)
def PopularSubreddits(self): """A function to output 10 most popular subreddits.""" print("Most popular subreddits right now are:") for subreddit in self.popular(limit=10): print("\t", subreddit) choice = gp("\n\nEnter [Y] if you want to open a subreddit.") if choice.lower() == "y": subreddit = input("Enter the name of the subreddit: ") Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.Subreddits.main(self)
def NewSubreddits(self): '''A function to output 10 newest subreddits.''' print('Newest subreddits are:') for subreddit in self.new(limit=10): print('\t', subreddit) choice = gp('\n\nEnter [Y] if you want to open a subreddit.') if choice.lower() == 'y': subreddit = input('Enter the name of the subreddit:') Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.Subreddits.main(self)
def NewSubreddits(self): """A function to output 10 newest subreddits.""" print("Newest subreddits are:") for subreddit in self.new(limit=10): print("\t", subreddit) choice = gp("\n\nEnter [Y] if you want to open a subreddit.") if choice.lower() == "y": subreddit = input("Enter the name of the subreddit:") Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.Subreddits.main(self)
def popular_subreddits(self): """A function to output 10 most popular subreddits.""" print("Most popular subreddits right now are:") for subreddit in self.subreddits.popular(limit=10): print("\t", subreddit) choice = gp("\n\nEnter [Y] if you want to open a subreddit.") if choice.lower() == "y": subreddit = Subreddit(input("Enter the name of the subreddit: "), self.scraper) subreddit.main() else: self.main()
def new_subreddit(self): """A function to output 10 newest subreddits.""" print("Newest subreddits are:") for subreddit in self.subreddits.new(limit=10): print("\t", subreddit) choice = gp("\n\nEnter [Y] if you want to open a subreddit.") if choice.lower() == "y": subreddit = Subreddit(input("Enter the name of the subreddit:"), self.scraper) subreddit.main() else: self.main()
def getInfoPrompt(self, name, silent=False): if not getattr(self, name): section = name.split("_")[0] value = " ".join(name.split("_")[1:]) prompt = "{} {}> ".format(section.upper(), value.title()) if silent: info = gp(prompt) else: info = raw_input(prompt) setattr(self, name, info) return getattr(self, name)
def passwordsetup(): from getpass import getpass as gp passmatch = False passcount = 0 passfinal = "" while not passmatch and passcount < 3: password_try1 = gp() password_try2 = gp() if password_try1 == password_try2: print "Your password has been set" passfinal = password_try2 passmatch = True elif passcount < 2: print "Sorry, those passwords did not match, try again" passcount = passcount + 1 else: print "Sorry, you clearly can't type. go home." return passfinal
def get_key_length(privatekey, withpass=False): """ Returns the length of a private key Keywords arguments: privatekey -- The file containing the private key withpass -- The key is encrypted with a passphrase """ try: priv_key = open(privatekey).read() except Exception as err: log.error("[get_key_length] {}".format(err)) else: if withpass: rsa_key = rsa.importKey(priv_key, passphrase=gp("Passphrase: ")) else: rsa_key = rsa.importKey(priv_key) return rsa_key.size()
def verify_user(): """ Get username and password from user. Currently unused function. Make an https/ssl POST request. Will return with embedded user-token to be used throughout site. Afterwards, return the user-token to invoking function. """ username = "******" # TODO: Uncomment following line # username = raw_input('Username: ') password = gp() data = "login={}&password={}".format(username, password) secureHTTPS = "https://8tracks.com/" verify = requests.post(secureHTTPS + "sessions.json", data=data) parsed_response = json.loads(verify.content) return parsed_response[u"user_token"]
def SearchByName(self): """A function to search for subreddits by name.""" query = input("Enter the name of the subreddit you want to search for:") print("Search results:") try: for subreddit in self.search_by_name(query): print("\t", subreddit) except: print("Subreddit not found!") time.sleep(1) Scraper.Subreddits.main(self) choice = gp("\nEnter [Y] if you want to open any of the above subreddits.") if choice.lower() == "y": subreddit = input("Enter the name of the subreddit:") Scraper.Subreddit.main(init_subreddit(reddit, subreddit)) else: Scraper.Subreddits.main(self)
def chkconfig(self): home = self.home # XXX cname = os.path.join(home, 'config') if not os.path.isdir(home): os.mkdir(home) os.chdir(home) config = cp() config.read(cname) changed = False if not config.has_section("user"): config.add_section("user") try: username = config.get("user", "username") except configparser.NoOptionError: username = input("Username: "******"user", "password") except configparser.NoOptionError: password = gp() changed = True if changed == True: config.set("user", "password", password) config.set("user", "username", username) mask = os.umask(0o077) config.write(open(cname, 'w')) os.umask(mask) # mask off global read print("Wrote configuration ({}).".format(cname)) print("If you need to change your") print("details, please edit this file.") print() self.username = username self.password = password self.protocol = 1 self.clientver = 0.1 self.client = "pyvndb"
def gen_pwd(user, web, masterpwd, strip=6, private=None, masteronfile=False, version=-1, withpass=False): """ Generates a password for the couple user/website Keywords arguments: user -- The username web -- The website masterpwd -- The master password to be used to gen the password, if masteronfile is true, then masterpwd is the file containing the master password strip -- The number of characters to be used in each slice of the password (default 4) private -- The private key used to decrypt an encrypted masterpwd encoded in b64 (default None) masteronfile -- Means that the masterpwd is on a file (default False) """ if masteronfile: masterpwd = open(masterpwd, 'r').read() if private is not None: try: priv_file = open(private, 'r') except Exception as err: log.error("[gen_pwd] {}".format(err)) else: priv_key = priv_file.read() if withpass: try: rsa_key = rsa.importKey(priv_key, passphrase = gp("passphrase: ")) except Exception as err: print("Error while importing the private key, the passphrase is probably wrong.") print(err) raise ValueError("Problem while decrypting the private key") return else: rsa_key = rsa.importKey(priv_key) cipher = pkcs.new(rsa_key) masterpwd = base64.b64decode(masterpwd) masterpwd = cipher.decrypt(masterpwd).decode('utf-8') priv_file.close() if len(masterpwd) < 3: log.error("[gen_pwd] The master password you gave is too short") return if len(masterpwd) < 10: log.warning("[gen_pwd] The master password you gave is short, please consider using a longer one") sym1 = masterpwd[-2] sym2 = masterpwd[-1] masterpwd = masterpwd[:-2] h = sha.new() h.update(masterpwd.encode('utf-8')) h.update(user.encode('utf-8')) h.update('@'.encode('utf-8')) h.update(web.encode('utf-8')) # This allows us to generate multiple passwords with the same couples if version >= 0: h.update(masterpwd[version % len(masterpwd)].encode('utf-8')) digest = h.hexdigest() return "{}{}{}{}{}".format( digest[:strip].upper(), sym1, digest[ int(len(digest) / 2) - int(strip / 2): int(len(digest) / 2) + int(strip / 2) ], sym2, digest[-strip:].lower() )
from core.tor.Handlers import Tor, HTMLHandler from getpass import getpass as gp passwd = gp("Pass: "******"http://c3jemx2ube5v5zpg.onion/", raw=False) elements = html.getElements() #print(elements) print(elements['title']) #for a in elements['div']: # print "[+] ", a for repeater in tor.getRepeaters(): print(repeater['address'])
def get_move_for_player(name): move = gp(prompt_msg.format(name)).lower() while not move in valid_moves: print invalid_msg.format(name) move = gp(prompt_msg.format(name)).strip().lower() # Remove whitespace and lower the case return Move(move) # Create a move class