当前位置: 首页>>代码示例>>Python>>正文


Python Post.message方法代码示例

本文整理汇总了Python中models.Post.message方法的典型用法代码示例。如果您正苦于以下问题:Python Post.message方法的具体用法?Python Post.message怎么用?Python Post.message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Post的用法示例。


在下文中一共展示了Post.message方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reply_to_thread

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import message [as 别名]
def reply_to_thread(request):
	thread_name = request.POST['thread_name']
	newpost = Post();
	newpost.message = request.POST['message']
	newpost.posted_by = request.user
	newpost.topic = Thread.objects.filter(name=decode_name(thread_name))[0]
	
	newpost.save()
	args = {}
	return HttpResponseRedirect(request.POST['current_url'])
开发者ID:mlisbit,项目名称:cshub_site,代码行数:12,代码来源:views.py

示例2: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import message [as 别名]
def add_post(data, instance_id=""):
    if instance_id:
        post = Post.get_by_id(int(instance_id))
    else:
        post = Post()

    if data["name"]:
        post.name = data["name"]

    if data["email"]:
        post.email = data["email"]

    if data["twitter"]:
        post.twitter = data["twitter"]

    if data["facebook"]:
        post.facebook = data["facebook"]

    if data["phone"]:
        post.phone = data["phone"]

    if data["message"]:
        post.message = data["message"]

    if data["post_type"]:

        types = []
        for this_type in data["post_type"]:
            post_type = this_type.replace(" ", "_")
            types.append(post_type.upper())
        if post.post_type:
            for item in types:
                post.post_type.append(item)
        else:
            post.post_type = types
    else:
        post.post_type = ['NEED']

    if data["expiry"]:
        post.expiry = data["expiry"]

    if data["status"]:
        post.status = data["status"].upper()

    if data["location"]:
        post.location = data["location"]

    post.put()
    return post
开发者ID:albertpadin,项目名称:bangonph,代码行数:51,代码来源:functions.py

示例3: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import message [as 别名]
def add_post(data, instance_id=""):
    if instance_id:
        post = Post.get_by_id(int(instance_id))
    else:
        post = Post()

    if data["name"]:
        post.name = data["name"]

    if data["email"]:
        post.email = data["email"]

    if data["twitter"]:
        post.twitter = data["twitter"]

    if data["facebook"]:
        post.facebook = data["facebook"]

    if data["phone"]:
        post.phone = data["phone"]

    if data["message"]:
        post.message = data["message"]

    if data["post_type"]:
        post.post_type = data["post_type"]

    if data["expiry"]:
        post.expiry = data["expiry"]

    if data["status"]:
        post.status = data["status"].upper()

    if data["location"]:
        post.location = data["location"]

    post.put()
    return post
开发者ID:rileonard15,项目名称:bangonph,代码行数:40,代码来源:functions.py

示例4: crawl

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import message [as 别名]
def crawl(user_id,type=INITIAL_CRAWL, url=None):
    # retrieve user info
    user = User.get_by_key_name(user_id)

    if type == INITIAL_CRAWL:
        # already indexed, ignore
        if user.indexed:
            logging.info('Already crawled %d for %s' % (user.num_indexed, user_id))
            task_crawl_previous(user_id, user.previous_url)
            return

        # Initial crawl url
        url = 'https://graph.facebook.com/%s/posts?access_token=%s' % (user.id, user.access_token)

    logging.info('start crawl: type=%d user_id=%s url=%s' % (type, user_id, url))

    try:
        result = urllib2.urlopen(url)
        data = result.read()
        logging.info(data)
        json_data = json.loads(data)
        posts = []
        index = {}
        for entity in json_data['data']:
            if 'message' in entity:
                post = Post(parent=user,key_name=entity['id'],id = entity['id'],from_name = entity['from']['name'],from_id=entity['from']['id'])
                post.message = entity['message']
                post.type = entity['type']
                post.created_time = entity['created_time']
                post.likes_count = 0
                if 'likes' in entity:
                    post.likes_count = entity['likes']['count']
                post.comments_count = 0
                if 'comments' in entity:
                    post.comments_count =entity['comments']['count']
                add_page_to_index(index, entity['id'], entity['message'])
                posts.append(post)
        if len(posts):
            # store posts
            db.put(posts)
            store_index_in_db(index, user)

        # store previous url in queue
        if type == INITIAL_CRAWL:
            if 'paging' in json_data:
                if 'previous' in json_data['paging']:
                    previous = json_data['paging']['previous']
                    logging.info(previous)
                    if len(previous) > 0:
                        user.previous_url = previous

        # update user
        count = 0
        if type != INITIAL_CRAWL:
            count = user.num_indexed
        user.num_indexed = count + len(posts)
        user.last_indexed = datetime.datetime.now()
        user.indexed = True
        user.put()

        # create task for next or previous page
        if 'paging' in json_data:
            if type == INITIAL_CRAWL or type == NEXT_CRAWL:
                # store next url in queue
                if 'next' in json_data['paging']:
                    next = json_data['paging']['next']
                    logging.info(next)
                    if len(next) > 0:
                        task_crawl_next(user_id, next)
            elif type == PREVIOUS_CRAWL:
                # store previous url in queue
                if 'previous' in json_data['paging']:
                    previous = json_data['paging']['previous']
                    logging.info(previous)
                    if len(previous) > 0:
                        task_crawl_previous(user_id, previous)
    except urllib2.URLError, e:
        logging.error(e)
        logging.error(e.read())
开发者ID:hideki,项目名称:locateweb,代码行数:81,代码来源:crawler.py


注:本文中的models.Post.message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。