mirror of
https://github.com/NohamR/Ratio.py.git
synced 2025-05-24 00:38:57 +00:00
Add configuration file
This commit is contained in:
parent
363aafe901
commit
8316712c75
@ -16,8 +16,10 @@ logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
class torrent():
|
||||
|
||||
def __init__(self, torrent_tile):
|
||||
with open(torrent_tile, 'rb') as tf:
|
||||
def __init__(self, configuration):
|
||||
self.configuration = configuration
|
||||
torrent_file = self.configuration['torrent:']
|
||||
with open(torrent_file, 'rb') as tf:
|
||||
data = tf.read()
|
||||
self.b_enc = bencoding()
|
||||
self.metainfo = self.b_enc.bdecode(data)
|
||||
|
35
main.py
35
main.py
@ -1,6 +1,35 @@
|
||||
from code.torrent import torrent
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
to = torrent('test.torrent')
|
||||
rep = to.tracker_start_request()
|
||||
to.tracker_process()
|
||||
def parse_args():
|
||||
"""Create the arguments"""
|
||||
parser = argparse.ArgumentParser('\nratio.py -c <configuration-file.json>')
|
||||
parser.add_argument("-c", "--configuration", help="Configuration file")
|
||||
return parser.parse_args()
|
||||
|
||||
def load_configuration(configuration_file):
|
||||
with open(configuration_file) as f:
|
||||
configuration = json.load(f)
|
||||
|
||||
if 'torrent' not in configuration:
|
||||
return None
|
||||
|
||||
return configuration
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_args()
|
||||
if args.configuration:
|
||||
configuration = load_configuration(args.configuration)
|
||||
else:
|
||||
sys.exit()
|
||||
|
||||
if not configuration:
|
||||
sys.exit()
|
||||
|
||||
to = torrent('test.torrent')
|
||||
rep = to.tracker_start_request()
|
||||
to.tracker_process()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user