Example #1
0
    def __init__(self, site):
        # Patch typogrify
        from typogrify import filters
        original_process_ignores = filters.process_ignores
        filters.applyfilters = lambda text: self.owntypo(filters.smartypants(text))
        filters.process_ignores = self.process_ignores(original_process_ignores)

        # Don't use widont
        filters.widont = lambda t: t
Example #2
0
def typogrify(data):
    if typo is None:
        req_missing(['typogrify'], 'use the typogrify filter')

    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #3
0
def typogrify(data):
    if typo is None:
        req_missing(['typogrify', 'use the typogrify filter'])

    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #4
0
def typogrify(data):
    global typogrify_filter
    if typo is None:
        raise Exception("To use the typogrify filter, you need to install typogrify.")
    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    #data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #5
0
def typogrify_sans_widont(data):
    # typogrify with widont disabled because it caused broken headline
    # wrapping, see issue #1465
    if typo is None:
        req_missing(['typogrify'], 'use the typogrify_sans_widont filter')

    data = typo.amp(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #6
0
def typogrify(data):
    """Prettify text with typogrify."""
    if typo is None:
        req_missing(["typogrify"], "use the typogrify filter")

    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #7
0
def typogrify_sans_widont(data):
    # typogrify with widont disabled because it caused broken headline
    # wrapping, see issue #1465
    if typo is None:
        req_missing(['typogrify'], 'use the typogrify_sans_widont filter')

    data = typo.amp(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #8
0
def typogrify(data):
    global typogrify_filter
    if typo is None:
        raise Exception(
            "To use the typogrify filter, you need to install typogrify.")
    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    #data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #9
0
def typogrify_sans_widont(data):
    """Prettify text with typogrify, skipping the widont filter."""
    # typogrify with widont disabled because it caused broken headline
    # wrapping, see issue #1465
    if typo is None:
        req_missing(["typogrify"], "use the typogrify_sans_widont filter")

    data = typo.amp(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #10
0
def typogrify(data):
    """Prettify text with typogrify."""
    if typo is None:
        req_missing(['typogrify'], 'use the typogrify filter', optional=True)
        return data

    data = _normalize_html(data)
    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #11
0
def typogrify(data):
    """Prettify text with typogrify."""
    if typo is None:
        req_missing(['typogrify'], 'use the typogrify filter', optional=True)
        return data

    data = _normalize_html(data)
    data = typo.amp(data)
    data = typo.widont(data)
    data = typo.smartypants(data)
    # Disabled because of typogrify bug where it breaks <title>
    # data = typo.caps(data)
    data = typo.initial_quotes(data)
    return data
Example #12
0
def typogrify_no_widont(value):
    value = Typogrify.amp(value)
    value = Typogrify.smartypants(value)
    value = Typogrify.caps(value)
    value = Typogrify.initial_quotes(value)
    return value
Example #13
0
def parse():
    """
    Parses the data CSV to JSON.
    """
    with open('data/data.csv', 'rb') as readfile:
        rows = list(csv.DictReader(readfile))

    print "Start parse(): %i rows." % len(rows)

    speeches = []
    speeches_by_tag = {}

    for row in rows:
        for k, v in row.items():
            row[k] = v.strip()

        row['year'] = None
        row['youtube_id'] = None
        row['vimeo_id'] = None

        if not row['name']:
            #print 'Skipping row without name'
            continue

        if row['date']: 
            if re.match('\d{1,2}/\d{1,2}/\d{4}', row['date']):
                try:
                    month, day, year = map(int, row['date'].split('/'))
                except:
                    print 'Unrecognized date format: "%s"' % row['date']
                    row['date'] = None

                row['year'] = year

                # NOTE: nonsense so month will format correctly
                # (strftime doens't work on dates before 1900)
                d = datetime.date(2000, month, day)

                row['date'] = '%s %i, %i' % (d.strftime('%B'), day, year) 
            elif re.match('\d{4}', row['date']):
                year = int(row['date'])

                row['year'] = year
                row['date'] = '%i' % year
            else:
                print 'Unrecognized date format: "%s"' % row['date']
                row['date'] = None
        else:
            print 'No date for %(name)s at %(school)s' % row 
            row['date'] = None

        if row['video_url']:
            o = urlparse(row['video_url'])

            if o.netloc.find('youtu') >= 0:
                if parse_qs(o.query):
                    row['youtube_id'] = parse_qs(o.query)['v'][0]
                else:
                    row['youtube_id'] = o.path.split('/')[-1]
            elif o.netloc.find('vimeo') >= 0:
                row['vimeo_id'] = o.path.split('/')[-1]

        if row['money_quote']:
            row['money_quote'] = smartypants(row['money_quote'].strip('"'))

        tags = [t.strip().lower() for t in row['take_homes'].replace(',', ';').split(';')]
        row['tags'] = []

        for tag in tags:
            if not tag:
                continue

            if tag not in app_config.TAGS:
                print 'Unrecognized tag: "%s" (%s)' % (tag, row['name']) 
                continue

            row['tags'].append(tag)

            if tag not in speeches_by_tag:
                speeches_by_tag[tag] = [] 
        
            speeches_by_tag[tag].append(row)

        row['slug'] = slugify(row)
        row['name'] = smartypants(row['name'])
        row['school'] = smartypants(row['school'])

        speeches.append(row)

    # Generate related speeches
    for speech in speeches:
        speech['related'] = {}

        for tag in speech['tags']:
            speech['related'][tag] = []
            next_speech = None

            for index, tag_speech in enumerate(speeches_by_tag[tag]):
                if tag_speech['slug'] == speech['slug']:
                    if index + 1 < len(speeches_by_tag[tag]):
                        next_speech = index + 1
                    else:
                        next_speech = 0

            speech['related'][tag].append({
                'slug': speeches_by_tag[tag][next_speech]['slug'],
                'name': speeches_by_tag[tag][next_speech]['name'],
                'school': speeches_by_tag[tag][next_speech]['school'],
                'year': speeches_by_tag[tag][next_speech]['year'],
                'img': speeches_by_tag[tag][next_speech]['img']
            })


    # Strip unused fields to keep filesize down
    del row['take_homes']
    del row['former_labels_ref']
    del row['former_field_ref']
    del row['former_mood_ref']
    del row['money_quote2']

    # Render complete data
    with open('www/static-data/data.json', 'w') as f:
        f.write(json.dumps(speeches))

    for tag, speeches in speeches_by_tag.items():
        print '%s: %i' % (tag, len(speeches))

    thin_speeches = []

    for speech in speeches:
        thin_speeches.append({
            'slug': speech['slug'],
            'name': speech['name'],
            'school': speech['school'],
            'tags': speech['tags'],
            'year': speech['year']
        })

    # Render thin data for index
    with open('www/static-data/data-thin.json', 'w') as f:
        f.write(json.dumps(thin_speeches))

    print "Finished."
Example #14
0
def smartypants_filter(s):
    return smartypants(s)
Example #15
0
def typogrify_no_widont(value):
    value = Typogrify.amp(value)
    value = Typogrify.smartypants(value)
    value = Typogrify.caps(value)
    value = Typogrify.initial_quotes(value)
    return value