Esempio n. 1
0
    def create_tournament_from_directory(self, dir, reuse_html=False):

        conf_file = os.path.join(dir, 'config.json')

        if not os.path.exists(conf_file):
            conf_file = conf_gen(dir, '*.docx')

        conf_dict = json.load(open(conf_file, 'r'))

        self.tour_name = conf_dict['tournament']
        self.year = conf_dict['year']

        packets = conf_dict['packets']

        for file_entry in packets:
            packet_file = os.path.join(dir, file_entry['filename'])
            packet_author = file_entry['author']

            packet = Packet(packet_author, tournament=self.tour_name)
            try:
                packet.load_packet_from_file(packet_file, reuse_html=reuse_html)
            except PacketParserError as ex:
                self.errors.append(ex)

            self.add_packet(packet)
Esempio n. 2
0
    def create_tournament_from_directory(self, dir):

        conf_file = os.path.join(dir, 'config.json')

        if not os.path.exists(conf_file):
            conf_file = conf_gen(dir, '*.docx')

        conf_dict = json.load(open(conf_file, 'r'))

        self.tour_name = conf_dict['tournament']
        self.year = conf_dict['year']

        packets = conf_dict['packets']

        for file_entry in packets:
            packet_file = os.path.join(dir, file_entry['filename'])
            packet_author = file_entry['author']

            packet = Packet(packet_author, tournament=self.tour_name)
            packet.load_packet_from_file(packet_file)

            self.add_packet(packet)
Esempio n. 3
0
def parser_driver(doc_file, mode='json'):

    p = Packet('test')
    p.load_packet_from_file(doc_file)
    p.is_valid()
Esempio n. 4
0
    parser.add_argument('-o', '--operation', dest='operation')
    parser.add_argument('-s', '--spec', dest='spec')
    parser.add_argument('-m', '--mode', dest='mode', default='json')
    parser.add_argument('-u', '--url', dest='url')
    parser.add_argument('-y', '--year', dest='year', type=int)
    parser.add_argument('--reuse-html', type=bool, default=False)
    parser.add_argument('-op', '--output-file', dest='output_file')
    
    args = parser.parse_args()

    if args.dir is not None and args.operation == 'process':
        parse_directory(args.dir, args.mode, args.reuse_html)

    if args.file is not None and args.operation == 'test':
        packet = Packet('test')
        packet.load_packet_from_file(args.file, test=True)

    if args.file is not None and args.operation is not None:
        if args.operation == 'process':
            parser_driver(args.file)

        if args.operation == 'validate':
            validate_json(args.file)

        if args.operation == 'import':
            import_json_into_mongo(args.file)

    if args.operation == 'conf' and args.dir is not None and args.spec is not None:
        conf_gen(args.dir, args.spec)

    if args.operation == 'send' and args.url is not None and args.file is not None: