Move csv files to different folder because Twint isn't saving to absolute path

This commit is contained in:
Vivek Teega 2020-04-23 21:42:00 +05:30
parent 7b5a6f5d46
commit b66eb3d909
2 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,6 @@
from flask import Flask
import pandas
app = Flask(__name__)
@app.route('/')

View File

@ -5,15 +5,27 @@
import twint
import os
from usernames import *
import shutil
import os
current_folder_path = os.path.abspath(os.getcwd())
def fetchUserdata(username):
c = twint.Config()
c.Username = username
c.Limit = 10
c.Store_csv = True
current_folder_path = os.path.abspath(os.getcwd())
c.Output = os.path.join(current_folder_path, f"{username}.csv")
twint.run.Search(c)
for idx, username in enumerate(twitterUsernames):
fetchUserdata(username)
fetchUserdata(username)
# Twint saves all csv files in the same folder, so move all of them to usercsv/
# todo: Find out why Twint doesn save to absolute path and remove the need for this step
files = os.listdir(current_folder_path)
destfolder = os.path.join(current_folder_path,'usercsv')
for f in files:
if (f.endswith('.csv')):
shutil.move(os.path.join(current_folder_path,f), os.path.join(destfolder,f))