-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateGroups.py
62 lines (46 loc) · 1.74 KB
/
createGroups.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from tqdm import tqdm
import os
import twint
import pandas as pd
import numpy as np
from collections import defaultdict
from collections import Counter
import csv
currPath = os.getcwd()
parent = os.path.abspath(os.path.join(currPath, os.pardir))
def createFollowersList(path, listOfFollowers, previousLists=None):
with open(path) as file:
markup = file.read()
for name in tqdm(markup.split()[1:1000]):
listOfFollowers.append(name)
return listOfFollowers
listOfTrumpFollowers = createFollowersList("/{}/realDonaldTrumpFollowers.csv".format(parent), [])
listOfBidenFollowers = createFollowersList("/{}/JoeBidenFollowers.csv".format(parent), [])
both = set(listOfTrumpFollowers).intersection(set(listOfBidenFollowers))
print("Total length!: ", len(listOfTrumpFollowers)+len(listOfBidenFollowers)-len(both))
print("Trump: ", len(listOfTrumpFollowers))
print(listOfTrumpFollowers)
print()
print("Biden: ", len(listOfBidenFollowers))
print(listOfBidenFollowers)
print()
print(len(both))
print(both)
print()
def removeDuplicates(listOfFollowers, both):
for user in both:
if user in listOfFollowers:
listOfFollowers.remove(user)
return listOfFollowers
uniqueTrump = set(removeDuplicates(listOfTrumpFollowers, both))
uniqueBiden = set(removeDuplicates(listOfBidenFollowers, both))
print("Trump: ", len(uniqueTrump))
print("Biden: ", len(uniqueBiden))
print("Both: ", len(both))
def saveToComp(file, faction, parent):
with open("/{}/{}.csv".format(parent, faction), "w") as followerFile:
csvwriter = csv.writer(followerFile)
csvwriter.writerows(zip(file))
saveToComp(uniqueTrump, "TrumpFollowers", parent)
saveToComp(uniqueBiden, "BidenFollowers", parent)
saveToComp(both, "BothFollowers", parent)