Created __main__ file as entry for pacakge. Updated imports.
This commit is contained in:
80
torrentSearch/__main__.py
Normal file
80
torrentSearch/__main__.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#!/usr/bin/env python3.6
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
"""Torrent Search.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
search.py <query> [-s <site>] [-f] [-p | --print] [--debug | --warning | --error]
|
||||||
|
search.py (-h | --help)
|
||||||
|
search.py --version
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h --help Show this screen
|
||||||
|
-s [site] Site to index [default: piratebay] (piratebay|jackett)
|
||||||
|
-p --print Print result to console
|
||||||
|
-f Filter response on release type
|
||||||
|
--version Show version
|
||||||
|
--debug Print all debug logs
|
||||||
|
--warning Print only logged warnings
|
||||||
|
--error Print error messages (Error/Warning)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
import logging.config
|
||||||
|
import signal
|
||||||
|
|
||||||
|
from docopt import docopt
|
||||||
|
from __init__ import __version__
|
||||||
|
|
||||||
|
from search import searchTorrentSite
|
||||||
|
from utils import ColorizeFilter, getConfig
|
||||||
|
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
formatter = logging.Formatter('%(asctime)s %(levelname)8s %(name)s | %(message)s')
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
|
||||||
|
logger = logging.getLogger('torrentSearch')
|
||||||
|
logger.addHandler(ch)
|
||||||
|
logger.setLevel(logging.ERROR) # This toggles all the logging in your app
|
||||||
|
logger.addFilter(ColorizeFilter())
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""
|
||||||
|
Main function, call searchTorrentSite
|
||||||
|
"""
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
|
arguments = docopt(__doc__, version=__version__)
|
||||||
|
|
||||||
|
if arguments['--debug']:
|
||||||
|
logger.level = logging.DEBUG
|
||||||
|
elif arguments['--warning']:
|
||||||
|
logger.level = logging.WARNING
|
||||||
|
elif arguments['--error']:
|
||||||
|
logger.level = logging.ERROR
|
||||||
|
|
||||||
|
logger.info('Torrent Searcher')
|
||||||
|
logger.debug(arguments)
|
||||||
|
|
||||||
|
# Fetch config
|
||||||
|
config = getConfig()
|
||||||
|
|
||||||
|
if arguments['-s'] in config['DEFAULT']['SITE_OPTIONS'].split(','):
|
||||||
|
site = arguments['-s']
|
||||||
|
logger.debug('site selected: {}'.format(site))
|
||||||
|
else:
|
||||||
|
logger.error('"{}" is a invalid site. Select from: {}'.format(arguments['-s'], config['DEFAULT']['SITE_OPTIONS']))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
searchTorrentSite(arguments['<query>'], site, arguments['-f'], arguments['--print'], config)
|
||||||
|
|
||||||
|
def signal_handler(signal, frame):
|
||||||
|
"""
|
||||||
|
Handle exit by Keyboardinterrupt
|
||||||
|
"""
|
||||||
|
logger.info('\nGood bye!')
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
#!/usr/bin/env python3.6
|
#!/usr/bin/env python3.6
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from xml.etree.ElementTree import fromstring
|
from xml.etree.ElementTree import fromstring
|
||||||
|
|
||||||
from torrentSearch.http_utils import build_url, fetch_url
|
from http_utils import build_url, fetch_url
|
||||||
from torrentSearch.torrent import Torrent
|
from torrent import Torrent
|
||||||
from torrentSearch.utils import humansize, representsInteger
|
from utils import humansize, representsInteger
|
||||||
|
|
||||||
logger = logging.getLogger('torrentSearch')
|
logger = logging.getLogger('torrentSearch')
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import re
|
|||||||
import logging
|
import logging
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from torrentSearch.http_utils import convert_query_to_percent_encoded_octets, build_url, fetch_url
|
from http_utils import convert_query_to_percent_encoded_octets, build_url, fetch_url
|
||||||
from torrentSearch.utils import return_re_match, deHumansize
|
from utils import return_re_match, deHumansize
|
||||||
from torrentSearch.torrent import Torrent
|
from torrent import Torrent
|
||||||
|
|
||||||
logger = logging.getLogger('torrentSearch')
|
logger = logging.getLogger('torrentSearch')
|
||||||
|
|
||||||
|
|||||||
@@ -1,96 +1,17 @@
|
|||||||
#!/usr/bin/env python3.6
|
#!/usr/bin/env python3.6
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
"""Torrent Search.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
search.py <query> [-s <site>] [-f] [-p | --print] [--debug | --warning | --error]
|
|
||||||
search.py (-h | --help)
|
|
||||||
search.py --version
|
|
||||||
|
|
||||||
Options:
|
|
||||||
-h --help Show this screen
|
|
||||||
-s [site] Site to index [default: piratebay] (piratebay|jackett)
|
|
||||||
-p --print Print result to console
|
|
||||||
-f Filter response on release type
|
|
||||||
--version Show version
|
|
||||||
--debug Print all debug logs
|
|
||||||
--warning Print only logged warnings
|
|
||||||
--error Print error messages (Error/Warning)
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import configparser
|
|
||||||
import signal
|
|
||||||
|
|
||||||
from docopt import docopt
|
from jackett import Jackett
|
||||||
|
from piratebay import Piratebay
|
||||||
from torrentSearch import __version__
|
from utils import ColorizeFilter, getConfig
|
||||||
from torrentSearch.jackett import Jackett
|
|
||||||
from torrentSearch.piratebay import Piratebay
|
|
||||||
from torrentSearch.utils import ColorizeFilter
|
|
||||||
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
ch = logging.StreamHandler()
|
|
||||||
formatter = logging.Formatter('%(asctime)s %(levelname)8s %(name)s | %(message)s')
|
|
||||||
ch.setFormatter(formatter)
|
|
||||||
|
|
||||||
logger = logging.getLogger('torrentSearch')
|
logger = logging.getLogger('torrentSearch')
|
||||||
logger.addHandler(ch)
|
|
||||||
logger.setLevel(logging.ERROR) # This toggles all the logging in your app
|
|
||||||
logger.addFilter(ColorizeFilter())
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""
|
|
||||||
Main function, call searchTorrentSite
|
|
||||||
"""
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
|
||||||
|
|
||||||
arguments = docopt(__doc__, version=__version__)
|
|
||||||
|
|
||||||
if arguments['--debug']:
|
|
||||||
logger.level = logging.DEBUG
|
|
||||||
elif arguments['--warning']:
|
|
||||||
logger.level = logging.WARNING
|
|
||||||
elif arguments['--error']:
|
|
||||||
logger.level = logging.ERROR
|
|
||||||
|
|
||||||
logger.info('Torrent Searcher')
|
|
||||||
logger.debug(arguments)
|
|
||||||
|
|
||||||
# Fetch config
|
|
||||||
config = getConfig()
|
|
||||||
|
|
||||||
if arguments['-s'] in config['DEFAULT']['SITE_OPTIONS'].split(','):
|
|
||||||
site = arguments['-s']
|
|
||||||
logger.debug('site selected: {}'.format(site))
|
|
||||||
else:
|
|
||||||
logger.error('"{}" is a invalid site. Select from: {}'.format(arguments['-s'], config['DEFAULT']['SITE_OPTIONS']))
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
searchTorrentSite(config, arguments['<query>'], site, arguments['-f'], arguments['--print'])
|
|
||||||
|
|
||||||
|
|
||||||
def getConfig():
|
|
||||||
"""
|
|
||||||
Read path and get configuartion file with site settings
|
|
||||||
|
|
||||||
:return: config settings read from 'config.ini'
|
|
||||||
:rtype: configparser.ConfigParser
|
|
||||||
"""
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config_dir = os.path.join(BASE_DIR, 'config.ini')
|
|
||||||
config.read(config_dir)
|
|
||||||
|
|
||||||
return config
|
|
||||||
|
|
||||||
def createJSONList(torrents):
|
def createJSONList(torrents):
|
||||||
"""
|
"""
|
||||||
@@ -160,13 +81,3 @@ def searchTorrentSite(config, query, site, filter, print_result):
|
|||||||
print(jsonList)
|
print(jsonList)
|
||||||
|
|
||||||
return jsonList
|
return jsonList
|
||||||
|
|
||||||
def signal_handler(signal, frame):
|
|
||||||
"""
|
|
||||||
Handle exit by Keyboardinterrupt
|
|
||||||
"""
|
|
||||||
logger.info('\nGood bye!')
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user