예제 #1
0
파일: message.py 프로젝트: TWBlueQS/TWBlue
 def onShorten(self, ev):
  urls =  twitter.utils.find_urls_in_text(self.text.GetValue())
  if len(urls) == 0:
   output.speak(_(u"There's no URL to be shortened"))
  elif len(urls) == 1:
   self.text.SetValue(self.text.GetValue().replace(urls[0], url_shortener.shorten(urls[0])))
   output.speak(_(u"URL shortened"))
  elif len(urls) > 1:
   urlList.shorten(urls, self).ShowModal()
  self.text.SetFocus()
예제 #2
0
 def shorten(self, event=None):
     urls = utils.find_urls_in_text(self.message.get_text())
     if len(urls) == 0:
         output.speak(_(u"There's no URL to be shortened"))
         self.message.text_focus()
     elif len(urls) == 1:
         self.message.set_text(self.message.get_text().replace(
             urls[0], url_shortener.shorten(urls[0])))
         output.speak(_(u"URL shortened"))
         self.message.text_focus()
     elif len(urls) > 1:
         list_urls = urlList.urlList()
         list_urls.populate_list(urls)
         if list_urls.get_response() == widgetUtils.OK:
             self.message.set_text(self.message.get_text().replace(
                 urls[list_urls.get_item()],
                 url_shortener.shorten(list_urls.get_string())))
             output.speak(_(u"URL shortened"))
             self.message.text_focus()
예제 #3
0
 def shorten_click (self, evt):
  logging.debug("URL Shorten button activated.")
  urls = self.GetURLList()
  if not urls:
   logging.debug("No URLs found in tweet. Nothing to shorten.")
   dlg_title = _('URL Shortener - No URLs')
   dlg_text = _('No URLs were found to shorten. If there is one, select the URL and click this button again.')
   dlg = wx.MessageDialog(self, dlg_text, dlg_title, wx.OK |  wx.ICON_INFORMATION)
   dlg.ShowModal()
   dlg.Destroy()
   # Set focus to the edit field by default
   self.message.SetFocus()
   #Deselect any current text.
   self.message.SetSelection(len(self.message.GetValue()),len(self.message.GetValue()))
   return 0
  logging.debug("Found at least 1 URL. Showing selection dialog.")
  if len(urls) == 1:
   url=urls[0]
  else:
   # Adapted from interface.py.
   dlg_title = _('URL Shortener - Select URL')
   dlg_text = _('Select URL to shorten.')
   dlg = wx.SingleChoiceDialog(None, dlg_title, dlg_text, urls, wx.CHOICEDLG_STYLE)
   dlg.Raise()
   if dlg.ShowModal() == wx.ID_OK:
    url = dlg.GetStringSelection()
  logging.debug("User selected URL to shorten: %s" % (url))
  clean = misc.url_cleanup(url)
  logging.debug("Clean URL (what will be replaced) is: %s" % (clean))
  surl = clean # URL to shorten
  if "://" not in surl:
   surl = "http://" + surl
  logging.debug("URL sent to shortener: %s" % (surl))
  short = url_shortener.shorten(surl, service=config.main['shortener']['urlShortener'])
  if short:
   logging.debug("Started with %s, will replace %s, shortening %s, shortened as %s" % (url, clean, surl, short))
   self.message.SetValue(self.message.GetValue().replace(clean, short))
   output.speak(_("URL Shortened."), True)
  else:
   logging.debug("Shorten failed: started with %s, will replace %s, tried shortening %s" % (url, clean, surl))
   dlg_title = _('URL Shortener - Problem')
   dlg_text = _('There was a problem shortening the selected URL.')
   dlg = wx.MessageDialog(self, dlg_text, dlg_title, wx.OK |   wx.ICON_INFORMATION)
   dlg.ShowModal()
   dlg.Destroy()
#Set focus to the edit field by default
  self.message.SetFocus()
#Deselect any current text.
  self.message.SetSelection(len(self.message.GetValue()),len(self.message.GetValue()))
예제 #4
0
 def shorten(self, event=None):
  urls = utils.find_urls_in_text(self.message.get_text())
  if len(urls) == 0:
   output.speak(_(u"There's no URL to be shortened"))
   self.message.text_focus()
  elif len(urls) == 1:
   self.message.set_text(self.message.get_text().replace(urls[0], url_shortener.shorten(urls[0])))
   output.speak(_(u"URL shortened"))
   self.message.text_focus()
  elif len(urls) > 1:
   list_urls = urlList.urlList()
   list_urls.populate_list(urls)
   if list_urls.get_response() == widgetUtils.OK:
    self.message.set_text(self.message.get_text().replace(urls[list_urls.get_item()], url_shortener.shorten(list_urls.get_string())))
    output.speak(_(u"URL shortened"))
    self.message.text_focus()
예제 #5
0
파일: commander.py 프로젝트: felixbade/Nux6
	def handle_message(self):
		message = self.bot.message
		if message.startswith(self.command_prefix):
			nocmd = False
			command = message.split()[0][1:]
			arguments = message.split()[1:]
			function = getattr(commands, command, None)
			if function is not None:
				function(arguments, self.bot)
		else:
			nocmd = True

		if hasURL(message):
			url = getLastURL(message)
			self.bot.reply(URLInfo(url).getInfo())
			if len(url) > 50 and nocmd:
				self.bot.reply(shorten(url))
예제 #6
0
파일: commands.py 프로젝트: felixbade/Nux6
def short(arguments, bot):
	url = bot.getLastURL()
	alias = None
	
	if len(arguments) == 1:
		if isURL(arguments[0]):
			url = arguments[0]
		else:
			alias = arguments[0]
	
	if len(arguments) == 2:
		url = arguments[0]
		alias = arguments[1]

	if url is None:
		return

	short_url = shorten(url, alias)
	bot.reply(short_url)
예제 #7
0
    def shorten_click(self, evt):
        logging.debug("URL Shorten button activated.")
        urls = self.GetURLList()
        if not urls:
            logging.debug("No URLs found in tweet. Nothing to shorten.")
            dlg_title = _('URL Shortener - No URLs')
            dlg_text = _(
                'No URLs were found to shorten. If there is one, select the URL and click this button again.'
            )
            dlg = wx.MessageDialog(self, dlg_text, dlg_title,
                                   wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
            # Set focus to the edit field by default
            self.message.SetFocus()
            #Deselect any current text.
            self.message.SetSelection(len(self.message.GetValue()),
                                      len(self.message.GetValue()))
            return 0
        logging.debug("Found at least 1 URL. Showing selection dialog.")
        if len(urls) == 1:
            url = urls[0]
        else:
            # Adapted from interface.py.
            dlg_title = _('URL Shortener - Select URL')
            dlg_text = _('Select URL to shorten.')
            dlg = wx.SingleChoiceDialog(None, dlg_title, dlg_text, urls,
                                        wx.CHOICEDLG_STYLE)
            dlg.Raise()
            if dlg.ShowModal() == wx.ID_OK:
                url = dlg.GetStringSelection()
        logging.debug("User selected URL to shorten: %s" % (url))
        clean = misc.url_cleanup(url)
        logging.debug("Clean URL (what will be replaced) is: %s" % (clean))
        surl = clean  # URL to shorten
        if "://" not in surl:
            surl = "http://" + surl
        logging.debug("URL sent to shortener: %s" % (surl))
        short = url_shortener.shorten(
            surl, service=config.main['shortener']['urlShortener'])
        if short:
            logging.debug(
                "Started with %s, will replace %s, shortening %s, shortened as %s"
                % (url, clean, surl, short))
            self.message.SetValue(self.message.GetValue().replace(
                clean, short))
            output.speak(_("URL Shortened."), True)
        else:
            logging.debug(
                "Shorten failed: started with %s, will replace %s, tried shortening %s"
                % (url, clean, surl))
            dlg_title = _('URL Shortener - Problem')
            dlg_text = _('There was a problem shortening the selected URL.')
            dlg = wx.MessageDialog(self, dlg_text, dlg_title,
                                   wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()


#Set focus to the edit field by default
        self.message.SetFocus()
        #Deselect any current text.
        self.message.SetSelection(len(self.message.GetValue()),
                                  len(self.message.GetValue()))
예제 #8
0
 def onGo(self, ev):
  self.parent.text.SetValue(self.parent.text.GetValue().replace(self.lista.GetStringSelection(), url_shortener.shorten(self.lista.GetStringSelection())))
  self.Destroy()