本文整理匯總了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)
示例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)
示例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)
示例4: runTest
# 需要導入模塊: from hackernews import HackerNews [as 別名]
# 或者: from hackernews.HackerNews import getHomePage [as 別名]
def runTest(self):
data = HackerNews.getHomePage()
self.assertTrue(len(data)>0)