def get_all_sin(self): i = 0 s = 0 self.session_open() for row2 in self.session2.query(QuiteRSS).order_by(desc(News.id)).all(): # 全データ指定 try: print(row2.title) time1 = datetime.datetime.strptime(row2.published.replace("T", " "), '%Y-%m-%d %H:%M:%S') time2 = datetime.datetime.strptime(row2.received.replace("T", " "), '%Y-%m-%d %H:%M:%S') quite_rss = News() quite_rss.id = row2.id quite_rss.feedId = row2.feedId quite_rss.title = row2.title quite_rss.published = time1 quite_rss.received = time2 quite_rss.link_href = row2.link_href self.session1.add(quite_rss) self.session1.commit() print ("データ取得") print(str(row2.id)) i = i + 1 except: print ("データがあります。") print(str(row2.id)) s = s + 1 sleep(1) self.session_close() print("取得データ" + str(i) + "個目") print("取得済データ" + str(s) + "個目")
def get_all_old(self): i = 0 s = 0 self.session_open() for row2 in self.session2.query(QuiteRSS).order_by( News.id).all(): # 全データ指定 #print (row2.title) #print (self.session2.query(News.title).one) if self.session1.query(QuiteRSS).filter( QuiteRSS.title == row2.title).all() == []: print("データ無し\n") try: print(row2.title) # 「T」「Z」が邪魔である z = row2.published.replace("Z", "") # Z削除 #print ("z : " + z) t = z.replace("T", " ") # T削除 #print ("t : " + t) time1 = datetime.datetime.strptime( t, '%Y-%m-%d %H:%M:%S') # 文字列を時間に変換 print(str(time1)) #time1 = datetime.datetime.strptime(row2.published.replace("T", " "), '%Y-%m-%d %H:%M:%S') # 「T」「Z」が邪魔である z = row2.received.replace("Z", "") # Z削除 #print ("z : " + z) t = z.replace("T", " ") # T削除 #print ("t : " + t) time2 = datetime.datetime.strptime( t, '%Y-%m-%d %H:%M:%S') # 文字列を時間に変換 #print(str(time2)) #time2 = datetime.datetime.strptime(row2.received.replace("T", " "), '%Y-%m-%d %H:%M:%S') quite_rss = News() quite_rss.id = row2.id quite_rss.feedId = row2.feedId quite_rss.title = row2.title quite_rss.published = time1 quite_rss.received = time2 quite_rss.link_href = row2.link_href self.session1.add(quite_rss) self.session1.commit() print("データ取得") print(str(row2.id)) i = i + 1 except: print("データがあります。") print(str(row2.id)) s = s + 1 sleep(1) self.session_close() print("取得データ" + str(i) + "個目") print("取得済データ" + str(s) + "個目")