def _build_file(self):
self.total_rows = 0
#Get recent tweets from dril and add to new file
for status in tweepy.Cursor(api.user_timeline, 'dril', since_id=self.since).items():
self.total_rows += self._process_status(status)
#Put content of old file in new file
#This is kind of messy uhhh
try:
#Open things for reading and writing
readFile = open('data/dril.csv', 'rt', encoding='utf-8')
writeFile = open('data/new.csv', 'at', encoding='utf-8')
read = reader(readFile)
write = writer(writeFile, delimiter=',', quoting=QUOTE_NONNUMERIC) #Uhhhhmmmmmhmh mmmm
for row in read:
write.writerow([int(row[0]), row[1]])
self.total_rows += 1
except IOError:
print('Failed to open file (1) [okay if this is the first time running]')
#Rename the new file to be the old file
os.rename('data/new.csv', 'data/dril.csv')
评论列表
文章目录