示例#1
0
def _is_author_exits(email) :
	con_d = db.connect_dev()
	query = 'SELECT id FROM author WHERE email=\'' + email + '\''
	result = db.do_select(con_d, query)
	con_d.close()
	
	if len(result) == 0 :
		return False
	return True
示例#2
0
def __get_hook_word_dict() :
	con = db.connect_dev()
	keyword_dict = {}
	query = "SELECT * FROM hooking_keyword"
	result = db.do_select(con, query)
	
	con.close()

	for (id, word) in result :
		keyword_dict[word.encode('utf-8')] = id
	return keyword_dict
示例#3
0
def main() :
	result = _get_raw_data()

	con = db.connect_dev()

	for row in result :
		# article table
		article = _make_article_info(con, row)
		query = db.make_insert_query('article', article)
		db.do_insert(con, query)

		# hooking keyword table
		raw_content = row[2]
		hook_words = _extract_hook_word(raw_content.encode('utf-8'))
		for word in hook_words.keys() :
			words_in_article = {'article_URL': article['URL'], 'hooking_keyword_id': word, 'count': hook_words[word]}
			query = db.make_insert_query('article_hooking_keyword', words_in_article)
			db.do_insert(con, query)
		
		# author table
		expected_author_string = row[5]
		author_list = _make_author_list(con, expected_author_string)

		for author in author_list :
			if not _is_author_exits(author['email']) :
				query = db.make_insert_query('author', author)
				db.do_insert(con, query)
			# Get author_id
			query = "SELECT id FROM author WHERE email=\'" + author['email'] + "\'"
			author_id = db.do_select(con, query)
			author_id = author_id[0][0]
			print author_id, author['name'], author['email'], author['press_id']

		# article_author table
			article_author = {'article_URL': article['URL'], 'author_id': author_id}
			query = db.make_insert_query('article_author', article_author)
			db.do_insert(con, query)
示例#4
0
def __get_press_id_from(url) :
	con_d = db.connect_dev()
	query = 'SELECT id FROM press WHERE domain=\'' + url + '\''
	result = db.do_select(con_d, query)
	con_d.close()
	return result[0][0]