示例#1
0
def version_android():
	try:
		version = queries.get_environment('singlo_android')

		return render_template('version.json', version=version)
	except Exception as e:
		print e
		return render_template('error.json')
示例#2
0
def blog():
	try:
		start_id = int(request.args.get('startid', '0'))
		size = int(request.args.get('size', '10'))

		last_time = queries.get_environment('blog_rss_time')
		threshold_time = str(datetime.now() - timedelta(minutes=10))
		if last_time is None or last_time <= threshold_time: 
			queries.set_environment('blog_rss_time', str(datetime.now()))

			blog_entries = filter(lambda x: not queries.check_blog_article(x.guid),
				feedparser.parse(current_app.config['BLOG_RSS']).entries)[::-1]
			
			for item in blog_entries:
				thumbnail = ''
				try:
					response = urllib.urlopen(item.link)
					page_source = response.read()
					new_link = page_source.split('id="screenFrame"')[1].split('src="')[1].split('"')[0]

					response = urllib.urlopen(new_link)
					page_source = response.read()
					new_link = new_link.split('://')[0] + '://' + new_link.split('://')[1].split('/')[0]
					new_link += page_source.split('id="mainFrame"')[1].split('src="')[1].split('"')[0]
				
					response = urllib.urlopen(new_link)
					page_source = response.read()
					thumbnail = page_source.split('og:image')[1].split('content="')[1].split('"')[0]
				except Exception as e:
					print e

				queries.add_blog_article(item, thumbnail)

		articles = queries.get_blog_article(start_id, size)

		return render_template('blog.json', articles=articles)
	except Exception as e:
		print e
		return render_template('error.json')