예제 #1
0
def get_events(args):
    events = json.loads(get_events_file(args))
    if 'ads' not in events:
        events['ads'] = []
    if 'decorations' not in events:
        events['decorations'] = []
    if 'motd' not in events:
        events['motd'] = ''
    return events
예제 #2
0
파일: ce_utils.py 프로젝트: jfalcou/infra
def get_events(cfg: Config) -> dict:
    events = json.loads(get_events_file(cfg))
    if 'ads' not in events:
        events['ads'] = []
    if 'decorations' not in events:
        events['decorations'] = []
    if 'motd' not in events:
        events['motd'] = ''
    return events
예제 #3
0
def ads_remove_cmd(args):
    events = json.loads(get_events_file(args))
    for i, ad in enumerate(events['ads']):
        if ad['id'] == args['id']:
            if args['force'] or \
                    are_you_sure('remove ad: {}'.format(ADS_FORMAT.format(ad['id'], str(ad['filter']), ad['html'])),
                                 args):
                del events['ads'][i]
                save_event_file(args, json.dumps(events))
            break
예제 #4
0
def ads_add_cmd(args):
    events = json.loads(get_events_file(args))
    new_ad = {
        'html': args['html'],
        'filter': args['filter'].split(',') if len(args['filter']) > 0 else [],
        'id': max([x['id'] for x in events['ads']]) + 1 if len(events['ads']) > 0 else 0
    }
    if are_you_sure('add ad: {}'.format(ADS_FORMAT.format(new_ad['id'], str(new_ad['filter']), new_ad['html'])), args):
        events['ads'].append(new_ad)
        save_event_file(args, json.dumps(events))
예제 #5
0
def ads_edit_cmd(args):
    events = json.loads(get_events_file(args))
    for i, ad in enumerate(events['ads']):
        if ad['id'] == args['id']:
            new_ad = {
                'id': ad['id'],
                'filter': (args['filter'].split(',') if len(args['filter']) > 0 else [])
                if args['filter'] is not None else ad['filter'],
                'html': args['html'] or ad['html']
            }
            print('{}\n{}\n{}'.format(ADS_FORMAT.format('Event', 'Filter(s)', 'HTML'),
                                      ADS_FORMAT.format('<FROM', str(ad['filter']), ad['html']),
                                      ADS_FORMAT.format('>TO', str(new_ad['filter']), new_ad['html'])))
            if are_you_sure('edit ad id: {}'.format(ad['id']), args):
                events['ads'][i] = new_ad
                save_event_file(args, json.dumps(events))
            break
예제 #6
0
파일: events.py 프로젝트: ojeda/infra
def events_to_file(cfg: Config, file: TextIO):
    """Saves the raw events file as FILE."""
    file.write(get_events_file(cfg))
예제 #7
0
파일: events.py 프로젝트: ojeda/infra
def events_to_raw(cfg: Config):
    """Dumps the events file as raw JSON."""
    print(get_events_file(cfg))
예제 #8
0
def events_to_file_cmd(args):
    with open(args['path'], mode='w') as f:
        f.write(get_events_file(args))
예제 #9
0
def events_to_raw_cmd(args):
    print(get_events_file(args))
예제 #10
0
def get_events(args):
    return json.loads(get_events_file(args))
예제 #11
0
def ads_clear_cmd(args):
    events = json.loads(get_events_file(args))
    if are_you_sure('clear all ads (Count: {})'.format(len(events['ads'])),
                    args):
        events['ads'] = []
        save_event_file(args, json.dumps(events))
예제 #12
0
def ads_list_cmd(args):
    events = json.loads(get_events_file(args))
    print(ADS_FORMAT.format('ID', 'Filters', 'HTML'))
    for ad in events['ads']:
        print(ADS_FORMAT.format(ad['id'], str(ad['filter']), ad['html']))