-
Notifications
You must be signed in to change notification settings - Fork 0
/
influencers_to_csv.py
executable file
·37 lines (30 loc) · 1.07 KB
/
influencers_to_csv.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
#!/usr/bin/python3
"""This script makes a CSV file (suitable for importing into a spreadsheet)
from the results of ./expand_influencers.py.
Example:
cat seed_sets/boston_seed_set.expanded_set.json | ./influencers_to_csv.py > out.csv
"""
import json
import sys
import csv
rows = []
for line in sys.stdin:
x = json.loads(line)
# Only keep the most popular users
if x["followers_count"] < 20:
continue
# Only keep the most relevant users
if x["civic_odds_ratio"] < 200:
continue
# Metric to sort by. (Could be "civic_odds_ratio" instead, or something else.)
metric = x["followers_count"]
rows.append((metric, x))
rows.sort(key = lambda x: x[0], reverse=True)
csvout = csv.writer(sys.stdout)
csvout.writerow(["Screen name", "Display name", "Location",
"Followers", "Relevance", "Description"])
for r in rows[:500]:
csvout.writerow([r[1]["screen_name"], r[1]["name"],
r[1]["location"], r[1]["followers_count"],
r[1]["civic_odds_ratio"],
r[1]["description"]])