forked from Ahsan196/FYP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractingTweetIDs.py
More file actions
58 lines (44 loc) · 1.39 KB
/
ExtractingTweetIDs.py
File metadata and controls
58 lines (44 loc) · 1.39 KB
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
import csv
import sys
#news_source = "politifact"
news_source = "gossipcop"
label = "real"
#label = "fake"
class News:
def __init__(self, info_dict, label, news_platform):
self.news_id = info_dict["id"]
self.news_url = info_dict["news_url"]
self.news_title = info_dict["title"]
self.tweet_ids =[]
try:
tweets = [int(tweet_id) for tweet_id in info_dict["tweet_ids"].split("\t")]
for item in tweets:
print(self.news_id,"\t",item)
self.tweet_ids = tweets
except:
pass
self.label = label
self.platform = news_platform
maxInt = sys.maxsize
while True:
# decrease the maxInt value by factor 10
# as long as the OverflowError occurs.
try:
csv.field_size_limit(maxInt)
break
except OverflowError:
maxInt = int(maxInt/10)
news_list = []
with open('path/politifact_real.csv'.format("dataset", news_source,label),mode="r", encoding="UTF-8") as csvfile:
reader = csv.DictReader(csvfile)
for news in reader:
news_list.append(News(news, label, news_source))
ids = []
for item in news_list:
if len(item.tweet_ids) > 0:
ids.extend(item.tweet_ids)
set_ids = set(ids)
ids = list(set_ids)
file = open("path/politifact_real.txt","a")
for idd in ids:
file.write("%s\n" % idd)