本文整理汇总了Python中r2.models.Link._submit方法的典型用法代码示例。如果您正苦于以下问题:Python Link._submit方法的具体用法?Python Link._submit怎么用?Python Link._submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.Link
的用法示例。
在下文中一共展示了Link._submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_all
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def submit_all():
from r2.models import Subdigg, Account, Link, NotFound
from r2.lib.media import set_media
from r2.lib.db import queries
sr = Subdigg._by_name('testmedia')
author = Account._by_name('testmedia')
links = []
for url in test_urls:
try:
# delete any existing version of the link
l = Link._by_url(url, sr)
print "Deleting %s" % l
l._deleted = True
l._commit()
except NotFound:
pass
l = Link._submit(url, url, author, sr, '0.0.0.0')
try:
set_media(l)
except Exception, e:
print e
if g.write_query_queue:
queries.new_link(l)
links.append(l)
示例2: dfp_creative_to_link
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def dfp_creative_to_link(creative, link=None):
from r2.models import (
Link,
PROMOTE_STATUS,
)
user = get_dfp_user()
sr = get_dfp_subreddit()
attributes = dfp_template_to_dict(
creative.creativeTemplateVariableValues)
kind = "self" if attributes["selftext"] else "link"
url = attributes["url"] if kind == "link" else "self"
if not link:
link = Link._submit(
attributes["title"], url, user, sr,
ip="127.0.0.1", sendreplies=False,
)
if kind == "self":
link.url = link.make_permalink_slow()
link.is_self = True
link.selftext = attributes["selftext"]
link.promoted = True
link.promote_status = PROMOTE_STATUS.promoted
link.thumbnail_url = attributes["thumbnail_url"]
link.mobile_ad_url = attributes["mobile_ad_url"]
link.third_party_tracking = attributes["third_party_tracking"]
link.third_party_tracking_2 = attributes["third_party_tracking_2"]
link.dfp_creative_id = creative["id"]
link._commit()
return link
示例3: new_promotion
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def new_promotion(is_self, title, content, author, ip):
"""
Creates a new promotion with the provided title, etc, and sets it
status to be 'unpaid'.
"""
sr = Subreddit._byID(Subreddit.get_promote_srid())
l = Link._submit(
is_self=is_self,
title=title,
content=content,
author=author,
sr=sr,
ip=ip,
)
l.promoted = True
l.disable_comments = False
l.sendreplies = True
PromotionLog.add(l, 'promotion created')
update_promote_status(l, PROMOTE_STATUS.unpaid)
# the user has posted a promotion, so enable the promote menu unless
# they have already opted out
if author.pref_show_promote is not False:
author.pref_show_promote = True
author._commit()
# notify of new promo
emailer.new_promo(l)
return l
示例4: _create_link
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def _create_link(creative):
"""
Creates a link to allow third party voting/commenting
"""
user = _get_user()
sr = _get_subreddit()
attributes = _template_to_dict(creative)
kind = "self" if attributes["selftext"] else "link"
url = attributes["url"] if kind == "link" else "self"
link = Link._submit(
attributes["title"], url, user, sr,
ip="127.0.0.1", sendreplies=False,
)
if kind == "self":
link.url = link.make_permalink_slow()
link.is_self = True
link.selftext = attributes["selftext"]
link.promoted = True
link.third_party_promo = True
link.thumbnail_url = attributes["thumbnail_url"]
link.mobile_ad_url = attributes["mobile_ad_url"]
link.third_party_tracking = attributes["third_party_tracking"]
link.third_party_tracking_2 = attributes["third_party_tracking_2"]
link.external_id = creative["id"]
link._commit()
return link
示例5: submit_rss_links
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def submit_rss_links(srname,rss,user,titlefield='title',linkfield='link'):
#Fuck 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
示例6: submit_link
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def submit_link(user, subreddit, title, url, thumb_url):
account = Account._by_name(user)
subreddit = Subreddit._by_name(subreddit)
ip = '127.0.0.1'
# submit the link
link = Link._submit(
is_self=False,
title=title,
content=url,
author=account,
sr=subreddit,
ip=ip,
spam=False,
)
try:
# force the thumbnail before scraper_q gets in the mix
image_data = urllib.urlopen(thumb_url).read()
force_thumbnail(link, image_data)
except:
pass
# various backend processing things
queries.new_link(link)
link.update_search_index()
# wait for the amqp worker to finish up
worker.join()
print link.make_permalink_slow()
示例7: new_promotion
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def new_promotion(title, url, selftext, user, ip):
"""
Creates a new promotion with the provided title, etc, and sets it
status to be 'unpaid'.
"""
sr = Subreddit._byID(get_promote_srid())
l = Link._submit(title, url, user, sr, ip)
l.promoted = True
l.disable_comments = False
PromotionLog.add(l, 'promotion created')
if url == 'self':
l.url = l.make_permalink_slow()
l.is_self = True
l.selftext = selftext
l._commit()
# set the status of the link, populating the query queue
if c.user_is_sponsor or user.trusted_sponsor:
set_promote_status(l, PROMOTE_STATUS.accepted)
else:
set_promote_status(l, PROMOTE_STATUS.unpaid)
# the user has posted a promotion, so enable the promote menu unless
# they have already opted out
if user.pref_show_promote is not False:
user.pref_show_promote = True
user._commit()
# notify of new promo
emailer.new_promo(l)
return l
示例8: new_promotion
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def new_promotion(title, url, selftext, user, ip):
"""
Creates a new promotion with the provided title, etc, and sets it
status to be 'unpaid'.
"""
sr = Subreddit._byID(get_promote_srid())
l = Link._submit(title, url, user, sr, ip)
l.promoted = True
l.disable_comments = False
PromotionLog.add(l, "promotion created")
if url == "self":
l.url = l.make_permalink_slow()
l.is_self = True
l.selftext = selftext
l._commit()
update_promote_status(l, PROMOTE_STATUS.unpaid)
# the user has posted a promotion, so enable the promote menu unless
# they have already opted out
if user.pref_show_promote is not False:
user.pref_show_promote = True
user._commit()
# notify of new promo
emailer.new_promo(l)
return l
示例9: post_if_goal_reached
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def post_if_goal_reached(date):
# bail out if this day's already been submitted
for link in get_recent_name_submissions():
if link.revenue_date == date:
return
revenue = gold_revenue_multi([date]).get(date, 0)
goal = gold_goal_on(date)
percent = revenue / float(goal)
bucket = int(percent)
if bucket == 0:
return
buyer_count = len(gold_buyers_on(date))
template_wp = WikiPage.get(SERVERNAME_SR, "templates/selftext")
template = random.choice(template_wp._get("content").split("\r\n---\r\n"))
boilerplate = WikiPage.get(SERVERNAME_SR, "templates/boilerplate")._get("content")
selftext_template = template + "\n\n---\n\n" + boilerplate
link = Link._submit(
is_self=True,
title=date.strftime("%a %Y-%m-%d"),
content=selftext_template % {
"percent": int(percent * 100),
"buyers": buyer_count,
},
author=SYSTEM_ACCOUNT,
sr=SERVERNAME_SR,
ip="127.0.0.1",
spam=False,
)
link.flair_text = "Name pending..."
link.flair_css_class = "goal-bucket-%d-active" % bucket
link.revenue_date = date
link.revenue_bucket = bucket
link.server_names = []
link._commit()
UPVOTE = True
queries.queue_vote(SYSTEM_ACCOUNT, link, UPVOTE, "127.0.0.1")
queries.new_link(link)
link.update_search_index()
template = WikiPage.get(SERVERNAME_SR, "templates/notification-message")._get("content")
subject_template, sep, body_template = template.partition("\r\n")
for id in gold_buyers_on(date):
recipient = Account._byID(id, data=True)
send_system_message(
recipient,
subject_template,
body_template % {
"percent": int(percent * 100),
"buyers": buyer_count,
"user": recipient.name,
"link": link.url,
},
)
示例10: POST_create
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def POST_create(self, res, title, description, location, latitude, longitude, timestamp, tzoffset, ip):
if res._chk_error(errors.NO_TITLE):
res._chk_error(errors.TITLE_TOO_LONG)
res._focus('title')
res._chk_errors((errors.NO_LOCATION,
errors.NO_DESCRIPTION,
errors.INVALID_DATE,
errors.NO_DATE))
if res.error: return
meetup = Meetup(
author_id = c.user._id,
title = title,
description = description,
location = location,
latitude = latitude,
longitude = longitude,
timestamp = timestamp,
tzoffset = tzoffset
)
# Expire all meetups in the render cache
g.rendercache.invalidate_key_group(Meetup.group_cache_key())
meetup._commit()
l = Link._submit(meetup_article_title(meetup), meetup_article_text(meetup),
c.user, Subreddit._by_name('meetups'),ip, [])
l.meetup = meetup._id36
l._commit()
meetup.assoc_link = l._id
meetup._commit()
when = datetime.now(g.tz) + timedelta(0, 3600) # Leave a short window of time before notification, in case
# the meetup is edited/deleted soon after its creation
PendingJob.store(when, 'process_new_meetup', {'meetup_id': meetup._id})
#update the queries
if g.write_query_queue:
queries.new_link(l)
res._redirect(url_for(action='show', id=meetup._id36))
示例11: test_sending_an_email
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def test_sending_an_email(self):
sr = Subreddit._by_name('reddit_test0')
account = self.get_test_user()
sr.add_subscriber(account)
self.assertIn(sr._id, account.spaces)
summary_email.reset_last_email_sent_at_for_all_accounts()
assert summary_email.should_send_activity_summary_email(account)
link_url = self.make_unique_url()
new_link = Link._submit("test_get_links", link_url, account, sr, '127.0.0.1', kind='link')
queries.new_link(new_link, foreground=True)
send_email = Mock()
summary_email.send_account_summary_email(1, send_email=send_email)
self.assert_equal(1, send_email.call_count)
self.assert_equal('[email protected]', send_email.call_args[0][0])
示例12: submit_link
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def submit_link(user, subreddit, title, url, thumb_url):
account = Account._by_name(user)
subreddit = Subreddit._by_name(subreddit)
ip = '127.0.0.1'
# submit the link
link = Link._submit(title, url, account, subreddit, ip, spam=False)
# force the thumbnail before scraper_q gets in the mix
image_data = urllib.urlopen(thumb_url).read()
force_thumbnail(link, image_data)
# various backend processing things
queries.queue_vote(account, link, True, ip)
queries.new_link(link)
queries.changed(link)
print link.make_permalink_slow()
示例13: POST_create
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def POST_create(self, res, title, description, location, latitude, longitude, timestamp, tzoffset, ip):
if res._chk_error(errors.NO_TITLE):
res._chk_error(errors.TITLE_TOO_LONG)
res._focus('title')
res._chk_errors((errors.NO_LOCATION,
errors.NO_DESCRIPTION,
errors.INVALID_DATE,
errors.NO_DATE))
if res.error: return
meetup = Meetup(
author_id = c.user._id,
title = title,
description = description,
location = location,
latitude = latitude,
longitude = longitude,
timestamp = timestamp,
tzoffset = tzoffset
)
# Expire all meetups in the render cache
g.rendercache.invalidate_key_group(Meetup.group_cache_key())
meetup._commit()
l = Link._submit(meetup_article_title(meetup), meetup_article_text(meetup),
c.user, Subreddit._by_name('discussion'),ip, [])
l.meetup = meetup._id36
l._commit()
meetup.assoc_link = l._id
meetup._commit()
#update the queries
if g.write_query_queue:
queries.new_link(l)
res._redirect(url_for(action='show', id=meetup._id36))
示例14: process_post
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def process_post(self, post_data, sr):
# Prepare data for import
title = self.kill_tags_re.sub('', post_data['title'])
article = u'%s%s' % (post_data['description'],
Link._more_marker + post_data['mt_text_more'] if post_data['mt_text_more'] else u'')
ip = '127.0.0.1'
tags = [self.transform_categories_re.sub('_', tag.lower()) for tag in post_data.get('category', [])]
naive_date = datetime.datetime.strptime(post_data['dateCreated'], DATE_FORMAT)
local_date = INPUT_TIMEZONE.localize(naive_date, is_dst=False) # Pick the non daylight savings time
utc_date = local_date.astimezone(pytz.utc)
# Determine account to use for this post
account = self._get_or_create_account(post_data['author'], post_data['authorEmail'])
# Look for an existing post created due to a previous import
post = self._query_post(Link.c.ob_permalink == post_data['permalink'])
if not post:
# Create new post
post = Link._submit(title, article, account, sr, ip, tags, date=utc_date)
post.blessed = True
post.comment_sort_order = 'old'
post.ob_permalink = post_data['permalink']
post._commit()
else:
# Update existing post
post.title = title
post.article = article
post.author_id = account._id
post.sr_id = sr._id
post.ip = ip
post.set_tags(tags)
post._date = utc_date
post.blessed = True
post.comment_sort_order = 'old'
post._commit()
# Process each comment for this post
comment_dictionary = {}
comments = self._query_comments(Comment.c.link_id == post._id, Comment.c.ob_imported == True)
[self.process_comment(comment_data, comment, post, comment_dictionary)
for comment_data, comment in map(None, post_data.get('comments', []), comments)]
示例15: submit_link
# 需要导入模块: from r2.models import Link [as 别名]
# 或者: from r2.models.Link import _submit [as 别名]
def submit_link(user, subreddit, title, url, thumb_url):
account = Account._by_name(user)
subreddit = Subreddit._by_name(subreddit)
ip = '127.0.0.1'
# submit the link
link = Link._submit(title, url, account, subreddit, ip, spam=False)
# force the thumbnail before scraper_q gets in the mix
image_data = urllib.urlopen(thumb_url).read()
force_thumbnail(link, image_data)
# various backend processing things
queries.queue_vote(account, link, UPVOTE, ip)
queries.new_link(link)
link.update_search_index()
# wait for the amqp worker to finish up
worker.join()
print link.make_permalink_slow()