Advertisement
FlyFar

adware.py

Oct 19th, 2023
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.30 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. """ Implementation of simple adware that pops multiple
  4. windows with the advertisements.
  5. """
  6.  
  7. import logging
  8. import sys
  9. import random
  10.  
  11. from PySide2.QtWidgets import QApplication, QDialog, QLabel, QVBoxLayout
  12.  
  13.  
  14. class AdWindow(QDialog):
  15.     """ This class represents ad window shown on the screen. """
  16.  
  17.     def __init__(self, ad_slogan, parent=None):
  18.         super(AdWindow, self).__init__(parent)
  19.         self.setWindowTitle("Advertisement!")
  20.  
  21.         # Create a layout so that the ad slogan is shown.
  22.         self.label = QLabel(ad_slogan)
  23.         layout = QVBoxLayout()
  24.         layout.addWidget(self.label)
  25.  
  26.         self.setLayout(layout)
  27.  
  28.     def closeEvent(self, event):
  29.         # Ignore the close event so that the ad
  30.         # can't be closed by pressing close button.
  31.         event.ignore()
  32.  
  33.  
  34. class Adware(QApplication):
  35.     """ This class represents implementation of adware. """
  36.  
  37.     def __init__(self, args):
  38.         super(Adware, self).__init__(args)
  39.  
  40.     @property
  41.     def advert_slogans(self):
  42.         """ Slogans of the promoted adds. """
  43.         return (
  44.             'Ferrari for only 9,99$!',
  45.             'John Biden is an idiot',
  46.             'Hoverboard for 99,99$!'
  47.         )
  48.  
  49.     def create_ad_window(self, ad_slogan):
  50.         """ Creates a windows showing the advertisement
  51.        slogan.
  52.  
  53.        :param str ad_slogan: Text of the ad.
  54.        """
  55.         window = AdWindow(ad_slogan=ad_slogan)
  56.         window.show()
  57.         return window
  58.  
  59.     def show_ads(self):
  60.         """ Creates the main GUI application and shows
  61.        the ads based on `:class:~Adware.advert_slogans`
  62.        """
  63.         ad_windows = []
  64.         for advert in self.advert_slogans:
  65.             # Create a new ad window.
  66.             ad_window = self.create_ad_window(advert)
  67.             # Move this window to random location on screen.
  68.             x_coordinate, y_coordinate = random.randint(1, 800), random.randint(1, 600)
  69.             ad_window.move(x_coordinate, y_coordinate)
  70.             ad_windows.append(ad_window)
  71.  
  72.         return ad_windows
  73.  
  74.  
  75. if __name__ == '__main__':
  76.     logging.basicConfig(level=logging.DEBUG)
  77.  
  78.     # Create our adware and show the ads.
  79.     adware = Adware(sys.argv)
  80.     windows = adware.show_ads()
  81.  
  82.     sys.exit(adware.exec_())
Tags: adware
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement