def like(self, user, passw, pageid): try: self.createbrowser() self.br.open('http://m.facebook.com/login.php', timeout=10) self.br.select_form(nr=0) self.br.form['email'] = user self.br.form['pass'] = passw self.br.submit() if 'Your password was incorrect.' in self.br.response().read( ) or "We didn't recognize your email address." in self.br.response( ).read( ) or 'Sorry, your account is temporarily unavailable.' in self.br.response( ).read(): Publisher().sendMessage( "update", "Could not login with {0}".format(user)) return Publisher().sendMessage("update", "Logged in with {0}".format(user)) self.br.open('http://m.facebook.com/' + pageid, timeout=10) for yc in self.br.links(text="Unlike"): Publisher().sendMessage("update", "Already liked with {0}".format(user)) return for xc in self.br.links(text="Like"): self.br.follow_link(xc) break Publisher().sendMessage("update", "Liked with {0}".format(user)) self.br.close() except Exception, e: Publisher().sendMessage("update", "{0} with {1}".format(str(e), str(a))) self.like(user, passw, pageid)
def __init__(self, mainDir, input, inlinedWebpageDir): self.__mainDir = mainDir self.__input = input self.__langId = LangDetect.instance() self.__inlinedWebpageDir = inlinedWebpageDir if not os.path.exists(self.__inlinedWebpageDir): os.makedirs(self.__inlinedWebpageDir) htmlsDir = os.path.join(self.__inlinedWebpageDir, "htmls"); if not os.path.exists(htmlsDir): os.makedirs(htmlsDir) data = shelve.open(self.__input) self.__data = [] self.__classes = set([self.defaultClass()]) url2klass = self.__readKlassFile() logger.info("Read shelve...") for item in data.itervalues(): text = item["text"] url = item["url"] klass = self.__getKlass(url2klass, url) if not self.__ignorable(text, url): self.__data.append(RowModel(url, text, klass, self)) if klass: self.__classes.add(klass) logger.info("Done " + str(len(self.__data))) Publisher.subscribe(self._onSave, "model.save") self.__downloader = UrlDownloaderController(self) self.__downloader.start()
def runPart(self): try: logger.debug("Fetch url... (qsize=" + str(self.__queue.qsize()) + ")") url = self.__queue.get(True, 1) cachedValue = self.__cache.get(url) if cachedValue: if url.getExpandedUrl() != cachedValue["url"]: raise Exception("Different url " + url.getExpandedUrl() + " != " + cachedValue["url"]) elif "error" in cachedValue and cachedValue["error"]: url.setError() self.__mgr.afterResolveUrl(url) return else: url.setTextAndHtmlAndUrl(cachedValue["text"], cachedValue["htm"], cachedValue["real_url"]) self.__mgr.afterResolveUrl(url) return resolver = UrlStoppableResolver(url, self.__mgr, self.__cache, self) putInQueue = resolver.resolve() if putInQueue: logger.debug("Requeue url") if self.correctInternetConnection(): logger.error(u"Restart model") Publisher.sendMessage("model.start", data={"soft": True}) else: logger.error(u"Pause model") Publisher.sendMessage("model.pause", data={"soft": True}) self.__queue.put(url) except Empty: return
def _OnLinkClicked(self, event): r = event.GetRow() c = event.GetCol() url = self.__urls[r][0] if c == 5: logger.info(simplejson.dumps(url, indent="\t")) elif c == 4: Publisher.sendMessage("model.prob_dist", data = url) elif c == 3: import webbrowser webbrowser.open(url["url"])
def onSendAndClose(self, event): """ Send a message and close frame """ msg = self.msgTxt.GetValue() Publisher().sendMessage(("show.mainframe"), msg) self.Close()
def run(self): self.running = True for a in self.accounts: if self.running: try: a = a.rsplit()[0] a = a.split(':') user = a[0] passw = a[1] self.like(user, passw, self.pageid) Publisher.sendMessage('uBar', 1) except: pass else: Publisher().sendMessage( "update", "Closing thread number {0}".format(str(self.id))) return
def __init__(self, parent, title): self.working = False wx.Frame.__init__(self, parent, title=title, size=(465, 420), style=wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX) self.panel = wx.Panel(self, -1) self.sizerOne = wx.BoxSizer(wx.HORIZONTAL) self.font = wx.Font(10, wx.NORMAL, wx.NORMAL, wx.NORMAL) self.labelAccounts = wx.StaticText(self.panel, -1, "File With Accounts:", (20, 20)) self.labelAccounts.SetFont(self.font) self.labelID = wx.StaticText(self.panel, -1, "ID of the page:", (270, 20)) self.labelID.SetFont(self.font) self.labelInfo = wx.StaticText(self.panel, -1, "Logs Info:", (15, 80)) self.labelInfo.SetFont(self.font) self.labelThreads = wx.StaticText(self.panel, -1, "Number of threads: ", (150, 20)) self.labelThreads.SetFont(self.font) self.nbthreads = wx.SpinCtrl(self.panel, -1, pos=(150, 40), size=(60, -1)) self.nbthreads.SetRange(1, 25565) self.textBox = wx.TextCtrl(self.panel, 1, pos=(20, 40), size=(110, 20)) self.textBoxID = wx.TextCtrl(self.panel, 2, pos=(270, 40), size=(150, 20)) self.logslist = wx.ListBox(self.panel, 4, (15, 100), (430, 200)) self.startButton = wx.Button(self.panel, 6, "Start", (200, 360)) self.Bind(wx.EVT_BUTTON, self.onButtonPressed, id=6) self.ProgressBar = wx.Gauge(self.panel, range=100, size=(430, 20), pos=(15, 330)) Publisher().subscribe(self.updateList, "update") Publisher().subscribe(self.updateBar, "uBar") self.Show(True)
def _doSmthElse(self): if self.__refreshGui.isSet(): logger.info("Send data to GUI") self.__refreshGui.clear() data = {} data["urls"] = self.__tweetResolvedListener.finalUrls() Publisher.sendMessage("update.urls", data=data) if self.__showProbDist.isSet(): url = self.__probDistUrl self.__showProbDist.clear() self.__probDistUrl = None probDistI = TxtClassificatorWrapper.instance().probDist(url.getText()) if self.__refreshStatusBar.isSet(): self.__refreshStatusBar.clear() data = {} data["cache"] = self.__urlResolver.cacheHitRate() data["position"] = self.__iter.position() data["position_end"] = self.__iter.count() data["current_file_c"] = self.__iter.currentFile() data["last_file_c"] = self.__iter.filesCount() Publisher.sendMessage("update.statusBar", data=data)
def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent=parent) self.frame = parent Publisher().subscribe(self.showFrame, ("show.mainframe")) self.pubsubText = wx.TextCtrl(self, value="") hideBtn = wx.Button(self, label="Hide") hideBtn.Bind(wx.EVT_BUTTON, self.hideFrame) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.pubsubText, 0, wx.ALL | wx.CENTER, 5) sizer.Add(hideBtn, 0, wx.ALL | wx.CENTER, 5) self.SetSizer(sizer)
def __init__(self): self.app = wx.App() wx.Frame.__init__(self, None, title='PyNews', pos=(150,150), size=(350,200)) menuBar = wx.MenuBar() menuBar.Append(self.__buildMenuAnalyze(), "&Analyze") menuBar.Append(self.__buildMenuView(), "&View") self.SetMenuBar(menuBar) self.grid = UrlsGrid(self) self.CreateStatusBar() self.Show() self.timer = wx.Timer(self) Publisher.subscribe(self.updateUrls, "update.urls") Publisher.subscribe(self.updateStatusBar, "update.statusBar") Publisher.subscribe(self.onModelPaused, "model.paused") Publisher.subscribe(self.onModelStarted, "model.started") self.Bind(wx.EVT_TIMER, self.onTimerEvent, self.timer) self.__paused = True self.timer.Start(1000 * 10)
def onRefreshMenuClick(self, event): logger.info("Request data for GUI") Publisher.sendMessage("model.refreshGui")
def onShowTreeMap(self, event): Publisher.sendMessage("model.showTreeMap")
def onTimerEvent(self, event): logger.info("Request status for GUI") Publisher.sendMessage("model.refreshStatusBar")
def doContinueJob(self): self.continueJob() self.__urlResolver.continueWorkers() Publisher.sendMessage("model.started")
def doPauseJob(self): self.pauseJob() self.__urlResolver.pauseWorkers() Publisher.sendMessage("model.paused")
def __init__(self, gui, stream, mainDir): StoppableThread.__init__(self, "Model") self.__iter = stream.__iter__() self.__elem = None self.__gui = gui self.__softPause = True self.__urlBuilder = UrlBuilder() self.__userBuilder = UserBuilder() streamDir = os.path.join(mainDir, "stream") userDir = os.path.join(mainDir, "user") self.__tweetResolvedListener = ResolvedTweetQueue( streamDir=streamDir, userDir=userDir, userBuilder=self.__userBuilder, urlBuilder=self.__urlBuilder ) self.__urlResolver = UrlResolverManager( os.path.join(streamDir, "urlResolverCache.db2"), self.__tweetResolvedListener ) self.__refreshGui = Event() self.__refreshStatusBar = Event() self.__showProbDist = Event() self.__probDistUrl = None Publisher.subscribe(self.onPauseJob, "model.pause") Publisher.subscribe(self.onResumeJob, "model.start") Publisher.subscribe(self.onRefreshGui, "model.refreshGui") Publisher.subscribe(self.onRefreshStatusBar, "model.refreshStatusBar") Publisher.subscribe(self.onProbDist, "model.prob_dist") Publisher.subscribe(self.onShowTreeMap, "model.showTreeMap") self.doPauseJob() self.start()
def onStartPauseButtonClick(self, event): if self.__paused: Publisher.sendMessage("model.start") else: Publisher.sendMessage("model.pause")
def onSave(self, ev): Publisher.sendMessage("model.save")