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
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
from xml.etree.ElementTree import fromstring
|
||||
|
||||
from torrentSearch.http_utils import build_url, fetch_url
|
||||
from torrentSearch.torrent import Torrent
|
||||
from torrentSearch.utils import humansize, representsInteger
|
||||
from http_utils import build_url, fetch_url
|
||||
from torrent import Torrent
|
||||
from utils import humansize, representsInteger
|
||||
|
||||
logger = logging.getLogger('torrentSearch')
|
||||
|
||||
@@ -36,7 +37,7 @@ class Jackett(object):
|
||||
"""
|
||||
Starts the call to getting result from our indexer
|
||||
:param jackett.Jackett self: object instance
|
||||
:param str query: query we want to search for
|
||||
:param str query: query we want to search for
|
||||
:return: list of results we found from scraping jackett output based on query
|
||||
:rtype: list
|
||||
"""
|
||||
|
||||
@@ -4,9 +4,9 @@ import re
|
||||
import logging
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from torrentSearch.http_utils import convert_query_to_percent_encoded_octets, build_url, fetch_url
|
||||
from torrentSearch.utils import return_re_match, deHumansize
|
||||
from torrentSearch.torrent import Torrent
|
||||
from http_utils import convert_query_to_percent_encoded_octets, build_url, fetch_url
|
||||
from utils import return_re_match, deHumansize
|
||||
from torrent import Torrent
|
||||
|
||||
logger = logging.getLogger('torrentSearch')
|
||||
|
||||
|
||||
@@ -1,96 +1,17 @@
|
||||
#!/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 argparse
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
import logging.config
|
||||
import configparser
|
||||
import signal
|
||||
|
||||
from docopt import docopt
|
||||
|
||||
from torrentSearch import __version__
|
||||
from torrentSearch.jackett import Jackett
|
||||
from torrentSearch.piratebay import Piratebay
|
||||
from torrentSearch.utils import ColorizeFilter
|
||||
from jackett import Jackett
|
||||
from piratebay import Piratebay
|
||||
from utils import ColorizeFilter, getConfig
|
||||
|
||||
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.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):
|
||||
"""
|
||||
@@ -108,7 +29,7 @@ def createJSONList(torrents):
|
||||
|
||||
# This should be done front_end!
|
||||
# I.E. filtering like this should be done in another script
|
||||
# and should be done with the shared standard for types.
|
||||
# and should be done with the shared standard for types.
|
||||
# PS: Is it the right move to use a shared standard? What
|
||||
# happens if it is no longer public?
|
||||
def chooseCandidate(torrent_list):
|
||||
@@ -147,26 +68,16 @@ def searchTorrentSite(config, query, site, filter, print_result):
|
||||
config['PIRATEBAY']['LIMIT'], config['PIRATEBAY']['SSL'])
|
||||
torrents_found = pirate.search(query)
|
||||
elif site == 'jackett':
|
||||
jackett = Jackett(config['JACKETT']['APIKEY'], config['JACKETT']['HOST'],
|
||||
jackett = Jackett(config['JACKETT']['APIKEY'], config['JACKETT']['HOST'],
|
||||
config['JACKETT']['PATH'], config['JACKETT']['LIMIT'], config.getboolean('JACKETT', 'SSL'))
|
||||
torrents_found = jackett.search(query)
|
||||
|
||||
if (filter):
|
||||
torrents_found = chooseCandidate(torrents_found)
|
||||
|
||||
|
||||
jsonList = createJSONList(torrents_found)
|
||||
|
||||
if (print_result):
|
||||
print(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