Skip to content

Commit

Permalink
Merge pull request #1 from m1chaelbarry/rich
Browse files Browse the repository at this point in the history
Moved from Clint to Rich for CLI menus
  • Loading branch information
m1chaelbarry authored Jan 30, 2022
2 parents d8cc7d1 + 96a3244 commit 07e83d6
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 121 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dist
test.py
*.log
api-key.txt
.vscode
.vscode
.env
70 changes: 39 additions & 31 deletions RegisterMegaAcc.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import os, re, time, sys, http.client, string, random
from clint import resources
from clint.textui import prompt
import os, re, time, sys, http.client, string, random, dotenv
from rich import print
from rich.prompt import Prompt

dotenv.load_dotenv()
Mailsac_Api_Key = os.getenv('API_KEY')
def SetApiKey():
Api_Key = Prompt.ask("Enter your api key")
file = open('.env', 'w+')
file.close()
dotenv.set_key('.env', 'API_KEY', Api_Key)
os.environ['API_KEY'] = Api_Key
global Mailsac_Api_Key
Mailsac_Api_Key = Api_Key
CheckApiKey(Api_Key)

def CheckApiKey(api_key=os.getenv('API_KEY')):
conn = http.client.HTTPSConnection("mailsac.com")

headersList = {
"Mailsac-Key": api_key
}

resources.init('michaelbarry', 'MegaClone')
payload = ""

conn.request("GET", "/api/me", payload, headersList)
response = conn.getresponse()
result = response.read().decode("utf-8")

if resources.user.read('api-key.txt') == None or '':
print('You dont have api key set.')
print('%s created.' % resources.user.path)
Mailsac_Api_Key = prompt.query("Your api key >>")
resources.user.write('api-key.txt', Mailsac_Api_Key)
if result == "null":
print('Your api key is: [red]invalid[/red]')
SetApiKey()

Mailsac_Api_Key = resources.user.read('api-key.txt').strip()

