Skip to content

Commit

Permalink
lint check and cleanup for api/info
Browse files Browse the repository at this point in the history
  • Loading branch information
kyamiko committed Jun 3, 2017
1 parent 807eb9b commit 0c868fd
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions utils/api_info_v2.py
Expand Up @@ -19,27 +19,32 @@

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='Query torrent info on Nyaa.si', epilog=environment_epillog)
parser = argparse.ArgumentParser(
description='Query torrent info on Nyaa.si', epilog=environment_epillog)

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')
conn_group.add_argument('--host', help='Select another api host (for debugging purposes)')

parser.add_argument('-q', '--query', required=True, help='Torrent by id or hash Required.')

parser.add_argument('--raw', default=False, action='store_true', help='Print only raw response (JSON)')
parser.add_argument('--raw', default=False, action='store_true',
help='Print only raw response (JSON)')


def easy_file_size(filesize):
for prefix in ['B','KiB','MiB','GiB','TiB']:
for prefix in ['B', 'KiB', 'MiB', 'GiB', 'TiB']:
if filesize < 1024.0:
return '{0:.1f} {1}'.format(filesize, prefix)
filesize = filesize / 1024.0
return '{0:.1f} {1}'.format(filesize, prefix)


if __name__ == '__main__':
args = parser.parse_args()

Expand All @@ -56,10 +61,9 @@ def easy_file_size(filesize):
if not (matchID or matchHASH):
raise Exception('Query was not a valid id or valid hash.')


api_info_url = api_host + API_INFO + '/' + api_query

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):
Expand Down Expand Up @@ -91,5 +95,4 @@ def easy_file_size(filesize):
rj['is_complete'] = 'Yes' if rj['is_complete'] else 'No'
rj['is_remake'] = 'Yes' if rj['is_remake'] else 'No'
print("Torrent #{} '{}' uploaded by '{}' ({}) (Created on: {}) ({} - {}) (Trusted: {}, Complete: {}, Remake: {})\n{}".format(
rj['id'], rj['name'], rj['submitter'], rj['filesize'], rj['creation_date'], rj['main_category'], rj['sub_category'],
rj['is_trusted'], rj['is_complete'], rj['is_remake'], rj['magnet']))
rj['id'], rj['name'], rj['submitter'], rj['filesize'], rj['creation_date'], rj['main_category'], rj['sub_category'], rj['is_trusted'], rj['is_complete'], rj['is_remake'], rj['magnet']))

0 comments on commit 0c868fd

Please sign in to comment.