Esempio n. 1
0
    def save(self,arguments):
        if arguments["<output_filepath>"]:
            print ("Saving TV dates. This might take some time.")
            save_details = False

            if arguments["--details"]:
                save_details = True

            if arguments["<output_filepath>"].endswith(".xml"):
                output_file = arguments["<output_filepath>"]
            else:
                output_file = arguments["<output_filepath>"] + ".xml"

            if save_details:
                tv.get_all_programs('xml',True,export_file=output_file,verbose=True)
            else:
                tv.get_all_programs('xml',False,export_file=output_file,verbose=True)

            print ("Tv dates saved on {0}".format(output_file))
Esempio n. 2
0
    def next(self,arguments):
        def _get_next(days,show,c_year,c_month,c_day,obj):
            if days:

                results = []

                for day in days:

                    if int(day["date"]["year"]) >= c_year:
                        c_results = []

                        if int(day["date"]["year"]) == c_year:
                            if int(day["date"]["month"]) >= c_month:
                                c_results = _find_show(day,show)

                        if int(day["date"]["year"]) > c_year:
                            c_results = _find_show(day,show)

                        results += c_results

                if results:
                    r = None

                    for result in results:
                        if result["date"]["year"] == c_year:
                            if result["date"]["month"] == c_month:
                                if result["date"]["day"] > c_day:
                                    r = result; break
                            else:
                                if result["date"]["month"] > c_month:
                                    r = result; break
                        else:
                            if result["date"]["year"] > c_year:
                                r = result; break

                    if r is None:
                        obj._print_next(results[0],show)
                    else:
                        obj._print_next(r,show)

                    return True

                else:
                    print ("No planned episode finded for {0}.".format(show))
            else:
                return False

        if arguments["<show_name>"]:

            show = arguments["<show_name>"]
            c_year,c_month,c_day = time.localtime()[:3]

            if arguments["--offline"]:
                offline_file = os.path.realpath(arguments["--offline"])

                if os.path.exists(offline_file):

                    days = _xmlParse(offline_file)

                    if not _get_next(days,show,c_year,c_month,c_day,self):
                        print ("The file {0} is empty or non-readable.".format(offline_file))

                else:
                    print ("The file {0} does not exists.".format(offline_file))

            else:
                days = tv.get_all_programs('python',False,verbose=True)

                if not _get_next(days,show,c_year,c_month,c_day,self):
                    print ("Unable to get tv programs. Check your connexion.")

        else:
            print ("No show name given. See tv-query --help.")