sqlite3.DatabaseError文件不是数据库

时间:2018-11-24 12:03:33

标签: python sqlite sqlalchemy

我需要帮助,试图从Twitter抓取数据,但我没有得到数据库

  

(sqlite3.DatabaseError)文件不是数据库[SQL:'PRAGMA   table_info(“ user_timeline”)'](此错误的背景位于:   http://sqlalche.me/e/4xp6

class Scrape:
    def __init__(self):    
        engine = sqlalchemy.create_engine("sqlite:///C:/Users/Mubarak/Downloads/my machine leaarning kit/twittermda.sqlite.sqbpro", echo=False)  # YOUR DATABASE NAME HERE
        Session = sessionmaker(bind=engine)
        self.session = Session()  
        Base.metadata.create_all(engine)

    def main(self):

        all_ids = self.session.query(ACCOUNT).all()

        print ('len(all_ids)', len(all_ids))


        #CHECK IF THE 'ACCOUNTS' TABLE HAS BEEN POPULATED; IF NOT, ADD DATA FROM 
        #CSV FILE TO THE TABLE
        if len(all_ids) < 1:
            conn = sqlite3.connect('test.sqlite')
            import pandas as pd
            df = pd.read_csv('C:/Users/Mubarak/Downloads/my machine leaarning kit/newaccounts.csv')
            df.to_sql('accounts', conn, if_exists='append', index=False)
            all_ids = self.session.query(ACCOUNT).all()

        keys = []
        for i in all_ids: 
            Unique_ID = i.Unique_ID
            Twitter_handle = i.Twitter_handle
            kid = Twitter_handle                
            rowid = i.Unique_ID
            print ('\n', "\rprocessing id %s/%s  --  %s" % (rowid, len(all_ids), Twitter_handle))
            sys.stdout.flush()


            page = 1
            while page < 17: #TO DOWNLOAD FEWER PAGES OF TWEETS, MODIFY THIS PLUS LINE 621
                print ("------XXXXXX------ STARTING PAGE"), page
                d = get_data_user_timeline_all_pages(kid, page)         
                if not d:
                    print ("THERE WERE NO STATUSES RETURNED........MOVING TO NEXT ID")
                    break        
                if len(d)==0:
                    print ("THERE WERE NO STATUSES RETURNED........MOVING TO NEXT ID")
                    break

                write_data(self, d, Twitter_handle, Unique_ID)


                #self.session.commit()

                #print 'pausing for 1 second'
                #time.sleep(1) #PAUSE FOR 1 SECOND

                page += 1
                if page > 16:
                    print ("WE'RE AT THE END OF PAGE 16!!!!!")
                    break
            self.session.commit()

        print  ('\n', '\n', '\n', "FINISHED WITH ALL IDS")
        self.session.close()

0 个答案:

没有答案