當前位置: 首頁>>代碼示例>>Python>>正文


Python HackerNews.getHomePage方法代碼示例

本文整理匯總了Python中hackernews.HackerNews.getHomePage方法的典型用法代碼示例。如果您正苦於以下問題:Python HackerNews.getHomePage方法的具體用法?Python HackerNews.getHomePage怎麽用?Python HackerNews.getHomePage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hackernews.HackerNews的用法示例。


在下文中一共展示了HackerNews.getHomePage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: refresh

# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import getHomePage [as 別名]
    def refresh(self, widget=None, no_timer=False, chrome_data_directory=None, firefox_data_directory=None):

        """Refreshes the menu """
        try:
            # Create an array of 20 false to denote matches in History
            searchResults = [False] * 20
            data = list(reversed(HackerNews.getHomePage()[0:20]))
            urls = [item['url'] for item in data]
            if chrome_data_directory:
                searchResults = self.mergeBoolArray(searchResults, Chrome.search(urls, chrome_data_directory))

            if firefox_data_directory:
                searchResults = self.mergeBoolArray(searchResults, Firefox.search(urls, firefox_data_directory))

            # Remove all the current stories
            for i in self.menu.get_children():
                if hasattr(i, 'url'):
                    self.menu.remove(i)

            # Add back all the refreshed news
            for index, item in enumerate(data):
                item['history'] = searchResults[index]
                if item['url'].startswith('item?id='):
                    item['url'] = "https://news.ycombinator.com/" + item['url']

                self.addItem(item)
        # Catch network errors
        except requests.exceptions.RequestException as e:
            print "[+] There was an error in fetching news items"
        finally:
            # Call every 10 minutes
            if not no_timer:
                gtk.timeout_add(10 * 30 * 1000, self.refresh, widget, no_timer, chrome_data_directory)
開發者ID:artiya4u,項目名稱:hackertray,代碼行數:35,代碼來源:__init__.py

示例2: refresh

# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import getHomePage [as 別名]
	def refresh(self, widget=None, data=None):
		data = reversed(HackerNews.getHomePage()[0:20]);
		#Remove all the current stories
		for i in self.menu.get_children():
			if(hasattr(i,'url')):
				self.menu.remove(i)
		#Add back all the refreshed news
		for i in data:
			self.addItem(i)
		#Call every 5 minutes
		gtk.timeout_add(5*60*1000, self.refresh)
開發者ID:gepser,項目名稱:hackertray,代碼行數:13,代碼來源:__init__.py

示例3: refresh

# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import getHomePage [as 別名]
    def refresh(self, widget=None, no_timer=False):
        """Refreshes the menu """
        data = reversed(HackerNews.getHomePage()[0:20])

        #Remove all the current stories
        for i in self.menu.get_children():
            if hasattr(i, 'url'):
                self.menu.remove(i)

        #Add back all the refreshed news
        for i in data:
            self.addItem(i)

        #Call every 5 minutes
        if not no_timer:
            gtk.timeout_add(10 * 60 * 1000, self.refresh)
開發者ID:ace03uec,項目名稱:hackertray,代碼行數:18,代碼來源:__init__.py

示例4: runTest

# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import getHomePage [as 別名]
	def runTest(self):
		data = HackerNews.getHomePage()
		self.assertTrue(len(data)>0)
開發者ID:Aaron1011,項目名稱:hackertray,代碼行數:5,代碼來源:hn_test.py


注:本文中的hackernews.HackerNews.getHomePage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。