mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-13 15:19:03 +00:00
Fix lint check + update lint script (#224)
* Fix PEP8 E301 on nyaa/models.py * Add utils/ to lint checker * Run of lint.sh + manual fixes As suggested https://github.com/nyaadevs/nyaa/pull/157#issuecomment-305051428 * Fix backwards tick in README * Updated script * Update Travis config
This commit is contained in:
@@ -38,6 +38,7 @@ SUKEBEI_CATS = '''1_1 - Art - Anime
|
||||
2_1 - Real Life - Photobooks / Pictures
|
||||
2_2 - Real Life - Videos'''
|
||||
|
||||
|
||||
class CategoryPrintAction(argparse.Action):
|
||||
def __init__(self, option_strings, nargs='?', help=None, **kwargs):
|
||||
super().__init__(option_strings=option_strings,
|
||||
@@ -55,15 +56,20 @@ class CategoryPrintAction(argparse.Action):
|
||||
print(NYAA_CATS)
|
||||
parser.exit()
|
||||
|
||||
environment_epillog = '''You may also provide environment variables NYAA_API_HOST, NYAA_API_USERNAME and NYAA_API_PASSWORD for connection info.'''
|
||||
|
||||
parser = argparse.ArgumentParser(description='Upload torrents to Nyaa.si', epilog=environment_epillog)
|
||||
environment_epillog = ('You may also provide environment variables NYAA_API_HOST, NYAA_API_USERNAME'
|
||||
' and NYAA_API_PASSWORD for connection info.')
|
||||
|
||||
parser.add_argument('--list-categories', default=False, action=CategoryPrintAction, nargs='?', help='List torrent categories. Include "sukebei" to show Sukebei categories')
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Upload torrents to Nyaa.si', epilog=environment_epillog)
|
||||
|
||||
parser.add_argument('--list-categories', default=False, action=CategoryPrintAction, nargs='?',
|
||||
help='List torrent categories. Include "sukebei" to show Sukebei categories')
|
||||
|
||||
conn_group = parser.add_argument_group('Connection options')
|
||||
|
||||
conn_group.add_argument('-s', '--sukebei', default=False, action='store_true', help='Upload to sukebei.nyaa.si')
|
||||
conn_group.add_argument('-s', '--sukebei', default=False,
|
||||
action='store_true', help='Upload to sukebei.nyaa.si')
|
||||
|
||||
conn_group.add_argument('-u', '--user', help='Username or email')
|
||||
conn_group.add_argument('-p', '--password', help='Password')
|
||||
@@ -71,8 +77,10 @@ conn_group.add_argument('--host', help='Select another api host (for debugging p
|
||||
|
||||
resp_group = parser.add_argument_group('Response options')
|
||||
|
||||
resp_group.add_argument('--raw', default=False, action='store_true', help='Print only raw response (JSON)')
|
||||
resp_group.add_argument('-m', '--magnet', default=False, action='store_true', help='Print magnet uri')
|
||||
resp_group.add_argument('--raw', default=False, action='store_true',
|
||||
help='Print only raw response (JSON)')
|
||||
resp_group.add_argument('-m', '--magnet', default=False,
|
||||
action='store_true', help='Print magnet uri')
|
||||
|
||||
tor_group = parser.add_argument_group('Torrent options')
|
||||
|
||||
@@ -80,16 +88,23 @@ tor_group.add_argument('-c', '--category', required=True, help='Torrent category
|
||||
tor_group.add_argument('-n', '--name', help='Display name for the torrent (optional)')
|
||||
tor_group.add_argument('-i', '--information', help='Information field (optional)')
|
||||
tor_group.add_argument('-d', '--description', help='Description for the torrent (optional)')
|
||||
tor_group.add_argument('-D', '--description-file', metavar='FILE', help='Read description from a file (optional)')
|
||||
tor_group.add_argument('-D', '--description-file', metavar='FILE',
|
||||
help='Read description from a file (optional)')
|
||||
|
||||
tor_group.add_argument('-A', '--anonymous', default=False, action='store_true', help='Upload torrent anonymously')
|
||||
tor_group.add_argument('-H', '--hidden', default=False, action='store_true', help='Hide torrent from results')
|
||||
tor_group.add_argument('-C', '--complete', default=False, action='store_true', help='Mark torrent as complete (eg. season batch)')
|
||||
tor_group.add_argument('-R', '--remake', default=False, action='store_true', help='Mark torrent as remake (derivative work from another release)')
|
||||
tor_group.add_argument('-A', '--anonymous', default=False,
|
||||
action='store_true', help='Upload torrent anonymously')
|
||||
tor_group.add_argument('-H', '--hidden', default=False, action='store_true',
|
||||
help='Hide torrent from results')
|
||||
tor_group.add_argument('-C', '--complete', default=False, action='store_true',
|
||||
help='Mark torrent as complete (eg. season batch)')
|
||||
tor_group.add_argument('-R', '--remake', default=False, action='store_true',
|
||||
help='Mark torrent as remake (derivative work from another release)')
|
||||
|
||||
trusted_group = tor_group.add_mutually_exclusive_group(required=False)
|
||||
trusted_group.add_argument('-T', '--trusted', dest='trusted', action='store_true', help='Mark torrent as trusted, if possible. Defaults to true')
|
||||
trusted_group.add_argument('--no-trusted', dest='trusted', action='store_false', help='Do not mark torrent as trusted')
|
||||
trusted_group.add_argument('-T', '--trusted', dest='trusted', action='store_true',
|
||||
help='Mark torrent as trusted, if possible. Defaults to true')
|
||||
trusted_group.add_argument('--no-trusted', dest='trusted',
|
||||
action='store_false', help='Do not mark torrent as trusted')
|
||||
parser.set_defaults(trusted=True)
|
||||
|
||||
tor_group.add_argument('torrent', metavar='TORRENT_FILE', help='The .torrent file to upload')
|
||||
@@ -105,7 +120,7 @@ def crude_torrent_check(file_object):
|
||||
file_object.seek(-1, os.SEEK_END)
|
||||
if file_object.read(1) != b'e':
|
||||
return False
|
||||
|
||||
|
||||
# Seek back to beginning
|
||||
file_object.seek(0)
|
||||
|
||||
@@ -118,7 +133,7 @@ if __name__ == "__main__":
|
||||
# Use debug host from args or environment, if set
|
||||
debug_host = args.host or os.getenv('NYAA_API_HOST')
|
||||
api_host = (debug_host or (args.sukebei and SUKEBEI_HOST or NYAA_HOST)).rstrip('/')
|
||||
|
||||
|
||||
api_upload_url = api_host + API_UPLOAD
|
||||
|
||||
if args.description_file:
|
||||
@@ -131,33 +146,33 @@ if __name__ == "__main__":
|
||||
if not crude_torrent_check(torrent_file):
|
||||
raise Exception("File '{}' doesn't seem to be a torrent file".format(args.torrent))
|
||||
|
||||
api_username = args.user or os.getenv('NYAA_API_USERNAME')
|
||||
api_username = args.user or os.getenv('NYAA_API_USERNAME')
|
||||
api_password = args.password or os.getenv('NYAA_API_PASSWORD')
|
||||
|
||||
|
||||
if not (api_username and api_password):
|
||||
raise Exception('No authorization found from arguments or environment variables.')
|
||||
|
||||
auth = (api_username, api_password)
|
||||
|
||||
data = {
|
||||
'name' : args.name,
|
||||
'category' : args.category,
|
||||
'name': args.name,
|
||||
'category': args.category,
|
||||
|
||||
'information' : args.information,
|
||||
'description' : args.description,
|
||||
'information': args.information,
|
||||
'description': args.description,
|
||||
|
||||
'anonymous' : args.anonymous,
|
||||
'hidden' : args.hidden,
|
||||
'complete' : args.complete,
|
||||
'remake' : args.remake,
|
||||
'trusted' : args.trusted,
|
||||
'anonymous': args.anonymous,
|
||||
'hidden': args.hidden,
|
||||
'complete': args.complete,
|
||||
'remake': args.remake,
|
||||
'trusted': args.trusted,
|
||||
}
|
||||
encoded_data = {
|
||||
'torrent_data' : json.dumps(data)
|
||||
encoded_data = {
|
||||
'torrent_data': json.dumps(data)
|
||||
}
|
||||
|
||||
|
||||
files = {
|
||||
'torrent' : torrent_file
|
||||
'torrent': torrent_file
|
||||
}
|
||||
|
||||
# Go!
|
||||
@@ -166,7 +181,7 @@ if __name__ == "__main__":
|
||||
|
||||
if args.raw:
|
||||
print(r.text)
|
||||
|
||||
|
||||
else:
|
||||
try:
|
||||
response = r.json()
|
||||
|
||||
Reference in New Issue
Block a user