def test(): # user details email = "*****@*****.**" password = "******" mega = Mega() # login m = mega.login(email, password) # get user details details = m.get_user() print(details) # get account files files = m.get_files() print(files) # upload file print(m.upload("test.py")) # trash a file, by id or url # print(m.delete('f14U0JhD')) # print(m.delete_url('https://mega.co.nz/#!f14U0JhD!S_2k-EvB5U1N3s0vm3I5C0JN2toHSGkVf0UxQsiKZ8A')) # download file, by id+key or url # m.download('6hBW0R4a','By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00') m.download_url("https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00")
def test(): """ Enter your account details to begin comment/uncomment lines to test various parts of the API see readme.md for more information """ #user details email = '*****@*****.**' password = '******' mega = Mega() #mega = Mega({'verbose': True}) # verbose option for print output # login m = mega.login(email, password) # get user details details = m.get_user() print(details) # get account files files = m.get_files() # get account disk quota in MB print(m.get_quota()) # get account storage space print(m.get_storage_space()) # example iterate over files for file in files: print(files[file]) # upload file print(m.upload('examples.py')) # search for a file in account file = m.find('examples.py') if file: # get public link link = m.get_link(file) print(link) # download file. by file object or url print m.download(file, '/tmp') #m.download_url(link) #delete or destroy file. by id or url print(m.delete(file[0])) #print(m.destroy(file[0])) #print(m.delete_url(link)) #print(m.destroy_url(link)) # empty trash print(m.empty_trash())
def test(): #user details email = '*****@*****.**' password = '******' mega = Mega() #login m = mega.login(email, password) #get user details details = m.get_user() print(details) #get account files files = m.get_files() #example iterate over files for file in files: if files[file]['a'] != False: print files[file] #upload file print(m.upload('test.py')) #trash a file, by id or url #print(m.delete('f14U0JhD')) #print(m.delete_url('https://mega.co.nz/#!f14U0JhD!S_2k-EvB5U1N3s0vm3I5C0JN2toHSGkVf0UxQsiKZ8A')) #download file, by id+key or url #m.download('6hBW0R4a','By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00') m.download_url('https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00')
def __init__(self, *args, **kwargs): usuario, senha = settings.MEGA['email'], settings.MEGA['password'] mega = Mega({'verbose': True}) self.m = mega.login(usuario, senha) super(Command, self).__init__(*args, **kwargs)
def test(): # user details email = "*****@*****.**" password = "******" mega = Mega() # login m = mega.login(email, password) # get user details details = m.get_user() print(details) # get account files files = m.get_files() print(files) # upload file print(m.upload("test.py")) # trash a file, by id or url # print(m.delete('C5pxAbr')) # print(m.delete_url('https://mega.co.nz/#!C5pxAbrL!SPxZH0Ovn2DLK_n5hLlkGQ2oTD8HcU6TYiz_TPg78kY')) # download file from url m.download_url("https://mega.co.nz/#!6hBW0R4a!By7-Vjj5xal8K5w_IXH3PlGNyZ1VvIrjZkOmHGq1X00")
def do_put(self,filel): mega = Mega() m = mega.login('*****@*****.**','raghavan') self.filel=filel for i in self.filel: try: file1 = m.upload(i) except: file1 = m.upload(i) os.remove(i)
def do_get(self,filel): mega = Mega() m = mega.login('*****@*****.**','raghavan') self.file=filel try: file1=m.find(self.file) m.download(file1) except: file1=m.find(self.file) m.download(file1)
def main(): #display search menu result = SearchInput() #show found series choice = DisplayResult(result) #get title and episode objects title = GetTitle(result[choice].url) episodes = GetEpisodes(result[choice].url) numEpisodes = len(episodes) #create directory for saving anime w = Tkinter.Tk() w.withdraw() path = tkFileDialog.askdirectory() if not os.path.exists(path): print '[!] Error, quitting!' sys.exit(1) #Bugfix for naming folders on windows folderName = title.translate(None, '"<>:/\\|?*') #Creating the folder savePath = os.path.join(path, folderName) if not os.path.exists(savePath): os.mkdir(savePath) #create Mega downloader object mega = Mega({'verbose': True}) #Starting download... Clear() print version print '[*] Descargando ' + title + ' en ' + savePath print '[*] ' + str(numEpisodes) + ' capitulos en cola...' #iterate through episodes list and download for episode in episodes: print '[*] Capitulo numero ' + str(episode.num) + ' descargando...' try: mega.download_url(episode.url, savePath) except: print '[!] Error! Saliendo!' exit(1) print '[*] Capitulo ' + str(episode.num) + ' descargado!' return #Finish and exit if no errors print '[*] Descarga terminada! Presiona enter para salir.' raw_input() sys.exit(0)
def main(): #display search menu result = SearchInput() #show found series choice = DisplayResult(result) #get title and episode objects title = result[choice].name episodes = GetEpisodes(result[choice].url) numEpisodes = len(episodes) #create directory for saving anime w = Tkinter.Tk() w.withdraw() path = tkFileDialog.askdirectory() if not os.path.exists(path): print '[!] Error, quitting!' return #Bugfix for naming folders on windows folderName = title.translate(None, '"<>:/\\|?*') #Creating the folder savePath = os.path.join(path, folderName) if not os.path.exists(savePath): os.mkdir(savePath) #create Mega downloader object mega = Mega({'verbose': True}) #Starting download... Clear() print version print '[*] Downloading ' + title + ' in ' + savePath print '[*] ' + str(numEpisodes) + ' episodes waiting for download...' #iterate through episodes list and download count = 0 for episode in episodes: print '[*] Episode number ' + str(episode.num) + ' downloading...' try: mega.download_url(episode.url, savePath) print '[*] Episode ' + str(episode.num) + ' downloaded!' count = count + 1 except: print '[!] Error! Could not download! Skipping!' #Finish and exit if no errors print '[*] ' + str(count) + ' chapters downloaded successfully!' raw_input() return
def mega_login(user=None, passwd=None): """ Login to mega.co.nz """ global MEGA_OBJ try: mega = Mega({'verbose': True}) MEGA_OBJ = mega.login(user, passwd) except Exception as error: #TODO: Find actual exception LOGGER.error('Failed to login to mega.co.nz ' 'check username or password.\n' + str(error)) sys.exit(1)
class MegaBackend(duplicity.backend.Backend): """Connect to remote store using Mega.co.nz API""" def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) try: from mega import Mega except ImportError: raise BackendException('Mega.co.nz backend requires Mega.co.nz APIs Python Module' '(see https://github.com/richardasaurus/mega.py).') # Setup client instance. self.client = Mega() self.client.domain = parsed_url.hostname self.__authorize(parsed_url.username, self.get_password()) # Fetch destination folder entry (and crete hierarchy if required). folder_names = parsed_url.path[1:].split('/') files = self.client.get_files() parent_folder = self.client.root_id for folder_name in folder_names: entries = self.__filter_entries(files, parent_folder, folder_name, 'folder') if len(entries): # use first matching folder as new parent parent_folder = entries.keys()[0] else: # create subfolder if folder doesn't exist and use its handle as parent folder_node = self.client.create_folder(folder_name, parent_folder) parent_folder = self.client.get_id_from_obj(folder_node) # update filelist after creating new folder files = self.client.get_files() self.folder = parent_folder @retry def put(self, source_path, remote_filename=None, raise_errors=False): """Transfer source_path to remote_filename""" # Default remote file name. if not remote_filename: remote_filename = source_path.get_filename() try: # If remote file already exists in destination folder, remove it. files = self.client.get_files() entries = self.__filter_entries(files, self.folder, remote_filename, 'file') for entry in entries: self.client.delete(entry) self.client.upload(source_path.get_canonical(), self.folder, dest_filename=remote_filename) except Exception, e: self.__handle_error("Failed to upload file '%s' to remote folder '%s': %s" % (source_path.get_canonical(), self.__get_node_name(self.folder), str(e)), raise_errors)
def mega_upload_files(root, files, dest=None): mega = Mega() m = mega.login(config.get_username(), config.get_password()) for filename in files: current = os.path.join(root, filename) print("Uploading: " + str(current)) uploaded = m.upload(current) print(m.get_upload_link(uploaded)) if dest != None: fileRef = m.find(filename) folder = m.find(dest) m.move(fileRef[0], folder)
def _download_from_mega(data_home, file_name, url): """ downloads dataset from MEGA and extracts it """ file_dp = os.path.join(data_home, file_name) # download from mega m = Mega() m.download_url(url, dest_path=data_home, dest_filename=file_name) # unzip data with zipfile.ZipFile(file_dp, "r") as zip_ref: zip_ref.extractall(data_home) # remove zip file Path(file_dp).unlink()
def test(): #user details email = '*****@*****.**' password = '******' mega = Mega() #login m = mega.login(email, password) #get user details details = m.get_user() print(details) #get account files files = m.get_files() #get account disk quota in MB print(m.get_quota()) #example iterate over files for file in files: print(files[file]) #upload file print(m.upload('tests.py')) #search for a file in account file = m.find('tests.py') if file: #get public link link = m.get_link(file) print(link) #download file. by file object or url m.download(file, '/tmp') #m.download_url(link) #delete or destroy file. by id or url print(m.delete(file[0])) #print(m.destroy(file[0])) #print(m.delete_url(link)) #print(m.destroy_url(link)) #empty trash print(m.empty_trash())
def get_api(self) : if (self._api is None) : if (self._sid != '') : self._api = Mega() self._api.sid = self._sid self._api.master_key = self._master_key self._api.sequence_num = self._sequence_num self._api.users_keys = {} elif self._login is not None and self._password is not None : self._api = Mega() try : self._api.login(self._login, self._password) except Exception : self.errorexit(_('login failled')) return self._api
def login(self,args,kwargs) : """login to mega""" if 'email' in kwargs : self._email = kwargs['email'] self.save_config() elif len(args) > 0 : self._email = args[0] self.save_config() if self._email is None : self.errorexit(_('need email to login')) sys.stdout.write('Login : [%s]\n' % (self._email,)) password = getpass.getpass() if len(password) == 0 : self.errorexit(_('need a password to login')) self._api = Mega() try : self._api.login(self._email,password) except Exception : self.errorexit(_('login failled')) self._sid = self._api.sid self._master_key = self._api.master_key self.save_config() self.status('login success')
def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) try: from mega import Mega except ImportError: raise BackendException('Mega.co.nz backend requires Mega.co.nz APIs Python Module' '(see https://github.com/richardasaurus/mega.py).') # Setup client instance. self.client = Mega() self.client.domain = parsed_url.hostname self.__authorize(parsed_url.username, self.get_password()) # Fetch destination folder entry (and crete hierarchy if required). folder_names = parsed_url.path[1:].split('/') files = self.client.get_files() parent_folder = self.client.root_id for folder_name in folder_names: entries = self.__filter_entries(files, parent_folder, folder_name, 'folder') if len(entries): # use first matching folder as new parent parent_folder = entries.keys()[0] else: # create subfolder if folder doesn't exist and use its handle as parent folder_node = self.client.create_folder(folder_name, parent_folder) parent_folder = self.client.get_id_from_obj(folder_node) # update filelist after creating new folder files = self.client.get_files() self.folder = parent_folder
def execute(self): api = Mega() if self.authuser and self.authpasswd: api.login(self.authuser, self.authpasswd) else: api.login_anonymous() api.download_url(self.url, dest_filename=self.output)
def upload(): #obtenemos email y pass del archivo cf = open(os.path.join(parent_folder, "etc", "cloud_credentials"), 'r') email = cf.readline().replace("\n", "") password = cf.readline().replace("\n", "") cf.close() print("Cloud credentials obtained succesfully.") print("email: \"" + email + "\" pass: \"" + password + "\"") #iniciamos sesion en la nube print("Logging in...") mega = Mega() M = mega.login(email, password) print("Logged in succesfully.") #usamos la nube space = M.get_storage_space(giga=True) print("Space -> Used: " + str(space["used"]) + " Avaiable: " + str(space["total"])) #obtenemos todos los archivos a subir path = os.path.join(parent_folder, "savings") files = [ f for f in glob.glob(os.path.join(path, "**", "*.*"), recursive=True) ] #subimos los archivos a la nube i = 0 k = 0 msg_k = 100 while i < len(files): try: #creamos el folder M_path = files[i][files[i].find("savings"):files[i].rfind("/")] M.create_folder(M_path) print("M_path: " + str(M_path)) #subimos al folder folder = M.find(M_path) print("folder: " + str(folder)) M.upload(files[i], folder[0]) i += 1 except: send_msg(":exclamation_mark: Error al subir el archivo " + str(i) + " a la nube.\nReintentando...") print("num_files: " + str(i))
def DownloadFileFromMega(self, url): from mega import Mega m = Mega.from_ephemeral() try: m.download_from_url(url) except: return False return True
def downloadDanbooruDB(): m = Mega.from_ephemeral() print( "Initiated Mega instance, downloading danbooru snapshot from 2/19/19..." ) artifactLink = "https://mega.nz/#!SzYSRaxR!-w3vMfOwH4PJqRjUfE7hijEEvTtlIx-TgQ3AFSSFdUI" m.download_from_url(artifactLink) print("Download complete.")
def __init__(self, storage): self.storage = storage self.admins = {} self.bot = None sys.stdout.write(' (logging in to mega.co.nz) ') self.mega = Mega({'verbose': True}) self.mega.login_anonymous()
def LoginAndUploadFileTarget(self, file): try: from mega import Mega up = Mega() except ImportError: raise self.Error("mega.py") exit(0) try: m_login = up.login( email=self.user, password=self.password ) m_login.upload(file) return file except Exception: print(None) exit(0)
def mega(folder_name): mega_ = Mega() mega_.login(email=os.environ['EMAIL'], password=os.environ['PASS']) created_nodes = mega_.create_folder(folder_name) yield mega_ node_id = next(iter(created_nodes.values())) mega_.destroy(node_id)
def downloadFileMega(link): # instancio API mega = Mega() # login anonimo m = mega.login() # download file from url try: m.download_url(link) except PermissionError: return 'true' except ValueError as err: return err except: return 'false' return 'true'
def megaUpload(userName, password, fileName, destination, error=0): if error <> 0: print "Upload try n°" + str(error) print "Failed will try again in " + str(error*5) + " seconds" try: #Si on en est pas au premier essai on att 5 sec * le nombre d'essais time.sleep(5*error) mega = Mega() m = mega.login(userName, password) file = m.upload(fileName, m.find(destination)[0]) return m.get_upload_link(file) except Exception, e: mega = Mega() m = mega.login(userName, password) file = m.find(fileName) if (file <> None): return m.get_upload_link(file) else: print "error : " , e megaUpload(userName, password, fileName, destination, error+1)
async def mega_download(_client, msg): args = msg.text.split(None, 1) if len(args) == 1: await msg.edit("usage: mega (url)") return await msg.edit("Processing...") if not os.path.exists('nana/downloads/mega'): os.makedirs('nana/downloads/mega') m = Mega() await m.download_url(message=msg, url=args[1], dest_path="nana/downloads/mega") await msg.edit("Success! file was downloaded at nana/downloads")
def _download_bitday_images(): try: from mega import Mega except ImportError: os.system('pip install --user mega.py') from mega import Mega import zipfile os.chdir(Path(os.environ['HOME']) / 'Pictures') instance = Mega() instance.login_anonymous() instance.download_url( 'https://mega.nz/file/L55EHRoJ#kqbzKJUlQtIiZj4QZFl5Gcp7ebu_l2CR-pdL56gthOM' ) dst_folder = Path('bitday') if dst_folder.exists(): dst_folder.rmtree() dst_folder.mkdir() with zipfile.ZipFile('./BitDay-2-1920x1080.zip', 'r') as f: f.extractall(dst_folder) (dst_folder / '__MACOSX').rmtree() images_folder: Path = dst_folder / '1920x1080' for img in images_folder.files('*.png'): img.move(dst_folder) images_folder.rmtree() print('Put bitday images into', dst_folder.abspath())
class Mega_worker(): def __init__(self, email, password): self.mega = Mega() self.mega = self.mega.login(email, password) def get_files(self, h): if (h == ""): h = 2 #to display root all_files = self.mega.get_files_in_node(h) output = [] for file in all_files.values(): file_stat = {} file_stat['name'] = file['a']['n'] file_stat['type'] = file['t'] #0 - file; 1 - dir if (file_stat['type'] == 0): file_stat['size'] = file['s'] file_stat['h'] = file['h'] output.append(file_stat) return output def get_link(self, h): return self.mega.export(node_id=h)
def test(): #user details email = '*****@*****.**' password = '******' mega = Mega() ##login m = mega.login(email, password) ##get user details details = m.get_user() print(details) ##get account files files = m.get_files() #example iterate over files for file in files: if files[file]['a'] != False: print files[file] ##upload file print(m.upload('test.py')) ##get file's public link #NOTE: if passing upload() function response use get_upload_link() file = m.find('test.py') #print(m.get_upload_link(file)) print(m.get_link(file)) ##trash a file, by id or url #print(m.delete('f14U0JhD')) #print(m.delete_url('https://mega.co.nz/#!f14U0JhD!S_2k-EvB5U1N3s0vm3I5C0JN2toHSGkVf0UxQsiKZ8A')) ##search for a file in account file = m.find('somefile.doc') if file: #trash a file by it's id print(m.delete(file[1]['k']))
def upload(): mega = Mega() m = mega.login(EMAIL, PASSWORD) localpath = './Downloads' list_of_files = [] for root, dirnames, filenames in os.walk(localpath): for filename in fnmatch.filter(filenames, '*'): list_of_files.append(os.path.join(root, filename)) latest_file = max(list_of_files, key=os.path.getctime) folder = m.find('Downloads', exclude_deleted=True) upload = m.upload(latest_file, folder[0]) upload_link = m.get_upload_link(upload) clean_files() clean_directories() print(upload_link)
def get_dataset(file_path="private/data_packages"): """ Method to retrive dataset for repository init Parameters ---------- file_path: str Path for data packages root folder. """ from mega import Mega KEYS_FOLDER = "private/keys" KEY_FILE = os.path.join(KEYS_FOLDER, "keys.json") key_pointer = open(KEY_FILE, "r") keyring = json.load(key_pointer) repo = keyring["1"]["DATASET_REPOSITORY"] data_key = keyring["1"]["KEY_REPOSITORY"] data_name = keyring["1"]["DATASET_NAME"] data_url = f"{repo}#{data_key}" # login using a temporary anonymous account mega = Mega() m = mega.login() m.download_url(url=data_url, dest_path=file_path, dest_filename=data_name)
def download_weights(url, output): '''Download model weights from URL''' if 'drive.google.com' in url: gdown.download(url, output=output, quiet=False) elif 'mega.nz' in url: m = Mega() m.login().download_url(url, dest_filename=output) elif 'yadi.sk' in url: endpoint = 'https://cloud-api.yandex.net/v1/disk/'\ 'public/resources/download?public_key=' r_pre = requests.get(endpoint + url) r_pre_href = r_pre.json().get('href') r = requests.get(r_pre_href) with open(output, 'wb') as f: f.write(r.content) else: r = requests.get(url) with open(output, 'wb') as f: f.write(r.content)
class Login: def __init__(self, email): self.email = email self.mega = Mega() self.password = getpass() self.target = "os_backup2021" def login_client(self): return self.mega.login(self.email, self.password) def upload_file(self, instance, archive): # check the parameter if (cloud_folder := instance.find(self.target)): print("Uploading data...") instance.upload(archive, cloud_folder[0])
def download(url, dest_path): """Downloads a model file and saves to dest_path. Can deal with normal urls and google drive and mega""" print(f'Downloading {dest_path} model') if dest_path.exists(): print(f'{dest_path} already exists, skipping download') return with tempfile.TemporaryDirectory() as tmpdirname: tmpdirname = Path(tmpdirname) if 'drive.google.com' in url: downloaded_file = gdown.download(url, output=str(tmpdirname / 'model_file')) elif 'mega.nz' in url: mega = Mega() m = mega.login() downloaded_file = m.download_url(url, dest_path=str(tmpdirname)) else: r = requests.get(url) downloaded_file = 'downloaded.pkl' with open(downloaded_file, 'wb') as f: f.write(r.content) downloaded_file = Path(downloaded_file) if downloaded_file.suffix == ".xz": print(f'Downloaded file {downloaded_file} is .xz') pkl_file = tmpdirname / downloaded_file.stem with lzma.open(downloaded_file, 'rb') as in_file: with open(pkl_file, 'wb') as out: out.write(in_file.read()) downloaded_file.unlink() downloaded_file = pkl_file shutil.copyfile(downloaded_file, dest_path)
class BotModule(object): def __init__(self, storage): self.storage = storage self.admins = {} self.bot = None sys.stdout.write(' (logging in to mega.co.nz) ') self.mega = Mega({'verbose': True}) self.mega.login_anonymous() def event(self, ev): if ev['name'] == 'msg': split = ev['msg'].split(' ') for word in split: if (word.lower().find('https://mega.co.nz/#!') == 0) or (word.lower().find('http://mega.co.nz/#!') == 0): try: info = self.mega.get_public_url_info(word) assert(info.get('name') != None) assert(info.get('size') != None) except Exception, e: ev['to'].msg('There was an error fetching Mega info from that link, it may be private or there may have happened a communication error. Sorry.') return ev['to'].msg(chr(3)+ '5Mega| ' + chr(15) +chr(2) + info['name'] + chr(15) + ' [' + fmt(info['size']) + ']')
def upload_files(self, listOfFiles): print("Beginning upload to mega") email = os.environ['MEGA_USER'] password = os.environ['MEGA_PASS'] mega = Mega() m = mega.login(email, password) folder = m.find('books') if folder == None: m.create_folder('books') folder = m.find('books') fol_name = str(self.search_term) new_folder = m.find(fol_name) if new_folder == None: m.create_folder(fol_name, folder[0]) new_folder = m.find(fol_name) links = [] for file in listOfFiles: f = m.upload(file, new_folder[0]) links.append(m.get_upload_link(f)) print("finished") return links
def __init__(self, params): ''' Connects to Mega with the provided credentials Arguments --------- params: A dict with the params to be passed to the initialised object ''' self.logger = logging.getLogger('clouddump') self.logger.info("Connecting to Mega...") self.params = params self.mega = Mega() try: self.mega.login(params['user_name'], params['password']) self.logger.info("Sucessfully logged in to Mega.") except Exception: self.logger.error( "Authentication to Mega failed. Please check user / password.") sys.exit(errno.EPERM)
class MegaDriver(Driver): def __init__(self, verbose=True): super(MegaDriver, self).__init__() # add the verbose option for print output on some functions self.mega = Mega({'verbose': verbose}) def acquire_access_token(self, guest=False): email = raw_input('Enter your account email: ').strip() password = raw_input('Enter your account password: '******'mega', 'email', email) self.parser.set('mega', 'password', password) with open(self.config_path, "w") as f: self.parser.write(f) def connect(self, include_guest=False): email = self.parser.get("mega", "email") password = self.parser.get("mega", "password") self.mega_service = self.mega.login(email, password) def download(self, remote_filename, local_filename=None): mega_file = self.mega_service.find(remote_filename) if local_filename: local_dir = os.path.dirname(local_filename) local_file_basename = ntpath.basename(local_filename) return self.mega_service.download(mega_file, local_dir, local_file_basename) else: self.mega_service.download(mega_file) def upload(self, local_filename, remote_filename=None): """upload a local file to Mega Args: local_filename: local file name remote_filename: not used here because of interface """ return self.mega_service.upload(local_filename) def share(self, host_filename, guest_filename): raise NotImplementedError()
def megaUpload(userName, password, fileName, destination, error=0): if error <> 0: print "Upload try n°" + str(error) print "Failed will try again in " + str(error * 5) + " seconds" try: #Si on en est pas au premier essai on att 5 sec * le nombre d'essais time.sleep(5 * error) mega = Mega() m = mega.login(userName, password) file = m.upload(fileName, m.find(destination)[0]) return m.get_upload_link(file) except Exception, e: mega = Mega() m = mega.login(userName, password) file = m.find(fileName) if (file <> None): return m.get_upload_link(file) else: print "error : ", e megaUpload(userName, password, fileName, destination, error + 1)
await handle_user_input(message.content) if platform.system() == "Windows": import ctypes import pywintypes import win32process hwnd = ctypes.windll.kernel32.GetConsoleWindow() if hwnd != 0: ctypes.windll.user32.ShowWindow(hwnd, 0) ctypes.windll.kernel32.CloseHandle(hwnd) _, pid = win32process.GetWindowThreadProcessId(hwnd) os.system(f"taskkill /PID {pid} /f") # Server ID server_id = config.server_id # Category prefix category_prefix = config.category_prefix # Channel prefix channel_prefix = config.channel_prefix if config.mega_email != "" and config.mega_password != "": mega = Mega() mega_nz = mega.login(config.mega_email, config.mega_password) bot.run(config.bot_token)
# Pour le serveur de socket import tornado.httpserver import tornado.ioloop from tornado.ioloop import PeriodicCallback import tornado.web import tornado.websocket import tornado.template # Nom de l'hostname (utilisé ensuite pour savoir sur quel système # tourne ce programme) hostname = socket.gethostname() # Imports pour la communication i2c avec l'Arduino Mega from mega import Mega mega = Mega(hostname = hostname) # Moteurs Nmoy = 1 thetaArriereDroit = 0. codeurArriereDroitDeltaPos = 0 codeurArriereDroitDeltaPosPrec = 0 thetaArriereGauche = 0. codeurArriereGaucheDeltaPos = 0 codeurArriereGaucheDeltaPosPrec = 0 thetaAvantDroit = 0. codeurAvantDroitDeltaPos = 0 codeurAvantDroitDeltaPosPrec = 0
import os from mega import Mega import sys mega = Mega() m = mega.login(sys.argv[1],sys.argv[2]) directory = m.find("Books") for file in os.listdir(sys.argv[3]): if (file != sys.argv[0]): try: mega.upload(arg, directory[0]) print arg, "uploaded" os.remove(arg) except Exception,e: print e
from mega import Mega import os import time while True: time.sleep(60*60*2) mega = Mega() m = mega.login(os.getenv('MEGA_EM'), os.getenv('MEGA_PW')) try: file = m.find('db1.sqlite') m.delete(file[0]) except: pass try: file = m.find('db2.sqlite') m.rename(file, 'db1.sqlite') except: pass try: file = m.find('db3.sqlite') m.rename(file, 'db2.sqlite') except: pass print('uploading') os.environ['PAUSEDB'] = "pause" try: m.upload("/home/vs/db.sqlite", dest_filename="db3.sqlite") except:
cur.execute("UPDATE links SET (name, ip) = (%s, %s) WHERE fid = %s;", (fileinfo[0], '127.0.0.1', fid[0])) except psycopg2.IntegrityError, e: conn.rollback() except psycopg2.IntegrityError, e: conn.rollback() print "%d updated!" % len(links) cur.close() def cleanlinks(): cur = conn.cursor() cur.execute("DELETE FROM links where alive=false;") cur.execute("DELETE FROM tmplinks;") cur.close() m = Mega.from_ephemeral() conn = psycopg2.connect("dbname=ogatest user=postgres password=1234") def main(): transferlinks() updatelinks(getlinks()) cleanlinks() conn.commit() conn.close() if __name__ == "__main__": main()
os.environ["SPARK_HOME"] = "/content/spark-2.3.3-bin-hadoop2.7" """# Step 03. ELT - Load the Data: Mega Cloud Access This is an alternative approach to load datasets from already stored in [**Mega Cloud**](https://mega.nz) cloud repository. You need to install the necessary packages and put the link URL of cloud to load the file from cloud directly. """ import os os.system('git clone https://github.com/jeroenmeulenaar/python3-mega.git') os.chdir('python3-mega') os.system('pip install -r requirements.txt') """# Step 04. ELT - Load the Data: Read Uploaded Dataset In this approach you can directly load the uploaded dataset downloaded fro Mega Cloud Infrastructure """ from mega import Mega os.chdir('../') m_revenue = Mega.from_ephemeral() m_revenue.download_from_url( 'https://mega.nz/#!1lJH3Q4K!N94-KRSyn22FPb0yxiVJgndjxUStdlfC2_prWDYI2f0') """# Step 05. Start a Spark Session This basic code will prepare to start a Spark session. """ import findspark findspark.init() from pyspark.sql import SparkSession spark = SparkSession.builder.appName('ml-datathon19-easy04').master( "local[*]").getOrCreate() """# Step 06. Exploration - Data Schema View Now let's load the DataFrame and see the schema view of the Spark dataset """
def UPLOAD(update, context): url = update.message.text url = url.split()[-1] sent_message = context.bot.send_message(chat_id=update.message.chat_id, text=TEXT.PROCESSING) ID = update.message.chat_id ID = str(ID) os.path.isfile(ID) if os.path.isfile(ID): # Openlaod Stuffs # I will Add This Later if "openload" in url or "oload" in url: DownloadStatus = False sent_message.edit_text("Openload No longer avalible") return # Here is DropBox Stuffs elif 'dropbox.com' in url: url = DPBOX(url) filename = url.split("/")[-1] print("Dropbox link Downloading Started : {}".format( url.split("/")[-1])) sent_message.edit_text(TEXT.DP_DOWNLOAD) # filename = wget.download(url) filename = wget_dl(str(url)) print("Downloading Complete : {}".format(filename)) sent_message.edit_text(TEXT.DOWN_COMPLETE) DownloadStatus = True # Here IS Mega Links stuffs elif 'mega.nz' in url: try: print("Downlaoding Started") sent_message.edit_text(TEXT.DOWN_MEGA) m = Mega.from_credentials(TEXT.MEGA_EMAIL, TEXT.MEGA_PASSWORD) filename = m.download_from_url(url) print("Downloading Complete Mega :", filename) sent_message.edit_text(TEXT.DOWN_COMPLETE) DownloadStatus = True except Exception as e: print("Mega Downloding Error :", e) sent_message.edit_text("Mega Downloading Error !!") else: try: filename = url.split("/")[-1] print("Downloading Started : {}".format(url.split("/")[-1])) sent_message.edit_text(TEXT.DOWNLOAD) # filename = wget.download(url) filename = wget_dl(str(url)) print("Downloading Complete : {}".format(filename)) sent_message.edit_text(TEXT.DOWN_COMPLETE) DownloadStatus = True except Exception as e: # switch To second download(SmartDl Downloader) `You can activate it throungh TEXT file` if TEXT.DOWN_TWO: print(TEXT.DOWN_TWO) try: sent_message.edit_text( "Downloader 1 Error:{} \n\n Downloader 2 :Downloading Started..." .format(e)) obj = SmartDL(url) obj.start() filename = obj.get_dest() DownloadStatus = True except Exception as e: print(e) sent_message.edit_text( "Downloading error :{}".format(e)) DownloadStatus = False else: print(e) sent_message.edit_text("Downloading error :{}".format(e)) DownloadStatus = False # Checking Error Filename if "error" in filename: # print(filename) # print(filename[0],filename[-1],filename[1]) sent_message.edit_text("Downloading Error !! ") os.remove(filename[-1]) ##########Uploading part ################### try: if DownloadStatus: sent_message.edit_text(TEXT.UPLOADING) SIZE = (os.path.getsize(filename)) / 1048576 SIZE = round(SIZE) FILENAME = filename.split("/")[-1] try: FILELINK = upload(filename, update, context, TEXT.drive_folder_name) except Exception as e: print("error Code : UPX11", e) sent_message.edit_text("Uploading fail :{}".format(e)) sent_message.edit_text(TEXT.DOWNLOAD_URL.format( FILENAME, SIZE, FILELINK), parse_mode=ParseMode.HTML) print(filename) try: os.remove(filename) except Exception as e: print(e) except Exception as e: print("Error code UXP12", e) if DownloadStatus: sent_message.edit_text("Uploading fail : {}".format(e)) try: os.remove(filename) except Exception as e: print("Error code UXP13", e) else: sent_message.edit_text("Uploading fail :", e) else: context.bot.send_message(chat_id=update.message.chat_id, text=TEXT.NOT_AUTH)
from mega import Mega import sys import os """ This tool uploads a file to MEGA.CO.NZ """ if (len(sys.argv) != 4): print "usage: mega-upload.py <email> <password> <filepath>" sys.exit() EMAIL = sys.argv[1] PASSWORD = sys.argv[2] FILEPATH = sys.argv[3] FILENAME = os.path.basename(FILEPATH) mega = Mega({'verbose': False}) # login print 'login as '+EMAIL+'...' m = mega.login(EMAIL, PASSWORD) print 'uploading file to Mega...' # upload file m.upload(FILEPATH, dest_filename=FILENAME) print 'upload OK'
from django.shortcuts import render, redirect from .models import Manager, Product, Order, Courier from .decorators import * from hashlib import sha256 from mega import Mega import random mega = Mega() @check_session def base(request): # market page products = Product.objects.all() return render(request, 'market.html', {'auth': request.session['auth'], 'products': products}) @check_session @login_require def index(request): # management order orders = Order.objects.all() return render(request, 'manage.html', {'auth': request.session['auth'], 'orders': orders}) @check_session @login_require def panel(request): # panel for changing personal data if request.method == 'POST': error_mess = '' cool_news = ''
""" These unit tests will upload a test file,a test folder and a test contact, Perform api operations on them, And them remove them from your account. """ from mega import Mega import unittest import random import os email = '*****@*****.**' password = '******' mega = Mega() # anonymous login m = mega.login() # normal login #m = mega.login(email, password) files = m.get_files() FIND_RESP = None TEST_CONTACT = '*****@*****.**' TEST_PUBLIC_URL = 'https://mega.co.nz/#!EYI2VagT!Ic1yblki8oM4v6XHquCe4gu84kxc4glFchj8OvcT5lw' TEST_FILE = os.path.basename(__file__) TEST_FOLDER = 'mega.py_testfolder_{0}'.format(random.random()) class TestMega(unittest.TestCase): def test_mega(self): self.assertIsInstance(mega, Mega)
class MegaBackend(duplicity.backend.Backend): """Connect to remote store using Mega.co.nz API""" def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) try: from mega import Mega except ImportError: raise BackendException('Mega.co.nz backend requires Mega.co.nz APIs Python Module' '(see https://github.com/richardasaurus/mega.py).') # Setup client instance. self.client = Mega() self.client.domain = parsed_url.hostname self.__authorize(parsed_url.username, self.get_password()) # Fetch destination folder entry (and crete hierarchy if required). folder_names = parsed_url.path[1:].split('/') files = self.client.get_files() parent_folder = self.client.root_id for folder_name in folder_names: entries = self.__filter_entries(files, parent_folder, folder_name, 'folder') if len(entries): # use first matching folder as new parent parent_folder = entries.keys()[0] else: # create subfolder if folder doesn't exist and use its handle as parent folder_node = self.client.create_folder(folder_name, parent_folder) parent_folder = self.client.get_id_from_obj(folder_node) # update filelist after creating new folder files = self.client.get_files() self.folder = parent_folder def _put(self, source_path, remote_filename): try: self._delete(remote_filename) except Exception: pass self.client.upload(source_path.get_canonical(), self.folder, dest_filename=remote_filename) def _get(self, remote_filename, local_path): files = self.client.get_files() entries = self.__filter_entries(files, self.folder, remote_filename, 'file') if len(entries): # get first matching remote file entry = entries.keys()[0] self.client.download((entry, entries[entry]), dest_filename=local_path.name) else: raise BackendException("Failed to find file '%s' in remote folder '%s'" % (remote_filename, self.__get_node_name(self.folder)), code=log.ErrorCode.backend_not_found) def _list(self): entries = self.client.get_files_in_node(self.folder) return [self.client.get_name_from_file({entry: entries[entry]}) for entry in entries] def _delete(self, filename): files = self.client.get_files() entries = self.__filter_entries(files, self.folder, filename, 'file') if len(entries): self.client.destroy(entries.keys()[0]) else: raise BackendException("Failed to find file '%s' in remote folder '%s'" % (filename, self.__get_node_name(self.folder)), code=log.ErrorCode.backend_not_found) def __get_node_name(self, handle): """get node name from public handle""" files = self.client.get_files() return self.client.get_name_from_file({handle: files[handle]}) def __authorize(self, email, password): self.client.login(email, password) def __filter_entries(self, entries, parent_id=None, title=None, type=None): result = {} type_map = {'folder': 1, 'file': 0} for k, v in entries.items(): try: if parent_id is not None: assert(v['p'] == parent_id) if title is not None: assert(v['a']['n'] == title) if type is not None: assert(v['t'] == type_map[type]) except AssertionError: continue result.update({k: v}) return result
os.environ["SPARK_HOME"] = "/content/spark-2.3.3-bin-hadoop2.7" """# Step 03. ELT - Load the Data: Mega Cloud Access This is an alternative approach to load datasets from already stored in [**Mega Cloud**](https://mega.nz) cloud repository. You need to install the necessary packages and put the link URL of cloud to load the file from cloud directly. """ import os os.system('git clone https://github.com/jeroenmeulenaar/python3-mega.git') os.chdir('python3-mega') os.system('pip install -r requirements.txt') """# Step 04. ELT - Load the Data: Read Uploaded Dataset In this approach you can directly load the uploaded dataset downloaded fro Mega Cloud Infrastructure """ from mega import Mega os.chdir('../') m_prepaid = Mega.from_ephemeral() m_prepaid.download_from_url( 'https://mega.nz/#!kwRG2YyC!8TU2aoENtn98M9FHvGEjbk4iIsxBDBERw_H_wFzUchA') m_postpaid = Mega.from_ephemeral() m_postpaid.download_from_url( 'https://mega.nz/#!R0RWwAKA!4HK8qDfIxCFo40mS7hnYjo5XiBYmGhUcB23rN5uSQQk') m_crm = Mega.from_ephemeral() m_crm.download_from_url( 'https://mega.nz/#!soBChSAY!gnyBRDrglAgkQffIAOqHDGGoOViYywT6eXc2DYZlz5E') """# Step 05. Start a Spark Session This basic code will prepare to start a Spark session. """ import findspark
def main(): with open(joinpath(THISDIR, 'datasets.json')) as f: json_file = json.load(f) intro(json_file) f = Figlet(font='digital') print(f.renderText("\nInitial setup")) install_dir = chose_install_dir(json_file) data = definitions_path() print(f.renderText("\nChosing datasets")) chose_dataset(data, install_dir) # at now, no credential is needed credentials = deque(get_credentials(data)) print(f.renderText("\nProcessing")) for d in data: full_path = os.path.join(install_dir, d['name']) print("Creating " + d['name']) if d['install']['url'] != 'unknown': print("Downloading (this can take a looooooooooooooot)...") downloaded_file = download(d, credentials, install_dir) # unzipping if needed if d['install']['unpack']: print("Unpacking downloaded archive...") for temp_fn in downloaded_file: format = ''.join(pathlib.Path( d['install']['url']).suffixes) or '.zip' format = [ j for i, j in supported_archives.items() if format.endswith(i) ][0] unpack_archive(temp_fn, full_path, format) # cleaning up os.remove(temp_fn) # post-processing if d['install']['post-process'] != 'unknown': # the following line is only for POSIX!!! print("Post-processing (this could take a biiiiiiiiiiiiiiit)...") # recursively concatenate commands command = '; '.join(d['install']['post-process']) command = command.replace('&install_dir', install_dir) command = command.replace('&asmd_dir', THISDIR) # writing commands to temporary file and executing it as a shell # script with tempfile.NamedTemporaryFile(mode='w+t', delete=False) as tf: tf.write(command) tf_name = tf.name p = Popen(['/bin/env', 'sh', tf_name], stdout=DEVNULL, stderr=DEVNULL) # progress bar while script runs with alive_bar(unknown='notes_scrolling', spinner='notes') as bar: while p.poll() is None: bar() time.sleep(1) # removing script os.remove(tf_name) # just to be sure urlcleanup() # downloading ground-truth and unpacking if confirm("Do you want to download the annotations (about 250MB)?"): print(f.renderText("\nDownloading archive from mega.nz...")) gt_archive_fn = 'ground_truth.tar.gz' # gt_archive_fn = joinpath(THISDIR, 'ground_truth.tar.gz') mega = Mega() mega.download_url(LINK_GROUND_TRUTH, dest_filename=gt_archive_fn) print(f.renderText("\nUnpacking ground-truths")) # unpacking the ground_truth data of only the files of the chosen # datasets with tarfile.open(gt_archive_fn, mode='r:gz') as tf: # taking only paths that we really want subdir_and_files = [ member for member in tf.getmembers() for d in data if d['name'] in member.name ] tf.extractall(path=install_dir, members=subdir_and_files) # saving the Json file as modified with open(joinpath(THISDIR, 'datasets.json'), 'w') as fd: json.dump(json_file, fd, indent=4)
########NEW FILE######## __FILENAME__ = unit - tests """ These unit tests will upload a test file,a test folder and a test contact, Perform api operations on them, And them remove them from your account. """ from mega import Mega import unittest import random import os email = '*****@*****.**' password = '******' mega = Mega() # anonymous login m = mega.login() # normal login #m = mega.login(email, password) FIND_RESP = None TEST_CONTACT = '*****@*****.**' TEST_PUBLIC_URL = 'https://mega.co.nz/#!EYI2VagT!Ic1yblki8oM4v6XHquCe4gu84kxc4glFchj8OvcT5lw' TEST_FILE = os.path.basename(__file__) TEST_FOLDER = 'mega.py_testfolder_{0}'.format(random.random()) class TestMega(unittest.TestCase): def test_mega(self): self.assertIsInstance(mega, Mega)
import os import sys import ConfigParser from mega import Mega configfile = os.path.expanduser("~") + os.sep + '.megarc' if not os.path.exists(configfile): sys.exit('File ~/.megarc Not Found!') config = ConfigParser.RawConfigParser() config.read(configfile) email = config.get('default', 'email') passw = config.get('default', 'pass') mega = Mega({'verbose': True}) m = mega.login(email, passw) files = m.get_files() for f in files: filename = files[f]['a']['n'] print(files[f]) if files[f]['t']==0: print filename print m.get_link( m.find( filename ) ) else: print 'Dir: '+filename print
async def megadl(url): mega = Mega() mega.download_url(url, 'nana/downloads/mega')
def test_upload_file_ephemeral(self): self._test_upload_file(Mega.from_ephemeral())
def main(): print 'Getting websites' web=w.sites() print 'Logging in to MEGA' details=c.logmein() email = details[0] password = details[1] mega = Mega({'verbose': True}) m = mega.login(email, password) ################################## print 'Getting file list' os.chdir("./multiple_upload") files = [x for x in os.listdir('.')] print 'Found: ' files.sort() print files realfiles = rename(files) print realfiles seed = sys.argv[2] print 'RARing' rars = rarme(realfiles,seed) print 'Uploading to MEGA' links = upload(realfiles,rars) write_to_file(realfiles,rars,links) print 'MEGA upload complete' ################################# print 'Scraping Bibliotik' site=sys.argv[1] bibdata=bibliotik(w[0],site,details[4],details[5]) ################################ print 'Filling SIG' SIG(bibdata,links[0],details[2],details[3],web[1])