/
fetchcsv.py
42 lines (33 loc) · 1.33 KB
/
fetchcsv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This file is responsible for pulling and maintaining csv data of all the handles mentioned in userlist.txt
# Please seperate each name by the character ','
# todo: as of 23 April 2020, update and syncing previously downloaded user data hasn't been implement.
import twint
import os
from usernames import *
import shutil
import os
current_folder_path = os.path.abspath(os.getcwd())
csv_foldername = 'usercsv'
def fetchUserdata(username):
c = twint.Config()
c.Username = username
c.Limit = 10
c.Store_csv = True
c.Output = os.path.join(current_folder_path, f"{username}.csv")
twint.run.Search(c)
def moveCSVfiles():
# 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,csv_foldername)
if not os.path.isdir(destfolder):
os.mkdir(destfolder)
for f in files:
if (f.endswith('.csv')):
shutil.move(os.path.join(current_folder_path,f), os.path.join(destfolder,f))
if __name__=='__main__':
# Fetch csv data and save
for idx, username in enumerate(twitterUsernames):
fetchUserdata(username)
# move csv files to usercsv folder
moveCSVfiles()