def id_generator(size=6, chars=string.ascii_letters + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
Expand Down Expand Up @@ -76,7 +95,7 @@ def logout():
def AppendToFile():
gen_email, gen_password = register()
readable = f'{gen_email}:{gen_password}\n'
print(f'{gen_email}:{gen_password}')
print(f'[cyan]{gen_email}:{gen_password}[/cyan]')
file_object = open('creds.txt', 'a')
file_object.write(readable)
file_object.close()
Expand All @@ -90,29 +109,12 @@ def get_verify_link(_gen_email):
get_verify_link(_gen_email)
return(link)

def CheckApi(api_key):
conn = http.client.HTTPSConnection("mailsac.com")

headersList = {
"Mailsac-Key": api_key
}

payload = ""

conn.request("GET", "/api/me", payload, headersList)
response = conn.getresponse()
result = response.read().decode("utf-8")

if result == "null":
return False
else:
return True


def register():
if CheckApi(Mailsac_Api_Key) == False:
print('api key doesnt work')
exit()


CheckApiKey(Mailsac_Api_Key)
startcmdserver()
logout()
gen_email, gen_password = generateCreds()
Expand All @@ -123,6 +125,12 @@ def register():
return(Credentials)

if __name__ == "__main__":
if os.getenv('API_KEY') == None:
print('[bold red]You dont have api key set.[/bold red]')
SetApiKey()
else:
print('Your api key is: [bold green]valid[/bold green]')

if len(sys.argv) == 2:
amount = int(sys.argv[1])
for _ in range(amount):
Expand Down
26 changes: 19 additions & 7 deletions clone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from RegisterMegaAcc import ExtractURL, register
import os, sys
from rich import print
from rich.spinner import Spinner
from rich.live import Live



Expand All @@ -22,7 +25,7 @@ def import_file(link):
def export_file(filename):
stream = os.popen(f'mega-export -a -f "{filename}"')
output = stream.read()
print(output)
# print(output)
return(output)

def mega_ls():
Expand All @@ -32,19 +35,28 @@ def mega_ls():

def clone(_link, _email, _password):
# os.popen('$env:PATH += ";$env:LOCALAPPDATA\MEGAcmd"')
print('Logging in...')
# print('Logging in...')
login(_email, _password)
print('Importing file...')
# print('Importing file...')
import_file(_link)
filename = str(mega_ls()).strip("'")
print(filename)
# print(filename)
mirror_link = ExtractURL(export_file(filename))
print('Logging out...')
# print('Logging out...')
logout()
return(mirror_link)


if __name__ == "__main__":
link = sys.argv[1]
email, password = register()
clone(link, email, password)
link_stripped = link.strip("'\"")
with Live(Spinner('dots', text='Registering account...', style='blue'), refresh_per_second=20, transient=True):
while True:
email, password = register()
break
with Live(Spinner('dots', text='Cloning...', style='blue'), refresh_per_second=20, transient=True):
while True:
exported = clone(link, email, password)
break
print()
print(f'[cyan]Cloned link: {exported}[/cyan]')
132 changes: 69 additions & 63 deletions megaclone.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,100 @@
from clint.textui import prompt, puts, colored, indent
from clint import resources
from RegisterMegaAcc import register
from RegisterMegaAcc import register, CheckApiKey, SetApiKey
from clone import clone
from upload import upload
import dotenv
from rich import print
from rich.prompt import Prompt, IntPrompt
from rich.spinner import Spinner
from rich.live import Live

resources.init('michaelbarry', 'MegaClone')

def checkApiKey():
Mailsac_Api_Key = resources.user.read('api-key.txt').strip()
if resources.user.read('api-key.txt') == None:
Mailsac_Api_Key = prompt.query("Your api key >>")
print('%s created.' % resources.user.path)
resources.user.write('api-key.txt', Mailsac_Api_Key)

dotenv.load_dotenv()

def Logo():
print()
puts(colored.red('$$\ $$\ $$$$$$\ $$\ '))
puts(colored.red('$$$\ $$$ | $$ __$$\ $$ | '))
puts(colored.red('$$$$\ $$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$ / \__|$$ | $$$$$$\ $$$$$$$\ $$$$$$\ '))
puts(colored.red('$$\$$\$$ $$ |$$ __$$\ $$ __$$\ \____$$\ $$ | $$ |$$ __$$\ $$ __$$\ $$ __$$\ '))
puts(colored.red('$$ \$$$ $$ |$$$$$$$$ |$$ / $$ | $$$$$$$ |$$ | $$ |$$ / $$ |$$ | $$ |$$$$$$$$ |'))
puts(colored.red('$$ |\$ /$$ |$$ ____|$$ | $$ |$$ __$$ |$$ | $$\ $$ |$$ | $$ |$$ | $$ |$$ ____|'))
puts(colored.red('$$ | \_/ $$ |\$$$$$$$\ \$$$$$$$ |\$$$$$$$ |\$$$$$$ |$$ |\$$$$$$ |$$ | $$ |\$$$$$$$\ '))
puts(colored.red('\__| \__| \_______| \____$$ | \_______| \______/ \__| \______/ \__| \__| \_______|'))
puts(colored.red(' $$\ $$ | '))
puts(colored.red(' \$$$$$$ | '))
puts(colored.red(' \______/ '))
print('[bold blue]$$\ $$\ $$$$$$\ $$\ [/bold blue]')
print('[bold blue]$$$\ $$$ | $$ __$$\ $$ | [/bold blue]')
print('[bold blue]$$$$\ $$$$ | $$$$$$\ $$$$$$\ $$$$$$\ $$ / \__|$$ | $$$$$$\ $$$$$$$\ $$$$$$\ [/bold blue]')
print('[bold blue]$$\$$\$$ $$ |$$ __$$\ $$ __$$\ \____$$\ $$ | $$ |$$ __$$\ $$ __$$\ $$ __$$\ [/bold blue]')
print('[bold blue]$$ \$$$ $$ |$$$$$$$$ |$$ / $$ | $$$$$$$ |$$ | $$ |$$ / $$ |$$ | $$ |$$$$$$$$ |[/bold blue]')
print('[bold blue]$$ |\$ /$$ |$$ ____|$$ | $$ |$$ __$$ |$$ | $$\ $$ |$$ | $$ |$$ | $$ |$$ ____|[/bold blue]')
print('[bold blue]$$ | \_/ $$ |\$$$$$$$\ \$$$$$$$ |\$$$$$$$ |\$$$$$$ |$$ |\$$$$$$ |$$ | $$ |\$$$$$$$\ [/bold blue]')
print('[bold blue]\__| \__| \_______| \____$$ | \_______| \______/ \__| \______/ \__| \__| \_______|[/bold blue]')
print('[bold blue] $$\ $$ | [/bold blue]')
print('[bold blue] \$$$$$$ | [/bold blue]')
print('[bold blue] \______/ [/bold blue]')
print()
puts(colored.red('Version: 0.2.2'))
print('[blue]Version: 0.3.0[/blue]')
print()

def reg_handler():
with indent(5, quote=colored.cyan(' |')):
puts(f'Registering Mega Account...')
email, password = register()
with indent(5, quote=colored.cyan(' |')):
puts(colored.magenta(f'Email: {email}'))
puts(colored.magenta(f'Password: {password}'))
with Live(Spinner('dots', text='Generating Mega account...', style='blue'), refresh_per_second=20, transient=True):
while True:
email, password = register()
break
print()
print(f'[cyan]Email: {email}[/cyan]')
print(f'[cyan]Password: {password}[/cyan]')
menu()

def api():
Mailsac_Api_Key = prompt.query("Your api key >>")
resources.user.write('api-key.txt', Mailsac_Api_Key)
menu()

def clone_handler():
link = prompt.query("Mega link >>")
email, password = register()
mirror_link = clone(link, email, password)
with indent(5, quote=colored.cyan(' |')):
puts(colored.magenta(f'Mega link: {mirror_link}'))
link = Prompt.ask("Mega link")
with Live(Spinner('dots', text='Generating Mega account...', style='blue'), refresh_per_second=20, transient=True):
while True:
email, password = register()
break
with Live(Spinner('dots', text='Cloning link...', style='blue'), refresh_per_second=20, transient=True):
while True:
mirror_link = clone(link, email, password)
break
print()
print(f'[cyan]Mega link: {mirror_link}[/cyan]')
menu()

def upload_handler():
link = (prompt.query("Path to file/dir to upload >>")).strip("'\"")
with indent(5):
puts(colored.red('Generating original account...'))
Oemail,Opassword = register()
with indent(5):
puts(colored.red('Generating mirror account...'))
Memail, Mpassword = register()
exported, mirrored = upload(link, Oemail, Opassword, Memail, Mpassword)
with indent(5, quote=colored.cyan(' |')):
puts(colored.magenta(f'Original link: {exported}'))
puts(colored.magenta(f'Mirror link: {mirrored}'))
path = (Prompt.ask("Path to file/dir to upload")).strip("'\"")
with Live(Spinner('dots', text='Registering original account...', style='blue'), refresh_per_second=20, transient=True):
while True:
Oemail,Opassword = register()
break
with Live(Spinner('dots', text='Registering mirror account...', style='blue'), refresh_per_second=20, transient=True):
while True:
Memail, Mpassword = register()
break
exported, mirrored = upload(path, Oemail, Opassword, Memail, Mpassword)
print()
print(f'[cyan]Original link: {exported}[/cyan]')
print(f'[cyan]Mirror link: {mirrored}[/cyan]')
menu()

def menu():
inst_options = [{'selector':'1','prompt':'Register Mega account','return':'reg'},
{'selector':'2','prompt':'Clone link to new account','return':'clone'},
{'selector':'3','prompt':'Upload file/dir to new account, then import it to another','return':'upload'},
{'selector':'4','prompt':'change your api key','return':'api'},
{'selector':'q','prompt':'quit','return':'quit'}]
inst = prompt.options("Choose option:", inst_options)
print()
print('[blue][1][/blue] Register Mega account')
print('[blue][2][/blue] Clone link to new account')
print('[blue][3][/blue] Upload file/dir to new account, then import it to another')
print('[blue][4][/blue] Change your API key')
print('[blue][5][/blue] Exit')
print()

option = IntPrompt.ask('Choose option')

if inst == 'reg':
if option == 1:
reg_handler()
elif inst == 'clone':
elif option == 2:
clone_handler()
elif inst == 'upload':
elif option == 3:
upload_handler()
elif inst == 'api':
api()
elif inst == 'quit':
elif option == 4:
SetApiKey()
menu()
elif option == 5:
print('[bold blue]Goodbye!')
exit()

if __name__ == "__main__":
Logo()
checkApiKey()
CheckApiKey()
print('Your api key is: [bold green]valid[/bold green]')
menu()


3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
clint
rich
python-dotenv
Loading

0 comments on commit 07e83d6

Please sign in to comment.