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) + "個目")
Esempio n. 2
0
    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) + "個目")
def get_all_sin():
    for row2 in session2.query(QuiteRSS).all():
        #print(row2.id, row2.feedId, row2.title, row2.published, row2.received, row2.link_href)
        #print(row2.published)
        time.sleep(1)
        try:
            newss = session1.query(News.id).order_by(desc(News.received)).all()
            for news in newss:
                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')

                ed_user = News(row.id == row2.id, row.feedId == row2.feedId,
                               row.title == row2.title, row.published == time1,
                               row.received == time2,
                               row.link_href == row2.link_href)
                session1.add(ed_user)

                session1.commit()
                print("データ取得")
        except:
            print("不思議なエラー")

    # セッション・クローズ
    # DB処理が不要になったタイミングやスクリプトの最後で実行
    session1.close()
    session2.close()