Skip to content

Commit

Permalink
added --version option.
Browse files Browse the repository at this point in the history
begin addition of run mode/automatic mode.
  • Loading branch information
l3uddz committed Mar 8, 2018
1 parent c14253e commit c7cfa18
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
24 changes: 24 additions & 0 deletions misc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@
'blacklist_title_keywords': ['untitled', 'barbie'],
'allowed_countries': ['us', 'gb', 'ca']
}
},
'automatic': {
'movies': {
'interval': 24,
'anticipated': 10,
'trending': 2,
'popular': 3
},
'shows': {
'interval': 72,
'anticipated': 100,
'trending': 2,
'popular': 1
},
'notifications': {
'plex slack': {
'type': 'slack',
'webhook': 'http://'
},
'my pushover': {
'client_id': '....',
'client_secret': '....'
}
}
}
}
cfg = None
Expand Down
1 change: 1 addition & 0 deletions misc/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, file_name=None, log_level=logging.DEBUG,

# disable bloat loggers
logging.getLogger('urllib3').setLevel(logging.ERROR)
logging.getLogger('schedule').setLevel(logging.ERROR)

# init console_logger
self.console_handler = logging.StreamHandler(sys.stdout)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
backoff==1.4.3
schedule==0.4.3
attrdict==2.0.0
click==6.7
backoff==1.4.3
requests==2.18.4
42 changes: 42 additions & 0 deletions traktarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time

import click
import schedule

from media.radarr import Radarr
from media.sonarr import Sonarr
Expand All @@ -20,6 +21,7 @@

# Click
@click.group(help='Add new shows & movies to Sonarr/Radarr from Trakt lists.')
@click.version_option('1.0.0', prog_name='traktarr')
def app():
pass

Expand Down Expand Up @@ -143,6 +145,10 @@ def shows(list_type, add_limit=0, add_delay=2.5, no_search=False):
log.info("Added %d new show(s) to Sonarr", added_shows)


############################################################
# MOVIES
############################################################

@app.command(help='Add new movies to Radarr.')
@click.option('--list-type', '-t', type=click.Choice(['anticipated', 'trending', 'popular']),
help='Trakt list to process.', required=True)
Expand Down Expand Up @@ -243,6 +249,42 @@ def movies(list_type, add_limit=0, add_delay=2.5, no_search=False):
log.info("Added %d new movie(s) to Radarr", added_movies)


############################################################
# AUTOMATIC
############################################################

def automatic_shows():
log.info("Running")


def automatic_movies():
log.info("Running")


@app.command(help='Run in automatic mode.')
@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr / Radarr.',
show_default=True)
@click.option('--no-search', is_flag=True, help='Disable search when adding to Sonarr / Radarr.')
def run(add_delay=2.5, no_search=False):
# add tasks to repeat
schedule.every(1).minutes.do(automatic_movies)
schedule.every(2).minutes.do(automatic_shows)

# run schedule
log.info("Automatic mode is now running...")
while True:
try:
schedule.run_pending()
except KeyboardInterrupt:
log.info("Scheduled tasks are no longer being processed due to Ctrl + C")
break
except Exception:
log.exception("Unhandled exception occurred while processing scheduled tasks: ")
else:
time.sleep(1)
log.info("Automatic mode is now finished!")


############################################################
# MAIN
############################################################
Expand Down

0 comments on commit c7cfa18

Please sign in to comment.