def build_conversation(self, account, previous): if not previous: return # nothing to do previous = [drug(**previous)] #print "try to build conversation",previous[0].pid,"(%s)"%account.service Post, Conversation = self.db.Post, self.db.Conversation while True: posts = Post.find().filter_by(pid = previous[-1].reply).all() if posts: previous.append(prepare_post(posts[0].__dict__)) else: try: status = api_call(account.service, 'statuses/user_timeline', {'id': previous[-1].replied_user, 'max_id':previous[-1].reply, 'count': 1}) except: print "[ERROR] during conversion fetch" print_exc() break if not status: break # nothing fetched or empty list update = parse_post(account, "", status[0]) update['source_id'] = update['user_id'] #print account.service, "con", update['pid'] update['by_conversation'] = True Post(**update).add() previous.append(drug(**update)) if previous[-1].reply is None: break if len(previous) == 1: return # still no conversation ids = " ".join(list(map(lambda p: str(p.pid), previous[1:]))) Conversation(pid = previous[0].pid, ids = ids).save() #print "conversation", previous[0].pid, "build." self.app.reader.update()
def pages(): return { 'twitter': drug( next = next_twitter_page, get = get_twitter_friends), 'identica': drug( next = next_identica_page, get = get_identica_friends) }
def setup(self): st = self.settings st.beginGroup("url") for service in map(unicode, st.allKeys()): self.urls[service] = unicode(st.value(service).toString()) st.endGroup() st.beginGroup("service") for service in map(unicode, st.allKeys()): self.services[service] = unicode(st.value(service).toString()) st.endGroup() st.beginGroup("account") for key in map(unicode, st.allKeys()): service = unicode(st.value(key).toString()) self.accounts[key] = drug( service = service, name = key.partition("/")[2], type = self.services[service], url = self.urls[service]) st.endGroup() for key, account in self.accounts.items(): self._accounts.append(key) self.add_account_to_list(account) self.accounts[key] = account = Account(account) add_service(account.service, {'api':account.api, 'search':account.search})
def setup(self): app, st, pref = self.app, self.settings, self.app.preferences.settings self.update['user'] = app.updateUser.emit self.update['friends'] = lambda *args: \ app.updateMicroblogging.emit(args[0], app.preferences.settings.value(\ "account/"+args[0]+"/id").toString(),\ False, *args[2:]) friends = drug(twitter = [], identica = []) if pref.contains("account/twitter/id"): friends.twitter = map(unicode, QSettings("blain", "%s-twitter-friends" % pref.value("account/twitter/id").\ toString()).allKeys()) if pref.contains("account/identica/id"): friends.identica = map(unicode, QSettings("blain", "%s-identica-friends" % pref.value("account/identica/id").\ toString()).allKeys()) # format: (timestamp, func, service, user, *args) self.timers = timers = [ unicode(st.value(str(i)).toString()) for i in range(st.value("count",0).toInt()[0]) ] # add timer entries new_friends = ['twitter', 'identica'] new_friend = {'twitter':friends.twitter , 'identica':friends.identica} for timer in map(lambda t: unicode(t).split(","), timers): if timer[1] == 'user': if timer[3] in new_friend[timer[2]]: new_friend[timer[2]].remove(timer[3]) elif timer[1] == 'friends': if timer[2] in new_friends: new_friends.remove(timer[2]) for service in new_friends: timers.append("{0},friends,{1},".format(time(),service)) for service in new_friend: for i, user in enumerate(new_friend[service]): new_friend[service][i] = "{0},user,{1},{2}".\ format(time(),service,user) if new_friend['twitter'] or new_friend['identica']: timers.extend(list(sum(zip(new_friend['identica'], new_friend['twitter']), ()))) if len(new_friend['twitter']) > len(new_friend['identica']): timers.extend(new_friend['twitter'][len(new_friend['identica']):]) else: timers.extend(new_friend['identica'][len(new_friend['twitter']):]) st.setValue('count',len(timers)) for i in range(len(timers)): st.setValue(str(i), timers[i]) self.timers = list(map(lambda t: [float(t[0])] + t[1:], map(lambda t: unicode(t).split(","), timers))) self.updates.user = self.user self.updates.friends = self.friends self.timer.setInterval( pref.value("timer/interval",1e4).toInt()[0]) # 10 sec if pref.value("timer/active", True).toBool(): self.timer.start()
def __init__(self, app): if not hasattr(app, 'preferences'): print("update: need 'preferences' from app.") exit(1) self.app = app self.update = {} self.timers = [] self.updates = drug() self.timer = QTimer(app) self.settings = QSettings("blain", "timers")
def save(self): app, st, ui = self.app, self.settings, self.ui st.setValue("icon/isdark", ui.darkradioButton.isChecked()) st.setValue("color/messages/fg", self.fgcolor.name()) st.setValue("color/messages/bg", self.bgcolor.name()) self.app.notifier.saveRadioButtons() self.app.icons.update_window_icon() self.app.icons.update_tray() if self.fgcolor != self.old.fgcolor or self.bgcolor != self.old.bgcolor: self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor) self.app.reader.update_messages_colors()
def save(self): app, st, ui = self.app, self.settings, self.ui st.setValue("account/twitter/id", ui.twitteridEdit.text()) st.setValue("account/identica/id", ui.identicaidEdit.text()) st.setValue("icon/isdark", ui.darkradioButton.isChecked()) st.setValue("color/messages/fg", self.fgcolor.name()) st.setValue("color/messages/bg", self.bgcolor.name()) self.app.icons.loadWindow() if self.fgcolor != self.old.fgcolor or self.bgcolor != self.old.bgcolor: self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor) self.app.window.update_messages_colors()
def addAccount(self): pref = self.app.preferences.ui if pref.addaccountButton.text() == "wait": return # already adding an account if pref.accountidEdit.text() == "": return # is empty index = pref.accountserviceComboBox.currentIndex() if index == 0 and pref.accounturlEdit.text() == "": return # is empty too account = drug(service = services[index].name, name = unicode(pref.accountidEdit.text()), type = services[index].type, url = services[index].url) if account.url is None: url = unicode(pref.accounturlEdit.text()) if url.endswith("/"): url = url[:-1] if not "://" in url: url = u"http://" + url account.url = url if account.service is None: s = account.url.partition("//")[2].partition("/")[0].split(".") account.service = s[-2] + s[-1] # save new account pref.addaccountButton.setText("wait") st = self.settings key = u"account/{0}/{1}".format(account.service, account.name) if st.contains(key): return # allready existing -> skip st.setValue(key, account.service) key = u"service/" + account.service if not st.contains(key): st.setValue(key, account.type) st.setValue(u"url/" + account.service, account.url) self.urls[account.service] = account.url pref.accountsTabWidget.setCurrentIndex(0) self.add_account_to_list(account) key = u"{0}/{1}".format(account.service, account.name) self._accounts.append(key) self.accounts[key] = account = Account(account) # create timer events for new account self.app.updates.add_timer("friends", account.service, account.name, "") self.app.updates.add_timer( "user", account.service, account.name, account.name) if account.groups is not None: self.app.updates.add_timer("groups",account.service,account.name,"") # install service if account.service not in self.services: self.services[account.service] = account.type add_service(account.service, {'api':account.api, 'search':account.search}) pref.addaccountButton.setText("add")
def load(self): st, ui = self.settings, self.ui self.fgcolor = QColor(st.value("color/messages/fg", self.app.palette().buttonText().color().name()).toString()) self.bgcolor = QColor(st.value("color/messages/bg", self.app.palette().button().color().name()).toString()) self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor) b = st.value("icon/isdark",True).toBool() ui.darkradioButton.setChecked(b) ui.lightradioButton.setChecked(not b) ui.fgcolorButton.setStyleSheet("background-color:"+self.fgcolor.name()) ui.bgcolorButton.setStyleSheet("background-color:"+self.bgcolor.name()) if self.app.notifier.buttons: self.app.notifier.resetRadioButtons()
def load(self): st, ui = self.settings, self.ui self.fgcolor = QColor(st.value("color/messages/fg", self.app.palette().buttonText().color().name()).toString()) self.bgcolor = QColor(st.value("color/messages/bg", self.app.palette().button().color().name()).toString()) self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor) ui.identicaidEdit.setText(st.value("account/identica/id").toString()) ui.twitteridEdit.setText(st.value("account/twitter/id").toString()) b = st.value("icon/isdark",True).toBool() ui.darkradioButton.setChecked(b) ui.lightradioButton.setChecked(not b) ui.fgcolorButton.setStyleSheet("background-color:"+self.fgcolor.name()) ui.bgcolorButton.setStyleSheet("background-color:"+self.bgcolor.name())
def setup(self): app, st, pref = self.app, self.settings, self.app.preferences.ui settingspath = dirname(str(self.settings.fileName())) filterpath = pathjoin(settingspath, "filter") # copy default filters into user config if not exists(filterpath) or not isdir(filterpath): mkdir(filterpath) localfilterpath = pathjoin(app.cwd, "filter") for filename in listdir(localfilterpath): if isfile(pathjoin(localfilterpath, filename)) and \ filename.endswith(".py") and \ not exists(pathjoin(filterpath, filename)): copyfile(pathjoin(localfilterpath, filename), pathjoin( filterpath, filename)) # read filters from directory for filename in listdir(filterpath): if isfile(pathjoin(filterpath, filename)) and filename.endswith(".py"): mname = filename[:-3] fp, pathname, desc = find_module(mname,[filterpath]) try: filter = load_module(mname, fp, pathname, desc) filterinfo = fi = filter.info() if not isinstance(filterinfo, dict) or \ not ('id' in fi and 'name' in fi and \ 'filter' in fi and 'install' in \ fi and 'config' in fi and \ 'filter_description' in fi and \ 'instance_description' in fi and\ isinstance(fi['config'], dict)): print "[ERROR] filter '%s' not valid." % filename else: filterinfo = drug(**filterinfo) self._keys.append(filterinfo.id) self._filters[filterinfo.id] = filterinfo item = filterinfo.name, filterinfo.id pref.filtersComboBox.addItem(*item) pref.filtersComboBox_new.addItem(*item) finally: if fp: fp.close() # add filters to list for n in range(st.value('count', 0).toInt()[0]): fid = str(st.value("id" + str(n)).toString()) fhash = str(st.value("hash" + str(n)).toString()) if fid in self._filters: self.show_filter_instance(self._filters[fid], fhash) else: print "[WARNING] doens't found filter", fid
from PyQt4.Qt import QSettings, QListWidgetItem, QLabel from inc.parse import drug from inc.microblogging import add_service services = [ drug(name=None, url=None, type="statusnet", title="Statusnet"), drug(name="identica",url="http://identi.ca",type="statusnet",title="Identi.ca"), drug(name="twitter", url="http://twitter.com", type="twitter", title="Twitter")] apis = { "statusnet": drug( api = "{0}/api/", search = "{0}/api/search.json", ), "twitter": drug( api = "http://api.twitter.com/1/", search = "http://search.twitter.com/search.json", ), } class Account: def __init__(self, drug): api = apis[drug.type] self.groups = None self.api = api.api.format(drug.url)
return # not a statusnet service #print "updating ", account, "groups ..." if self.check_thread(id, service, "groups"): self.threads[id] = GroupsThread(self.app, account, updategroups) def start_updateGroups(self, service, account, *args): self.updateGroups(service, account, *args) service, account = unicode(service), unicode(account) self.start(service + account + u"groups") def start(self, *services): #print "starting", ", ".join(services) for service in services: if service not in self.threads: print "unknown thread %s" % service return self.threads[service].start() pages = { 'twitter': drug( next = next_twitter_page, get = get_twitter_friends), 'statusnet': drug( next = next_statusnet_page, get = get_statusnet_friends), }
def setup(self): app, st, pref = self.app, self.settings, self.app.preferences.settings account_id = {} # thread starting functions self.update['user'] = app.updateUser.emit self.update['group'] = lambda *args: app.updateGroup.emit(*args[1:]) self.update['groups'] = lambda *args: \ app.updateGroups.emit(args[1], False, *args[2:]) self.update['friends'] = lambda *args: \ app.updateMicroblogging.emit(args[0], account_id[service], False, *args[2:]) # read existing friends friends = {} for service in ["twitter", "identica"]: friends[service] = [] if pref.contains("account/%s/id" % service): account_id[service] = pref.value( "account/%s/id" % service).toString() friends[service] = map(unicode, QSettings("blain", "%s-%s-friends" % (account_id[service], service)).allKeys()) friends = drug(**friends) # read existing groups groups = [] if pref.contains("account/identica/id"): groups = map(unicode, QSettings("blain", "%s-groups" % account_id['identica']).allKeys()) # format: (timestamp, func, service, user, *args) timers = [ unicode(st.value(str(i)).toString()) for i in range(st.value("count",0).toInt()[0]) ] # find new timer entries new_friend = {'twitter':friends.twitter , 'identica':friends.identica} new_friends = new_friend.keys() new_group = groups new_groups = True for timer in map(lambda t: unicode(t).split(","), timers): if timer[1] == 'user': if timer[3] in new_friend[timer[2]]: new_friend[timer[2]].remove(timer[3]) elif timer[1] == 'friends': if timer[2] in new_friends: new_friends.remove(timer[2]) elif timer[1] == 'groups': new_groups = False elif timer[1] == 'group': if timer[3] in new_group: new_group.remove(timer[3]) # add new friend lists for service in new_friends: timers.append("{0},friends,{1},".format(time(), service)) # add groups update timer if new_groups and 'identica' in account_id: timers.append("{0},groups,,{1}".\ format(time(), account_id['identica'])) # add new groups for group in new_group: timers.append("{0},group,,{1}".format(time(), group)) # add new friends for service in new_friend: for i, user in enumerate(new_friend[service]): new_friend[service][i] = "{0},user,{1},{2}".\ format(time(),service,user) # zip list(friends) of both services together if new_friend['twitter'] or new_friend['identica']: timers.extend(list(sum(zip(new_friend['identica'], new_friend['twitter']), ()))) if len(new_friend['twitter']) > len(new_friend['identica']): timers.extend(new_friend['twitter'][len(new_friend['identica']):]) else: timers.extend(new_friend['identica'][len(new_friend['twitter']):]) # save new timers st.setValue('count',len(timers)) for i in range(len(timers)): st.setValue(str(i), timers[i]) # more python readable format timers = [ unicode(t).split(",") for t in timers ] timers = [ [float(t[0])] + t[1:] for t in timers ] self.timers = timers # start timers self.updates.user = self.user self.updates.group = self.group self.updates.groups = self.groups self.updates.friends = self.friends self.timer.setInterval( pref.value("timer/interval",1e4).toInt()[0]) # 10 sec if pref.value("timer/active", True).toBool(): self.timer.start()