Last active
June 22, 2018 23:30
-
-
Save kordless/cc0ff2ac3be55f69ca1753d907cab2bc to your computer and use it in GitHub Desktop.
output forcenode format for d3.json from lucidworks fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./forcenode.py 35.233.253.193 celeb-list.txt > amps.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ale_BarralesM | |
Taibo2 | |
RicardoAnayaC | |
MikelArriolaP | |
PRI_Nacional | |
EPN | |
JoseAMeadeK | |
Mzavalagc | |
tatclouthier | |
AntonioAttolini | |
JuarezCisneros | |
Claudiashein | |
dparamooficial | |
yeidckol | |
lopezobrador_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
import sys | |
import tweepy | |
import json | |
import requests | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
if __name__ == '__main__': | |
try: | |
if sys.argv[1] and sys.argv[2]: | |
f = open(sys.argv[2]) | |
group = 0 | |
amps = [] | |
links = [] | |
# loop over short list of screen names in file looking for who else is mentioned with them in original tweets | |
for screenName in f: | |
group = group + 1 | |
screenName = screenName.rstrip("\r\n") | |
url = "http://%s:8764/api/apollo/apps/sockitter/query-pipelines/sockitter/collections/sockitter/select" % sys.argv[1] | |
payload = { | |
'debug': 'true', | |
'echoParams': 'all', | |
'f.userMentionScreenName_ss.facet.limit': 100, | |
'facet.field': 'userMentionScreenName_ss', | |
'wt': 'json', | |
'rows': 5, | |
'q': 'tweet_t:%s AND -RT' % screenName | |
} | |
auth = ('admin', 'f00bar222') | |
r = requests.get(url, params=payload, auth=auth) | |
# list user screennames mentioned from query | |
i = 0 | |
citem = "" | |
# print "processing co-mentions for %s" % screenName.rstrip("\r\n") | |
for item in r.json()['facet_counts']['facet_fields']['userMentionScreenName_ss']: | |
if (i % 2) == 0: | |
# facet item | |
citem = item.rstrip("\r\n") | |
amps.append({"id": citem, "group": group}) | |
else: | |
# facet count | |
# print citem, item | |
links.append({"source": screenName, "target": citem, "value": item}) | |
if item < 1: | |
break | |
i = i + 1 | |
else: | |
# doesn't happen | |
sys.exit() | |
output = {} | |
output["nodes"] = amps | |
output["links"] = links | |
print json.dumps(output) | |
except Exception as ex: | |
if len(sys.argv) == 2: | |
print "enter an IP" | |
elif len(sys.argv) == 1: | |
print "enter an IP and filename" | |
else: | |
print "something wrong: %s" % ex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment