本文整理汇总了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)