Ejemplo n.º 1
0
def submit_rss_links(srname,rss,user,titlefield='title',linkfield='link'):
    #F**k the API, let's just do it the way we would if we were really doing it.  This avoids screwing around with cookies and so forth...
    feed=fetch_feed(rss)
    if feed is None:
        return
    ac=Account._byID(user)
    sr=Subsciteit._by_name(srname)
    ip='0.0.0.0'
    niceify=False
    if domain(rss)=="arxiv.org":
        niceify=dict(find="\(arXiv:.*?\)",replace="")
    #Let's randomize why not...
    random.shuffle(feed.entries)
    for article in feed.entries:
	#This can take all night if it has to, we don't want to hammer the server into oblivios
	sleep(1)
        kw = fetch_article(article,titlefield=titlefield,linkfield=linkfield,niceify=niceify)
        if kw is None:
	    continue
	l = Link._submit(kw['title'],kw['link'],ac,sr,ip,spam=False)
	l._commit()
	l.set_url_cache()
	#We don't really need auto-submitted links to be vote on...
	queries.queue_vote(ac,l,True,ip,cheater=False)
	queries.new_link(l)
	changed(l)
	print "Submitted %s" % article[titlefield]
	sleep(.1)
    return
Ejemplo n.º 2
0
    def get_subsciteit(self):
        """checks if the current url refers to a subsciteit and returns
        that subsciteit object.  The cases here are:

          * the hostname is unset or is g.domain, in which case it
            looks for /r/XXXX or /sciteits.  The default in this case
            is Default.
          * the hostname is a cname to a known subsciteit.

        On failure to find a subsciteit, returns None.
        """
        from pylons import g
        from r2.models import Subsciteit, Sub, NotFound, DefaultSR
        try:
            if not self.hostname or self.hostname.startswith(g.domain):
                if self.path.startswith('/r/'):
                    return Subsciteit._by_name(self.path.split('/')[2])
                elif self.path.startswith('/sciteits/'):
                    return Sub
                else:
                    return DefaultSR()
            elif self.hostname:
                return Subsciteit._by_domain(self.hostname)
        except NotFound:
            pass
        return None
Ejemplo n.º 3
0
    def degolden(self, account, severe=False):

        if severe:
            account.gold_charter = False
            Award.take_away("charter_subscriber", account)

        Award.take_away("sciteit_gold", account)
        account.gold = False
        account._commit()

        if g.lounge_sciteit and not getattr(account, "gold_charter", False):
            sr = Subsciteit._by_name(g.lounge_sciteit)
            sr.remove_contributor(account)
Ejemplo n.º 4
0
def subscribe_to_blog_and_annoucements(filename):
    import re
    from time import sleep
    from r2.models import Account, Subsciteit

    r_blog = Subsciteit._by_name("blog")
    r_announcements = Subsciteit._by_name("announcements")

    contents = file(filename).read()
    numbers = [ int(s) for s in re.findall("\d+", contents) ]

#    d = Account._byID(numbers, data=True)

#   for i, account in enumerate(d.values()):
    for i, account_id in enumerate(numbers):
        account = Account._byID(account_id, data=True)

        for sr in r_blog, r_announcements:
            if sr.add_subscriber(account):
                sr._incr("_ups", 1)
                print ("%d: subscribed %s to %s" % (i, account.name, sr.name))
            else:
                print ("%d: didn't subscribe %s to %s" % (i, account.name, sr.name))
Ejemplo n.º 5
0
def run():
    #rss = get_sr_rss()
    #names = rss.keys()
    #Build tree order, this will be from root to leaves.
    order=build_sr_tree(Subsciteit._by_name(g.default_sr)._id)
    #Populate RSS in the other order...
    order.reverse()
    for sr_id in order:
        sr = Subsciteit._byID(sr_id)
	if sr.rss_source:
	    #ac=Account._byID(srob.moderators[0])
	    ac=Account._by_name(g.system_user)
            print "Populating %s as %s using feed |%s|" % (sr.name,ac.name,sr.rss_source)
            submit_rss_links(sr.name,sr.rss_source,user=ac._id)
Ejemplo n.º 6
0
    def by_sr_merged(cls, sr, _update=False):
        if sr.name == g.default_sr:
            return cls.by_sr(sr)

        my_adsrs =     cls.by_sr(sr)
        global_adsrs = cls.by_sr(Subsciteit._by_name(g.default_sr, stale=True))

        seen = {}
        for adsr in my_adsrs:
            seen[adsr._thing1.codename] = True
        for adsr in global_adsrs:
            if adsr._thing1.codename not in seen:
                my_adsrs.append(adsr)

        return my_adsrs
Ejemplo n.º 7
0
    def engolden(self, account, days):
        account.gold = True

        now = datetime.now(g.display_tz)

        existing_expiration = getattr(account, "gold_expiration", None)
        if existing_expiration is None or existing_expiration < now:
            existing_expiration = now
        account.gold_expiration = existing_expiration + timedelta(days)

        description = "Since " + now.strftime("%B %Y")
        trophy = Award.give_if_needed("sciteit_gold", account,
                                     description=description,
                                     url="/help/gold")
        if trophy and trophy.description.endswith("Member Emeritus"):
            trophy.description = description
            trophy._commit()
        account._commit()

        account.friend_rels_cache(_update=True)

        if g.lounge_sciteit:
            sr = Subsciteit._by_name(g.lounge_sciteit)
            sr.add_contributor(account)
Ejemplo n.º 8
0
def copy_karmas():
    sciteit = Subsciteit._by_name('sciteit.com')
    for user in all_users():
        print user.name, user.link_karma, user.comment_karma
        user.incr_karma('link', sciteit, user.link_karma)
        user.incr_karma('comment', sciteit, user.comment_karma)