Created
January 19, 2017 15:24
-
-
Save pkoch/c33176541cb149d5c8aa8e172caa98a6 to your computer and use it in GitHub Desktop.
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
import json | |
def slurp_entries(file_name): | |
return [json.loads(l) for l in open(file_name).readlines()] | |
def truque(file_name): | |
""" | |
Identify users that retweet stuff within one second of its publishing date | |
and do no other actions. | |
file_name: The input | |
""" | |
alibied = set() | |
culprits = set() | |
tape = [] | |
tweets_in_tape = set() | |
for entry in slurp_entries(file_name): | |
while tape[0]['timestamp'] < entry['timestamp'] - 1000: | |
t = tape.pop(0) | |
tweets_in_tape.remove(t['id']) | |
tape.append(entry) | |
id_ = entry['id'] | |
tweets_in_tape.add(id_) | |
user = entry['user'] | |
if ( | |
entry['action'] == 'retweet' | |
and id_ in tweets_in_tape | |
and user not in alibied | |
): | |
culprits.add(user) | |
else: | |
alibied.add(user) | |
culprits.remove(user) | |
return culprits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment