Tags

,

Já aconteceu, ao clicar em um link para fazer download abriu uma nova página com uma propaganda enorme para cadastrar o seu celular e o link invertido?

Exemplo: http://www.sitenormal.com/?url=moc.oditrevnietis.www//:ptth

Aconteceu isto comigo!!! A página verdadeira estava com o endereço invertido. E para facilitar minha vida e brincar um pouco com Python e PyQT4 fiz um pequeno hack utility para organizar  o texto invertido.

Download: reversetext.py

É necessário instalar:

Segue script abaixo:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#############################################################################################
# reverse_util.py - Graphical Reverse Text Utility
#
# Using Library:
#  - PyQt4
#  - Python 2.5
#
# by Razec,  https://razec.wordpress.com
######################################June/2010################################################

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore

class HelloWindow(QtGui.QMainWindow):

 def __init__(self, win_parent = None):
 #Init the base class
 QtGui.QMainWindow.__init__(self, win_parent)
 self.create_widgets()

 def create_widgets(self):
 #Widgets
 self.label = QtGui.QLabel("Inversed Text:")
 self.invtext_edit = QtGui.QLineEdit()
 self.rev_button = QtGui.QPushButton("Revert")

 #connect signal
 QtCore.QObject.connect(self.rev_button
 , QtCore.SIGNAL("clicked()")
 , self.on_hello_clicked)

 #Vertical layout
 v_box = QtGui.QVBoxLayout()
 v_box.addWidget(self.label)
 v_box.addWidget(self.invtext_edit)
 v_box.addWidget(self.rev_button)
 #Create central widget, add layout and set
 central_widget = QtGui.QWidget()
 central_widget.setLayout(v_box)
 self.setCentralWidget(central_widget)

 def on_hello_clicked(self):
 QtGui.QMessageBox.information(self
 , "Reversed Text!"
 , "Reversed -->: %s" % self.invtext_edit.text()[::-1]
 , QtGui.QMessageBox.Ok)

if __name__ == "__main__":
 # Create the QApplication
 app = QtGui.QApplication(sys.argv)
 #The Main window
 main_window = HelloWindow()
 main_window.show()
 # Enter the main loop
 app.exec_()

O segredo do python para inverter qualquer texto é este:

"Reversed -->: %s" % self.invtext_edit.text()[::-1]

Traduzindo…

texto[::-1]

Advertisements