Beispiel #1
0
def reblog_a_blog(client, post, sem):
    try:
        print('reblog start {}'.format(post.post_id))

        if post.photos is None:
            print('skip, blog {} has no detail'.format(post['post_id']))
            return None

        post = {
            'post_id': post.post_id,
            'title': post.title,
            'desc': post.desc,
            'author_name': post.author_name,
            'photos': json.loads(post.photos),
        }
        format_post = format_discuz_post(post)
        if format_post is None:
            print('skip reblog {}'.format(post['post_id']))
            return None

        for num, desc in enumerate(format_post['contents']):
            reblog_post = dict(post)
            reblog_post['desc'] = desc
            if len(format_post['contents']) > 1:
                reblog_post['title'] += '【{}】'.format(num + 1)
            tumblr_posting(client, reblog_post,
                           helper.get_config('TUMBLR', 'blog_name'))
    except TumblrLimitException as e:
        print(e)
    except Exception as e:
        print(e)
        print('reblog fail for {}'.format(post['post_id']))
        return 'end'
    finally:
        sem.release()
Beispiel #2
0
def format_discuz_post(post):
    image_count = 0
    image_total = len(post['photos'])
    if image_total < 5:
        Post.update(downloaded=3).where(
            Post.post_id == post['post_id']).execute()
        return None
    post['desc'] = '\n'.join(
        list(filter(lambda line: len(line) > 3, post['desc'].splitlines())))
    desc = ''
    replace = []
    split_count = 100
    split_name = '\n=========================\n'
    for num, line in enumerate(post['desc'].splitlines()):
        line = line.replace('{', '').replace('}', '')

        if num in replace:
            continue
        if '下载 (' in line:
            image_count += 1
            desc += '\n{}'
            replace = [num + 1]

            if image_count % split_count == 0 and (
                    image_total - image_count) > split_count // 2:
                desc += split_name

        else:
            desc = desc + '\n' + line

    if image_total - image_count > 0:
        for i in range(1, image_total - image_count + 1):
            desc += '\n{}'
            if i % split_count == 0 and (image_total - i) > split_count // 2:
                desc += split_name

    post['desc'] = desc.format(*('<img src="{}">'.format(
        helper.get_config('DISCUZ', 'base_url') + 'attachments/%s' % photo_id)
                                 for photo_id in post['photos']))
    post['contents'] = post['desc'].split(split_name)
    return post
Beispiel #3
0
 def test_load_config_success(self):
     config = helper.get_config('APP', 'debug')
     assert config == 1
Beispiel #4
0
from library import helper
import json
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "library"))
from library import helper
from discuz import Discuz
import repository

if __name__ == '__main__':
    debug = bool(helper.get_config('APP', 'debug') == 1)
    base_url = repository.ConfigRepo.get_value('base_url')
    cookies = repository.ConfigRepo.get_value('cookies')
    concur = int(helper.get_config('APP', 'concur'))
    discuz = Discuz(base_url, concur, debug)
    post = discuz.post(261394)
    print(post)
Beispiel #5
0
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "library"))
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "src"))

from library import helper
import repository
import json
from src.discuz import Discuz

# from playhouse.flask_utils import PaginatedQuery
# Add the directory containing your module to the Python path (wants absolute paths)

base_url = repository.ConfigRepo.get_value('base_url')
cookies = repository.ConfigRepo.get_value('cookies')
concur = int(helper.get_config('APP', 'concur'))
discuz = Discuz(base_url, concur).set_cookies(cookies)


async def docs(request):
    data = {
        '列表': {
            'route': '/',
            'params': {
                'cat': {
                    'rf': '最近加精',
                    'top': '本月最热',
                    'hot': '当前最热',
                    'md': '本月讨论',
                    'rp': '最近得分',
                    'tf': '本月收藏',
Beispiel #6
0
def init_client():
    return tumblpy.Tumblpy(helper.get_config('TUMBLR', 'consumer_key'),
                           helper.get_config('TUMBLR', 'consumer_secret'),
                           helper.get_config('TUMBLR', 'token'),
                           helper.get_config('TUMBLR', 'token_secret'))