本文整理汇总了Python中hackernews.HackerNews.get_item方法的典型用法代码示例。如果您正苦于以下问题:Python HackerNews.get_item方法的具体用法?Python HackerNews.get_item怎么用?Python HackerNews.get_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hackernews.HackerNews
的用法示例。
在下文中一共展示了HackerNews.get_item方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Hacker
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
class Hacker(object):
def __init__(self, vim):
self.vim = vim
self.hn = HackerNews()
self.urls = None
@neovim.command("Test")
def test(self):
self.vim.command("vsplit")
@neovim.command('HackerNews')
def fill_buffer(self):
stories = []
urls = {}
for story in self.hn.top_stories()[0:30]:
item = self.hn.get_item(story)
stories.append(item.title)
urls[item.title] = item.url
self.vim.command("split HackerNews")
self.vim.command("buffer HackerNews")
self.vim.command("set buftype=nofile")
self.vim.command("set bufhidden=hide")
self.vim.command("setlocal noswapfile")
self.vim.current.buffer[:] = stories
self.urls = urls
@neovim.command('HackerOpen')
def autocmd_handler(self):
url = self.urls[self.vim.current.line]
webbrowser.open_new_tab(url)
示例2: get_news
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
def get_news(from_num, num_headlines):
hn = HackerNews()
print "Starting HN"
news_lst = []
for story_id in hn.top_stories(limit=num_headlines):
news_lst.append(hn.get_item(story_id).title + "\n")
return news_lst
示例3: TestGetItem
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
class TestGetItem(unittest.TestCase):
def setUp(self):
self.hn = HackerNews()
def test_get_item(self):
item = self.hn.get_item(8863)
self.assertIsInstance(item, Item)
self.assertEqual(item.item_id, 8863)
self.assertEqual(item.by, "dhouston")
示例4: get_hackernews_article
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
def get_hackernews_article():
hn_wrapper = HackerNews()
index = random.choice(hn_wrapper.top_stories())
story = hn_wrapper.get_item(index)
result = story.title
if story.url is not None:
result += "\n" + story.url
return result
示例5: getHN_stories
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
def getHN_stories(self, article_limit):
hn = HackerNews()
articles_to_retrieve = int(article_limit*1.5)
top_story_ids = hn.top_stories(limit=articles_to_retrieve)
stories = []
for story_id in top_story_ids:
stories.append(hn.get_item(story_id))
return stories
示例6: updateHackerNews
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
def updateHackerNews():
sql = 'truncate discussion'
database_execute(sql)
hn = HackerNews()
id=1
stories=hn.top_stories(limit=30)
for story_id in stories:
item=hn.get_item(story_id)
id=story_id
url="https://news.ycombinator.com/item?id="+str(story_id)
title=item.title.replace("'","")
score=item.score
sql = "insert into discussion values('%s','%s','%s','%s')"%(id,title,url,score)
#FL.debug(sql)
database_execute(sql)
return "success"
示例7: sync_with_hacker_news
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
def sync_with_hacker_news():
hn = HackerNews()
for story_id in hn.top_stories(limit=90):
story = hn.get_item(story_id)
persisted_news_item = NewsItem.query.get(story_id)
if persisted_news_item:
print "Updating story:", story_id
persisted_news_item.upvotes = story.score
persisted_news_item.comments = comment_count(story)
else:
print "Adding story:", story_id
news_item = NewsItem(
id=story_id, url=story.url, posted_on=story.submission_time,
upvotes=story.score,
comments=comment_count(story))
db.session.add(news_item)
for user in User.query.all():
db.session.add(UserNewsItem(user=user, news_item=news_item))
db.session.commit()
示例8: HackerNews
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
from hackernews import HackerNews
from .models import Story
hn = HackerNews()
for stories in hn.top_stories(limit=10):
stories = hn.get_item(stories)
print stories.title
print stories.url
print stories.score
print stories.by
print stories.submission_time
print stories.item_id
Story.objects.create(title=stories.title, url = stories.url, \
score = stories.score, submitter = stories.by, \
timestamp = stories.submission_time, hn_id = stories.item_id)
示例9: __init__
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
class HackNews:
def __init__(self):
self.hn = HackerNews()
self.jsonObj = []
def displayHackNews(self, jobsOrHeadlines):
if jobsOrHeadlines == "headlines":
return self.topStories()
elif jobsOrHeadlines == "jobs":
return self.jobAds()
else:
resp.message("Oops, wrong catagory! Text us: 'HACKNEWS: jobs' or 'HACKNEWS: headlines'")
def topStories(self):
uncleanHeadline = ""
cleanHeadline = ""
textReturn = ""
for story_id in self.hn.top_stories(limit=10):
uncleanHeadline = str(self.hn.get_item(story_id))
uncleanHeadline = uncleanHeadline.split(' - ', 1 )
cleanHeadline = uncleanHeadline[1][:-1]
textReturn += cleanHeadline + '\n\n'
self.jsonObj.append({ "title" : cleanHeadline })
if(cleanHeadline and cleanHeadline != ""):
self.jsonObj.append({ "sucess" : "true" })
else:
self.jsonObj.append({ "sucess" : "false" })
return textReturn
def jobAds(self):
textReturn = ""
numLoops = 0
maxLoops = 10
for story_id in self.hn.top_stories():
numLoops += 1
story = self.hn.get_item(story_id)
if numLoops >= 10:
break
if story.item_type == 'job':
uncleanHeadline = str(story)
uncleanHeadline = uncleanHeadline.split(' - ', 1 )
cleanHeadline = uncleanHeadline[1][:-1]
textReturn += cleanHeadline + '\n'
if cleanHeadline and cleanHeadline != "":
self.jsonObj.append({ "title" : cleanHeadline })
if textReturn == "":
textReturn += "No jobs have been posted in Top Stories, try again tomorrow!"
self.jsonObj.append({ "sucess" : "false" })
else:
self.jsonObj.append({ "sucess" : "true" })
return textReturn
def convertToJson(self):
return self.jsonObj
示例10: HackerNews
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
"""Downloads items from HN
"""
from hackernews import HackerNews
import string
hn = HackerNews()
with open('amazon.txt','w') as f:
for i in range(50, 20000):
item = hn.get_item(i)
if item.text:
s = item.text
s = filter(lambda x: x in string.printable, s)
if 'amazon' in s:
print s
print type(s)
f.write(s)
f.flush()
f.write("\n")
示例11: str
# 需要导入模块: from hackernews import HackerNews [as 别名]
# 或者: from hackernews.HackerNews import get_item [as 别名]
places.append("New York Bagels")
places.append("Karl Strauss")
number = random.randint(0,len(places) - 1)
sc.rtm_send_message(chan, "You should go to %s to for food." % places[number])
####JIRA STUFF
elif "!helpdesk" in message:
request = message[10:]
new_issue = j.create_issue(project="IT", summary=request, description="Created by Slack", issuetype={'name':'Service Request'}, reporter={"name": email}) #edit project ID to match.
sc.rtm_send_message(chan, "Your helpdesk ticket for '%s' has been created." % request)
####Hacker News Stuff
elif "!hn" in message:
n=0
sc.rtm_send_message(chan,"Top 2 HackerNews Stories:")
for story_id in hn.top_stories(limit=2):
derp = hn.get_item(story_id)
derp = str(derp)
print "derp is:"
print derp
herp = derp
print "herp is:"
print herp
derpy = derp.split(":")[1]
print "derpy is:"
print derpy
derpy = derpy.split("-")[0]
print "derpy is"
print derpy
derpy = derpy.strip()
print "derpy is"
print derpy