예제 #1
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_photo_post(post):
    tplate = Template('photo')

    kdict = post.copy()

    photo_html = '<ul>\n'

    for photo in post['photos']:
        photo_html += '<li>\n'
        caption_html = '<div class="photo">\n' + photo['caption'] + '\n</div>\n'
        try:
            loc = download_data(photo['original_size']['url'], 'image')
            photo_html += '<img src="' + loc + '" title="' + photo['original_size']['url'] + '">\n'
        except Exception:
            photo_html += '<a href="' + photo['original_size']['url'] + '">' + photo['original_size']['url'] + '</a>\n'
        photo_html += caption_html
        photo_html += '</li>\n'

    photo_html += '</ul>\n'

    kdict['photos'] = photo_html

    if key_exists_not_null('image_permalink', post):
        kdict['image_permalink'] = '<a href="' + post['image_permalink'] + '">' + post['image_permalink'] + '</a>'

    if key_exists_not_null('link_url', post):
        kdict['link_url'] = '<a href="' + post['link_url'] + '">' + post['link_url'] + '</a>'

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #2
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_link_post(post):
    tplate = Template('link')

    kdict = post.copy()

    if('link_image' in post.keys()):
        img_location = download_data(post['link_image'], 'image')
        kdict['link_image'] = '<img src="' + img_location + '" title="' + post['link_image'] + '">\n'

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #3
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_answer_post(post):
    tplate = Template('answer')

    kdict = post.copy()

    if(kdict['asking_url'] == None):
        dict.pop(kdict, 'asking_url')
    else:
        kdict['asking_url'] = '<a href="' + post['asking_url'] + '">' + post['asking_url'] + '</a>'

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #4
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def generate_index(posts):
    tplate = Template('index')

    posts = sorted(posts, key=lambda posts:posts['date'])

    rows = ''
    for p in posts:
        rows += create_index_row(p)

    kdict = {'blog_name' : posts[0]['blog_name'],
             'index_template' : rows}

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #5
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_chat_post(post):
    tplate = Template('chat')

    kdict = post.copy()

    conversation = '<ul>\n'
    for phrase in post['dialogue']:
        conversation += '<li><strong>' + phrase['label'] + '</strong> ' + phrase['phrase'] + '</li>\n'
    conversation += '</ul>\n'

    kdict['body'] = conversation

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #6
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_audio_post(post):
    tplate = Template('audio')

    kdict = post.copy()

    if 'album_art' in post.keys():
        try:
            loc = download_data(post['album_art'], 'image')
            kdict['album_art'] = '<img src="' + loc + '" title="' + post['album_art'] + '">\n'
        except Exception:
            dict.pop(kdict, 'album_art')

    if key_exists_not_null('audio_url', post):
        try:
            loc = download_data(post['audio_url'], 'audio')
            kdict['local_file'] = '<audio control><source src="' + loc + '" type="audio/mp3"></audio>\n'
        except Exception:
            pass

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #7
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_video_post(post):
    tplate = Template('video')

    kdict = post.copy()

    if key_exists_not_null('thumbnail_url', post):
        try:
            loc = download_data(post['thumbnail_url'], 'image')
            kdict['thumbnail'] = '<img src="' + loc + '" title="' + post['thumbnail_url'] + '">\n'
        except Exception:
            kdict['thumbnail'] = '<a href="' + post['thumbnail_url'] + '">' + post['thumbnail_url'] + '</a>'

    if key_exists_not_null('permalink_url', post):
        kdict['permalink_url'] = '<a href="' + post['permalink_url'] + '">' + post['permalink_url'] + '</a>'

    if key_exists_not_null('video_url', post):
        kdict['video_url'] = '<a href="' + post['video_url'] + '">' + post['video_url'] + '</a>'

    kdict['player'] = post['player'][0]['embed_code']

    return tplate.insert_keys(tplate.get_keys(), kdict)
예제 #8
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_general_post(post, type_html):
    tplate = Template('general')
    keys = tplate.get_keys()

    null_means_false_keys = ['mobile', 'bookmarklet', 'highlighted']

    kdict = {}

    for k in keys:
        try:
            if(isinstance(post[k], list) or isinstance(post[k], dict)):
                continue
            kdict[k] = post[k]
            if(k in null_means_false_keys and k == None):
                kdict[k] = False
        except KeyError:
            if(k in null_means_false_keys):
                kdict[k] = False

    kdict['tags'] = process_tags(post['tags'])
    kdict['type_template'] = type_html
    kdict['css_template'] = Template.template_style

    prev_post = get_previous_post(post)
    if(prev_post != None):
        kdict['older_post'] = get_filename(prev_post)
    else:
        kdict['older_post'] = '#'

    next_post = get_next_post(post)
    if(next_post != None):
        kdict['newer_post'] = get_filename(next_post)
    else:
        kdict['newer_post'] = '#'

    return tplate.insert_keys(keys, kdict)
예제 #9
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_quote_post(post):
    tplate = Template('quote')
    return tplate.insert_keys(tplate.get_keys(), post)
예제 #10
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
def process_text_post(post):
    tplate = Template('text')
    return tplate.insert_keys(tplate.get_keys(), post)
예제 #11
0
파일: crumblr2.py 프로젝트: BaFin/Crumblr2
    consumer_key = parser.get(default_section, 'consumer_key')
    global consumer_secret
    consumer_secret = parser.get(default_section, 'consumer_secret')
    global token
    token = parser.get(default_section, 'token')
    global token_secret
    token_secret = parser.get(default_section, 'token_secret')
    global max_connections
    max_connections = parser.get(default_section, 'max_connections')
    global dl_content
    dl_content = parser.get(default_section, 'dl_content')
    #global dl_retries
    #dl_retries = parser.get(default_section, 'dl_retries')

    return parser

if __name__ == '__main__':
    load_configuration()

    make_output_dir()
    dl_pool = []
    all_posts = load_posts()

    if(token_secret != ''):
        do_followers()
    do_posts(all_posts)
    do_index(all_posts)

    Template.copy_style_if_not_exists(output_dir)
    print 'All done. Goodbye!'