Esempio n. 1
0
 def fill_pref(self):
     cfg = config.tp_cfg()
     if not cfg.load():
         self.ab_entry.set_text(API_BASE)
         self.ob_entry.set_text(OAUTH_BASE)
         self.op_entry.set_text(config.get_home_dir())
         self.lc_entry.set_text('blue')
     else:
         self.ab_entry.set_text(cfg.api_base)
         self.ob_entry.set_text(cfg.oauth_base)
         self.op_entry.set_text(cfg.output_path)
         self.fn_entry.set_text(cfg.font_path)
         self.lc_entry.set_text(cfg.link_color)
         self.hp_enable.set_active(cfg.proxy_enable)
         self.ph_entry.set_text(cfg.proxy_host)
         self.pp_entry.set_text(cfg.proxy_port)
Esempio n. 2
0
 def reset_btn_clicked(self, widget, data = None):
     cfg = config.tp_cfg()        
     cfg.set_api_base(API_BASE)
     cfg.set_oauth_base(OAUTH_BASE)
     cfg.set_output_path(config.get_home_dir())
     cfg.set_link_color('blue')
     cfg.set_proxy_enable(False)
     cfg.set_proxy_host('')
     cfg.set_proxy_port('')
     cfg.save()
     self.hp_enable.set_active(cfg.proxy_enable)
     self.ab_entry.set_text(cfg.api_base)
     self.ob_entry.set_text(cfg.oauth_base)
     self.fn_entry.set_text(cfg.font_path)
     self.op_entry.set_text(cfg.output_path)
     self.lc_entry.set_text(cfg.link_color)
     self.ph_entry.set_text(cfg.proxy_host)
     self.pp_entry.set_text(cfg.proxy_port)
Esempio n. 3
0
    def oauth_request_thread(self, param = None):
        cfg = config.tp_cfg()
        cfg.load()

        self.client = oauthapi.tpOAuth(http_proxy = {
            'host': cfg.proxy_host,
            'port': cfg.proxy_port
            } if cfg.proxy_enable else None)
        self.request_token = self.client.fetch_request_token()
        if self.request_token is None:
            gtk.gdk.threads_enter()
            self.progress_bar.set_text('Fetch Request Token Failed!')
            self.oauth_area_destroy()
            self.start_button.show()
            gtk.gdk.threads_leave()
            return False
        gtk.gdk.threads_enter()
        self.progress_bar.set_text('Fetch Request Token Success!')
        gtk.gdk.threads_leave()
        self.client.authorization_token(self.request_token)
        return True
Esempio n. 4
0
    def save_btn_clicked(self, widget, data = None):
        cfg = config.tp_cfg()
        self.proxy_host = self.ph_entry.get_text()
        self.proxy_port = self.pp_entry.get_text()
        if self.hp_enable.get_active():
            self.proxy_enable = True
            if len(self.proxy_port) == 0 or len(self.proxy_host) == 0:
                self.show_warning('Please input proxy information')
                return
        else:
            self.proxy_enable = False

        self.font_path = self.fn_entry.get_text()
        if len(self.font_path) == 0:
            self.show_warning('Please input absolute path of the font file')
            return
        self.output_path = self.op_entry.get_text()
        self.link_color = self.lc_entry.get_text()
        self.api_base = self.ab_entry.get_text()
        self.oauth_base = self.ob_entry.get_text()
        if len(self.api_base) == 0:
            self.show_warning('Please input api base string')
            return
        if len(self.oauth_base) == 0:
            self.show_warning('Please input oauth base string')
            return
        cfg.set_proxy_enable(self.proxy_enable)
        cfg.set_proxy_host(self.proxy_host)
        cfg.set_proxy_port(self.proxy_port)
        cfg.set_output_path(self.output_path)
        cfg.set_font_path(self.font_path)
        cfg.set_link_color(self.link_color)
        cfg.set_api_base(self.api_base)
        cfg.set_oauth_base(self.oauth_base)
        cfg.save()
        self.show_warning('Save configuration successfully')
Esempio n. 5
0
    def start_button_clicked(self, widget, data= None):
        cfg = config.tp_cfg()
        if not cfg.load():
            self.show_warning('''
This is the first time you run tweets2pdf.
\nGo to Preference and do some settings.
''')
            return

        client = oauthapi.tpOAuth(http_proxy = {
            'host': cfg.proxy_host,
            'port': cfg.proxy_port
            } if cfg.proxy_enable else None)

        if not client.restore_access_token():
            token = client.fetch_request_token()
            if token is None:
                return
            client.authorization_token(token)
            verifier = raw_input("please input PIN code:")
            token = client.fetch_access_token(token, verifier)
            client.save_access_token()
        
        if self.tweets_type == TWEETS_OTHERS_TIMELINE or \
            self.tweets_type == TWEETS_OTHERS_FAVORITES:
            screen_name = self.sn_entry.get_text()
            if len(screen_name) == 0:
                self.show_warning('Please input screen name of the account')
                return
        else:
            screen_name = client.access_token.screen_name
        
        tweets_max_id = self.get_id_from_entry(self.matd_entry)
        tweets_min_id = self.get_id_from_entry(self.mitd_entry)
        if self.tweets_type == TWEETS_MY_TIMELINE or self.tweets_type == TWEETS_OTHERS_TIMELINE:
            default_name = 'tweets_%s.pdf' % screen_name
        elif self.tweets_type == TWEETS_RETWEETED_BY_ME:
            default_name = 'tweets_%s_rt.pdf' % screen_name
        elif self.tweets_type == TWEETS_MY_RETWEETED:
            default_name = 'tweets_%s_rted.pdf' % screen_name
        elif self.tweets_type == TWEETS_MY_FAVORITES or \
                self.tweets_type == TWEETS_OTHERS_FAVORITES:
            default_name = 'tweets_%s_fav.pdf' % screen_name

        path = cfg.output_path
        if len(path) > 0:
            if path[len(path) - 1] != '/':
                path += '/'

        pdf_name = path + default_name

        if self.wc_btn.get_active():
            has_cover = False
        else:
            has_cover = True

        tpdoc = tp_document(oauth_client = client, \
                screen_name = screen_name, \
                tweets_type = self.tweets_type, \
                pdf_name = pdf_name, \
                has_cover = has_cover, \
                tweets_min_id = tweets_min_id, \
                tweets_max_id = tweets_max_id, \
                font_path = cfg.font_path, \
                link_color = cfg.link_color, \
                main_panel = self)
        tpdoc.set_tweets_count(self.get_id_from_entry(self.tc_entry))

        self.start_button.set_sensitive(False)

        self.thread = threading.Thread(target = generate_thread, args = [[tpdoc, self]])
        self.thread.setDaemon(1)
        self.thread.start()