get_Article_processed.py 700 B

12345678910111213141516171819202122232425
  1. #coding:utf8
  2. import psycopg2
  3. import codecs
  4. conn = psycopg2.connect(dbname="BiddingKM_test_10000",user="postgres",password="postgres",host="192.168.2.101")
  5. cursor = conn.cursor()
  6. cursor.execute(" select distinct id from articles ")
  7. all_doc_id = cursor.fetchall()
  8. for doc_id in all_doc_id:
  9. cursor.execute(" select sentence_text from sentences where doc_id='"+str(doc_id[0])+"' order by sentence_index ")
  10. all_sentence = cursor.fetchall()
  11. with codecs.open("export_article/"+str(doc_id[0])+".txt","w",encoding="utf8") as f:
  12. for sentence in all_sentence:
  13. f.write(sentence[0])
  14. f.write("\n")
  15. f.flush()
  16. f.close()