Last active
December 28, 2023 10:42
-
-
Save oleksis/992ab66dbec275d8e4329e68c9cff7fe to your computer and use it in GitHub Desktop.
Print the links of files in mega.nz API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print the links of files | |
# following directory structure | |
# using mega.py package | |
# | |
# Books | |
# |_ Alejandro Dumas | |
# |_ El Conde de Montecristo | |
# |_ J.K.Rowling | |
# |_ Harry Poter 1 | |
# |_ Harry Poter 2 | |
# Output: | |
# | |
# Alejandro Dumas | |
# [El Conde de Montecristo.txt](https://mega.co.nz/#!hnomla4S!_UO0X9_5ppuU_QjYaK6gZe74D5V5Vn5GAAAAAAAAAAA) | |
# J.K.Rowling | |
# [Harry Potter 1.txt](https://mega.co.nz/#!gvwQDIJa!ziL9FeaLLQQ9cUqec_gTD-zMHDdcwhAOAAAAAAAAAAA) | |
# [Harry Poter 2.txt](https://mega.co.nz/#!p35CxIqK!w8xxoL0Uxh3uWsaOji0dVfWvIMoMCSzmAAAAAAAAAAA) | |
# Export environmet variables (GNU/Linux) | |
# export [email protected] | |
# export PASS=micontraseñasegura | |
import logging | |
import os | |
# pip install mega.py==1.0.8 | |
from mega import Mega | |
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.WARNING) | |
# logger = logging.getLogger(__name__) | |
email = os.environ['EMAIL'] | |
password = os.environ['PASS'] | |
mega = Mega() | |
m = mega.login(email, password) | |
files = m.get_files() | |
folde_name = 'Books' | |
folder = None | |
# Find folder Books | |
for file in files: | |
node = files[file] | |
if node['t'] == 1 and node['a']['n'] == folde_name: | |
folder = node | |
break | |
assert folder is not None | |
for file in files: | |
node = files[file] | |
# Node Author folder in Books | |
if node['t'] == 1 and node['p'] == folder['h']: | |
author = node | |
print(author['a']['n']) | |
for num, _file in enumerate(files): | |
book = files[_file] | |
# Node Book file | |
if book['t'] == 0 and book['p'] == author['h']: | |
print(" [%s](%s)" % (book['a']['n'], m.get_link((num, book)))) |
export all links from public folder? how
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to get links of random folder using link just