Example #1
0
def links_name_cmd(args):
    link_from = args['from']
    if len(link_from) < 6:
        raise RuntimeError('from length must be at least 6')
    if len(args['to']) < 6:
        raise RuntimeError('to length must be at least 6')
    base_link = get_short_link(link_from)
    if not base_link:
        raise RuntimeError('Couldn\'t find base link {}'.format(link_from))
    base_link['prefix']['S'] = args['to'][0:6]
    base_link['unique_subhash']['S'] = args['to']
    base_link['stats']['M']['clicks']['N'] = '0'
    base_link['creation_ip']['S'] = '0.0.0.0'
    # It's us, so we don't care about "anonymizing" the time
    base_link['creation_date']['S'] = datetime.datetime.utcnow().isoformat()
    title = input('Link title: ')
    author = input('Author(s): ')
    if len(author) == 0:
        # We explicitly ignore author = . in the site code
        author = '.'
    project = input('Project: ')
    description = input('Description: ')
    base_link['named_metadata'] = {'M': {
        'title': {'S': title},
        'author': {'S': author},
        'project': {'S': project},
        'description': {'S': description}
    }}
    print('New link: {}'.format(pprint(base_link)))
    if are_you_sure('create new link named {}'.format(args['to']), args):
        put_short_link(base_link)
Example #2
0
def links_update_cmd(args):
    link_to = args['to']
    link_from = args['from']
    if len(link_from) < 6:
        raise RuntimeError('from length must be at least 6')
    if len(args['to']) < 6:
        raise RuntimeError('to length must be at least 6')
    base_link = get_short_link(link_from)
    if not base_link:
        raise RuntimeError('Couldn\'t find base link {}'.format(link_from))
    link_to_update = get_short_link(link_to)
    if not link_to_update:
        raise RuntimeError('Couldn\'t find existing short link {}'.format(link_to))
    link_to_update['full_hash'] = base_link['full_hash']
    print('New link: {}'.format(pprint(link_to_update)))
    if are_you_sure('update link named {}'.format(link_to), args):
        put_short_link(link_to_update)
Example #3
0
def links_update(link_from: str, link_to: str):
    """Update a link; point LINK_FROM to existing LINK_TO."""
    if len(link_from) < 6:
        raise RuntimeError('from length must be at least 6')
    if len(link_to) < 6:
        raise RuntimeError('to length must be at least 6')
    base_link = get_short_link(link_from)
    if not base_link:
        raise RuntimeError('Couldn\'t find base link {}'.format(link_from))
    link_to_update = get_short_link(link_to)
    if not link_to_update:
        raise RuntimeError(
            'Couldn\'t find existing short link {}'.format(link_to))
    link_to_update['full_hash'] = base_link['full_hash']
    print('New link: {}'.format(pformat(link_to_update)))
    if are_you_sure('update link named {}'.format(link_to)):
        put_short_link(link_to_update)