import os
import sys
import sentiments
import analyze_batch
import calctoxdiff
import posthist
import its
import votes


def main(folder, intervl):
    sentiments.main(folder)
    analyze_batch.main(folder, intervl)
    calctoxdiff.main(folder, intervl)
    posthist.main(folder, intervl)
    its.main(folder, 1)
    votes.main(folder, 1)
    pass


if __name__ == "__main__":
    # execute only if run as a script
    usage = sys.argv[0] + " <folder>"
    if len(sys.argv) < 2:
        print(usage)
        sys.exit(1)
    folder = sys.argv[1]
    if not os.path.isdir(folder):
        print(folder + " is not a folder")
        sys.exit(1)
    interval = 3
    if len(sys.argv) >= 3:
        if sys.argv[2].startswith("-i"):
            interval = sys.argv[2][2:]
            try:
                interval = int(interval)
            except ValueError:
                print("-i: int required")
                sys.exit(1)
            if interval < 1 or interval > 12:
                print("-i: only 1 - 12")
                sys.exit(1)
        else:
            print("unknown parameter: " + sys.argv[2])
            sys.exit(1)

    main(folder, interval)
