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


Python Login.get_config方法代码示例

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


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

示例1: __init__

# 需要导入模块: from login import Login [as 别名]
# 或者: from login.Login import get_config [as 别名]
class Controller:
    def __init__(self):
        print "init controller"
        self.login_instance = Login()
        self.logger = self.login_instance.get_logger()
        self.config = self.login_instance.get_config()
        self.cj = self.login_instance.cj
        self.cookie_dict = self.login_instance.cookie_dict
        self.cookie_str = ""
        self.opener = self.login_instance.opener
        orm.set_dblogger()
        self.session = orm.load_session()

    def is_stored_user(self, user_id):
        query = self.session.query(orm.Users)
        count = query.filter(orm.Users.idusers == user_id).count()
        self.session.commit()
        return count != 0

    def is_stored_username(self, username):
        query = self.session.query(orm.Users)
        count = query.filter(orm.Users.username == username).count()
        self.session.commit()
        return count != 0

    def get_userid_by_username(self, username):
        """
        will query the db and get the user_id by username
        """
        user_id = 0
        query = self.session.query(orm.Users.idusers, orm.Users.username)
        try:
            user_id = query.filter(orm.Users.username == username).first().idusers
        except:
            self.logger.error("query.filter(orm.Users.username == %s).first().idusers" % username)
            user_id = 0
        return user_id

    def get_followingscount_by_userid(self, user_id):
        """
        will query th db and get the followings_count by user_id
        """
        followings_count = 0
        query = self.session.query(orm.Users.followings_count, orm.Users.idusers)
        try:
            user_id = query.filter(orm.Users.idusers == user_id).first().followings_count
        except:
            self.logger.error("query.filter(orm.Users.idusers == %s).first().followings_count" % user_id)
            followings_count = 0
        return followings_count

    def store_user_into_db(self, user_home, user_info, username):
        """
        store the user into the users table
        """
        insert_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        add_user = orm.Users(
            idusers=user_home["user_id"],
            username=username,
            screen_name=user_info["screen_name"],
            gender=user_info["gender"],
            location=user_info["location"],
            description=user_info["description"],
            profile_image_url=user_info["profile_image_url"],
            followings_count=user_home["followings_count"],
            followers_count=user_home["followers_count"],
            statuses_count=user_home["statuses_count"],
            is_verified=user_info["is_verified"],
            is_daren=user_info["is_daren"],
            verify_info=user_info["verify_info"],
            insert_time=insert_time,
            tag=user_info["tag"],
            education_info=user_info["education_info"],
            career_info=user_info["career_info"],
            create_time="2000-01-01 00:00:00",
            birthday=user_info["birthday"],
            is_visited="0",
            is_picked="0",
            pick_time="2000-01-01 00:00:00",
        )
        self.session.add(add_user)
        self.session.commit()

    def update_user_is_visited(self, user_id):
        """
        change the is_visited of the user from 0 to 1,
           means that this user has been visited, and will not be visited again
        """
        try:
            self.session.query(orm.Users).filter(orm.Users.idusers == user_id).update({"is_visited": 1})
            self.session.commit()
            print "Now %s is set to be visited, namely is_visited=1" % str(user_id)
        except:
            self.logger.error("update is_visited error...user_id: %s" % user_id)

    def store_follow_into_db(self, user_id, following_id):
        """
        store the user following relationship into the follow table
        """
        try:
#.........这里部分代码省略.........
开发者ID:iswangheng,项目名称:Website_Crawler,代码行数:103,代码来源:controller.py


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