Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. from PySide.QtCore import QObject, QThread, Signal
  2. import requests
  3. import bs4
  4.  
  5.  
  6. class Worker(QThread):
  7.     def __init__(self, url, *args, **kwargs):
  8.         super().__init__(*args, **kwargs)
  9.         self.trades = 'NODATA'
  10.         self.posts = 'NODATA'
  11.         self.url = url
  12.         self.start()
  13.  
  14.     def run(self):
  15.         soup = bs4.BeautifulSoup(requests.get(self.url).text)
  16.         self.trades = soup.select('div.stat_box div.value')[0].get_text().replace(',', '')
  17.         self.posts = soup.select('div.stat_box div.value')[1].get_text()
  18.         return self
  19.  
  20.  
  21. class Outpost(QObject):
  22.     finished = Signal(Worker)
  23.  
  24.     def __init__(self, id64, *args, **kwargs):
  25.         super().__init__(*args, **kwargs)
  26.         worker = Worker('http://www.myurl.com/' + id64)
  27.         self.trades = worker.trades
  28.         self.posts = worker.posts
  29.         self.finished.emit()
  30.         self.finished.connect(worker.quit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement