当前位置: 首页>>代码示例>>Python>>正文


Python HackerNews.get_item方法代码示例

本文整理汇总了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)
开发者ID:dpzmick,项目名称:neovim-hackernews,代码行数:35,代码来源:hacker.py

示例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
开发者ID:AustinBenavides,项目名称:HackTX2015,代码行数:9,代码来源:run.py

示例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")
开发者ID:NanYoMy,项目名称:haxor,代码行数:12,代码来源:test_get_item.py

示例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
开发者ID:malcolm-mergulhao,项目名称:starter-python-bot,代码行数:12,代码来源:messenger.py

示例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
开发者ID:KaffeLatte,项目名称:pn_stack,代码行数:13,代码来源:python_web_service.py

示例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"
开发者ID:NanYoMy,项目名称:hackernews,代码行数:18,代码来源:helloworld.py

示例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()
开发者ID:fayazkhan,项目名称:reverse_hn_feed,代码行数:21,代码来源:models.py

示例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)
开发者ID:n3bukadn3zar,项目名称:reservo,代码行数:20,代码来源:hn_api.py

示例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
开发者ID:SDharan93,项目名称:bridge2grid-backend,代码行数:81,代码来源:hacknews.py

示例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")


开发者ID:philratcliffe,项目名称:HNBooks,代码行数:24,代码来源:hn.py

示例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
开发者ID:PatrickGarrity,项目名称:SuperSlackBot,代码行数:33,代码来源:superbot.py


注:本文中的hackernews.HackerNews.get_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。