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


Python Twitter.subscribe方法代码示例

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


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

示例1: App

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import subscribe [as 别名]
class App(QApplication):
    backendReady = pyqtSignal()

    def __init__(self, args):
        QApplication.__init__(self, args)

        self.data_path = self.setup_data_path()
        self.load_config()

        self.twitter = Twitter(self.config)
        self.load_state()

        self.twitter.accountCreated.connect(self.apply_proxy)

        self.aboutToQuit.connect(self._on_shutdown)

    def setup_data_path(self):
        data_path = path('~/.mutc').expand()
        if not data_path.exists():
            data_path.mkdir()
            config_filename = path(__file__).parent / "config.default.json"
            shutil.copy(config_filename, data_path / "config.json")

        return data_path

    def apply_proxy(self, account):
        account.proxy_host = self.proxy_host
        account.proxy_port = self.proxy_port

    def load_config(self):
        with open(self.data_path / 'config.json') as fd:
            self.config = json.load(fd)

        proxy = self.config["proxy"]

        if proxy["host"] and proxy["port"]:
            self.proxy_host = proxy["host"]
            self.proxy_port = proxy["port"]
        else:
            self.proxy_host, self.proxy_port = discover_proxy()

    def save_config(self):
        with open(self.data_path / 'config.json', 'w') as fd:
            json.dump(self.config, fd)

    def save_state(self):
        panels = [(s.subscription_type, s.account, s.args)
                    for s, _ in self.twitter.panel_model.panels]
        state = {
            "accounts": self.twitter.account_model.accounts,
            "accounts_selected": self.twitter.account_model.selected,
            "panels": panels,
        }
        import pprint
        pprint.pprint(state)
        with open(self.data_path / 'state.pickle', 'wb') as fd:
            pickle.dump(state, fd)

    def load_state(self):
        try:
            with open(self.data_path / 'state.pickle', 'rb') as fd:
                state = pickle.load(fd)
        except EOFError:
            Logger("app").warn("statefile corrupted")
            return
        except IOError:
            return

        for account in state["accounts"]:
            self.apply_proxy(account)
            self.twitter.add_account(account)

        self.twitter.account_model.selected = state["accounts_selected"]

        for subscription_type, account, args in state["panels"]:
            self.twitter.subscribe({
                "account": account,
                "type": subscription_type,
                "args": args,
            })

    def _on_shutdown(self):
        self.twitter.thread.running = False
        self.twitter.thread = False

        self.save_state()
        self.save_config()

    @pyqtSlot("QVariant")
    def open_url(self, url):
        return webbrowser.open_new_tab(url)
开发者ID:Locke,项目名称:mutc,代码行数:93,代码来源:main.py


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