Advertisement
zfoxatis

Torrents manager

Apr 14th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.54 KB | None | 0 0
  1. #!/usr/bin/python3.2
  2. # -*- coding: Utf-8 -*-
  3.  
  4. '''
  5. program: NCore torrents manager 0.1
  6.         Ez a program Ncore torrentszerver generált oldalaiból a saját torrentlisták külső feldolgozását végzi el.
  7.         Összehasonlítja a saját seed-elt torrentjeink listáját a saját seed kötelezett torrentjeink listájával.
  8.  
  9.         Futattásához telepíteni kell: Python 3.x (http://www.python.org/download/)
  10.                                       PySide 1.x (http://qt-project.org/wiki/Category:LanguageBindings::PySide::Downloads)
  11.                                                  (vagy a linuxos tárolókból)
  12.  
  13. create by: 13.04.2013
  14. author:    zfoxatis@gmail.com
  15. license:   LGPL (http://hu.wikipedia.org/wiki/GNU_Lesser_General_Public_License)
  16.  
  17. Thanks to all developers who have created:  Python, Qt, PySide, Ubuntu, GNU
  18. '''
  19.  
  20. import sys
  21. import os
  22.  
  23. from PySide.QtGui import *
  24. from PySide.QtCore import *
  25. from html.parser import HTMLParser
  26.  
  27.  
  28. class MyScreen():
  29.     '''Képernyő felbontása és a a középpont helyének kiszámolása'''
  30.     def __init__(self):
  31.         self.resolution = QDesktopWidget().screenGeometry()
  32.  
  33.     def screenSize(self):
  34.         return self.resolution.width(),self.resolution.height()
  35.    
  36.     def screenCenterPoint(self):
  37.         return int(self.screenSize()[0]/2),int(self.screenSize()[1]/2)
  38.  
  39. class MyLabel(QLabel):
  40.     def __init__(self):
  41.         super(MyLabel,self).__init__()
  42.         self.setFont(font1)
  43.  
  44. class MyLabel2(QLabel):
  45.     def __init__(self):
  46.         super(MyLabel2,self).__init__()
  47.         self.setFont(font2)
  48.  
  49. class Font1(QFont):
  50.     def __init__(self):
  51.         super(Font1, self).__init__()
  52.         self.setFamily('Arial')
  53.         self.setBold(True)
  54.         self.setPointSize(14)
  55.        
  56. class Font2(Font1):
  57.     def __init__(self):
  58.         super(Font2, self).__init__()
  59.         self.setBold(False)
  60.         self.setPointSize(10)
  61.         self.setItalic(True)
  62.  
  63. class Font3(Font1):
  64.     def __init__(self):
  65.         super(Font3, self).__init__()
  66.         self.setPointSize(11)
  67.        
  68.  
  69. class MyHTMLParser(HTMLParser):
  70.     '''html forráskód feldolgozó'''
  71.     def __init__(self):
  72.         self.lista=[]
  73.         super(MyHTMLParser, self).__init__(strict = False)        
  74.  
  75.     def handle_starttag(self, tag, attrs):
  76.         attr={}
  77.         for name,data in attrs:
  78.             attr[name]=data
  79.         for pattern in ['title','onclick','href']: # az html tag amiben szerepel ez a 3 attributum az tartalmazza a torrent adatait
  80.             try:
  81.                 attr[pattern]
  82.             except:
  83.                 return
  84.         self.lista.append(attr['title'].strip()+', '+attr['onclick'].split(';')[0])
  85.  
  86.  
  87. class MyDialog(QDialog):
  88.     '''eredmény ablak '''
  89.     def __init__(self, tabla):
  90.         super(MyDialog, self).__init__()
  91.         self.tabla=tabla
  92.         self.setWindowTitle('Torrentek')
  93.         self.resize(900,640)
  94.         self.setModal(True)
  95.         self.setSizeGripEnabled(True)
  96.        
  97.         self.move(MyScreen().screenCenterPoint()[0]-int(self.size().width()/2),MyScreen().screenCenterPoint()[1]-int(self.size().height()/2))
  98.         self.gridLayout=QGridLayout()
  99.        
  100.         self.table =QTableWidget()
  101.         self.table.setRowCount(len(self.tabla))
  102.         self.table.setColumnCount(2)
  103.         self.table.setColumnWidth(0, 430)
  104.         self.table.setColumnWidth(1, 430)
  105.        
  106.         self.table.setHorizontalHeaderLabels(['Futtatott torrentek','Seed kötelezett torrentek' ])
  107.         self.table.setFont(font3)
  108.        
  109.         sor=0
  110.         for iteml,itemr in self.tabla:
  111.             self.litem = QTableWidgetItem(iteml)
  112.             self.ritem = QTableWidgetItem(itemr)
  113.             self.table.setItem(sor,0,self.litem)
  114.             self.table.setItem(sor,1,self.ritem)
  115.             sor+=1
  116.        
  117.         self.exitButton=QPushButton('Vissza')
  118.         self.gridLayout.addWidget(self.table,  0, 0 )
  119.         self.gridLayout.addWidget(self.exitButton, 1, 0)
  120.         self.setLayout(self.gridLayout)
  121.         self.connect(self.exitButton, SIGNAL("clicked()"),self.close)
  122.  
  123.  
  124. class MainWindow(QMainWindow):
  125.     '''főablak'''
  126.     def __init__(self,window):
  127.         super(MainWindow, self).__init__()
  128.         self.resize(940,680)
  129.        
  130.         self.myFrame=QFrame()
  131.         self.myGridLayout=QGridLayout()
  132.         self.myHBoxLayout=QHBoxLayout()
  133.         self.pasteWindow()
  134.    
  135.         self.setCentralWidget(self.myFrame)
  136.         self.setWindowTitle('my NCore torrents manager :)')
  137.         self.move(MyScreen().screenCenterPoint()[0]-int(self.size().width()/2),MyScreen().screenCenterPoint()[1]-int(self.size().height()/2))
  138.         self.show()
  139.        
  140.     def pasteWindow(self):
  141.        
  142.         self.myseed_pagehtml=QPlainTextEdit()
  143.         self.myneedseed_pagehtml=QPlainTextEdit()
  144.        
  145.         self.label1=MyLabel()
  146.         self.label1.setText('Futtatott torrentek')
  147.         self.label2=MyLabel()
  148.         self.label2.setText('Seed kötelezett torrentek')
  149.         self.label3=MyLabel2()
  150.         self.label3.setText('''A saját nevedre kattintva bejővő oldal html kódja:
  151.        1. katt a nevedre ->
  152.        2. ctrl + u ->
  153.        3. ctrl + a ->
  154.        4. ctrl + c ->
  155.        5. katt ide a szövegterületre ->
  156.        6. ctrl + v''')    
  157.         self.label4=MyLabel2()
  158.         self.label4.setText('''Az aktívitásra kattintva bejővő oldal html kódja
  159.        1. katt az aktivitásra ->
  160.        2. ctrl + u ->
  161.        3. ctrl + a ->
  162.        4. ctrl + c ->
  163.        5. katt ide a szövegterületre ->
  164.        6. ctrl + v''')    
  165.  
  166.         self.delButton1=QPushButton('Töröl')
  167.         self.delButton1.setFont(font3)
  168.         self.delButton2=QPushButton('Töröl')
  169.         self.delButton2.setFont(font3)
  170.        
  171.         self.okButton=QPushButton('Összehasonlítás')
  172.         self.okButton.setFont(font1)
  173.         self.exitButton=QPushButton('Kilépés')
  174.         self.exitButton.setFont(font1)
  175.        
  176.         self.myHBoxLayout.addWidget(self.okButton)
  177.         self.myHBoxLayout.addWidget(self.exitButton)
  178.        
  179.         self.myHBoxLayout.setStretch(0, 1)
  180.         self.myHBoxLayout.setStretch(3, 1)
  181.  
  182.         self.myGridLayout.addWidget(self.label1, 0, 0)
  183.         self.myGridLayout.addWidget(self.label2, 0, 1)
  184.         self.myGridLayout.addWidget(self.label3, 1, 0)
  185.         self.myGridLayout.addWidget(self.label4, 1, 1)
  186.         self.myGridLayout.addWidget(self.myseed_pagehtml, 2, 0)
  187.         self.myGridLayout.addWidget(self.myneedseed_pagehtml, 2, 1)
  188.         self.myGridLayout.addWidget(self.delButton1, 3, 0)
  189.         self.myGridLayout.addWidget(self.delButton2, 3, 1)
  190.         self.myGridLayout.addLayout(self.myHBoxLayout, 4,0, 1, 2 )
  191.                
  192.         self.myFrame.setLayout(self.myGridLayout)
  193.        
  194.         self.connect(self.delButton1, SIGNAL("clicked()"), self.myseed_pagehtml.clear)
  195.         self.connect(self.okButton, SIGNAL("clicked()"),self.listdialog)
  196.         self.connect(self.exitButton, SIGNAL("clicked()"),self.close)
  197.         self.connect(self.delButton2, SIGNAL("clicked()"),self.myneedseed_pagehtml.clear)
  198.        
  199.     def listdialog(self):
  200.         self.listwork()
  201.         self.listwin=MyDialog(self.tabla)
  202.         self.listwin.show()
  203.            
  204.     def listwork(self):
  205.         self.tabla=[]
  206.         parser = MyHTMLParser()
  207.         parser.feed(self.myseed_pagehtml.toPlainText())
  208.  
  209.         parser2 = MyHTMLParser()
  210.         parser2.feed(self.myneedseed_pagehtml.toPlainText())
  211.        
  212.         #print(parser.lista)
  213.         #print(parser2.lista)
  214.        
  215.         for oszlop1 in parser.lista:
  216.             self.tabla.append([oszlop1,''])
  217.        
  218.         for oszlop2 in parser2.lista:
  219.             if oszlop2 in parser.lista:
  220.                 self.tabla[parser.lista.index(oszlop2)]=[oszlop2,oszlop2]
  221.             else:
  222.                 self.tabla.append(['',oszlop2])
  223.         self.tabla.sort()
  224.  
  225. if __name__ == '__main__':
  226.     app = QApplication(sys.argv)  
  227.     app.setStyle('plastique') #windowsvista,cleanlooks,windows”, “motif”, “cde”, “plastique”, “windowsxp”, or “macintosh”.
  228.    
  229.     font1=Font1()
  230.     font2=Font2()
  231.     font3=Font3()
  232.    
  233.     QLocale.setDefault(QLocale(QLocale.Hungarian, QLocale.Hungary))
  234.     translatorFileName = "qt_"
  235.     translatorFileName += QLocale.system().name()
  236.     translator = QTranslator(app)
  237.     if translator.load(translatorFileName, QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
  238.         app.installTranslator(translator)
  239.        
  240.     window=QMainWindow()
  241.     mainwindow = MainWindow(window)
  242.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement